[foreign-jextract] Duplicated interface declarations when using typedefs for function pointers
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Jan 28 17:57:42 UTC 2021
This seems odd. But I guess I can see why jextract ends up doing that.
I think what jextract *should* do is to reuse the interface for
`callback_t` whenever possible (which should be declared at the
toplevel).
In other words, it seems like jextract is re-generating a new interface
every time it encounters a reference to a function pointer typedef,
which seems a bug.
Maurizio
On Thu, 2021-01-28 at 18:48 +0100, Filip Krakowski wrote:
> Hi,
>
> I just noticed that jextract generates duplicate code (interfaces)
> for
> function pointers within each struct instead at the top-level.
> Each interface's name seems to have a suffix based on the occurrence
> of
> the declaration in the source file.
>
> typedef void (*callback_t)(void *arg);
>
> typedef struct first_handler {
> callback_t cb;
> } first_handler_t;
>
> typedef struct second_handler {
> callback_t cb;
> } second_handler_t;
>
> This code generates the following java source code.
>
> @C("struct first_handler")public static class first_handler {
> ...
> public static interface cb {
>
> void apply(jdk.incubator.foreign.MemoryAddress x0);
>
> public static @C("callback_t") MemorySegment
> allocate(cb fi) {
> return RuntimeHelper.upcallStub(cb.class, fi,
> ucx_h_constants_0.cb$FUNC(),
> "(Ljdk/incubator/foreign/MemoryAddress;)V");
> }
>
> public static @C("callback_t") MemorySegment
> allocate(cb fi, NativeScope scope) {
> return allocate(fi).handoff(scope);
> }
> }
> ...
> }
>
> @C("struct second_handler")public static class second_handler {
> ...
> public static interface cb$0 {
>
> void apply(jdk.incubator.foreign.MemoryAddress x0);
>
> public static @C("callback_t") MemorySegment
> allocate(cb$0 fi) {
> return RuntimeHelper.upcallStub(cb$0.class, fi,
> ucx_h_constants_0.cb$0$FUNC(),
> "(Ljdk/incubator/foreign/MemoryAddress;)V");
> }
>
> public static @C("callback_t") MemorySegment
> allocate(cb$0 fi, NativeScope scope) {
> return allocate(fi).handoff(scope);
> }
> }
> ...
> }
>
> From my point of view both interfaces are identical. Is there a
> reason
> for placing them inside the struct class?
>
>
> Best regards
> Filip
>
>
More information about the panama-dev
mailing list