[foreign-jextract] Duplicated interface declarations when using typedefs for function pointers
Filip Krakowski
krakowski at hhu.de
Thu Jan 28 17:48:15 UTC 2021
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