RFR: 7903947: Access to function pointers in structs could be streamlined
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Jul 24 09:40:12 UTC 2025
On Wed, 23 Jul 2025 12:37:47 GMT, Nizar Benalla <nbenalla at openjdk.org> wrote:
> Please review this patch to add a new option where you can generate an direct invoker methods. This feature is intended to be used on structs that are just a collection of functions we had like to call.
>
> If this feature is used, we remove the getter to avoid name collisions as we assume this is similar to an interface.
>
> Changes to `GUIDE.md` have been intentionally left out from this initial patch to make reviews easier.
>
>
> struct Foo {
> struct Bar (*a)(void);
> struct Bar (*b)(int);
> };
>
>
> Before
>
>
> var foo = alloc_callback_h.foo();
>
> var barA = Foo.a.invoke(Foo.a(foo), arena);
> var barB = Foo.b.invoke(Foo.b(foo), arena, 100);
>
>
> After
>
>
> var foo = alloc_callback_h.foo();
>
> var barA = Foo.a(foo, arena);
> var barB = Foo.b(foo, arena, 100);
src/main/java/org/openjdk/jextract/impl/IncludeHelper.java line 111:
> 109: }
> 110:
> 111: if (kind == IncludeKind.STRUCT || kind == IncludeKind.UNION) {
Not sure I get this logic -- it seems like we're always setting a property P for a typedef with name N whenever we see it set for a struct N? That seems odd.
But in example as the one you added in the test are a bit ambiguous, as the same declaration induces both an anonymous struct decl and a typedef, so it is less clear which is which. If I write:
typedef struct Foo {
int a;
};
It seems to be that jextract only retains a "struct" tree, and throws away the typedef. In fact I was surprised that your test worked at all, as in the above case `dump-includes` would include something like this:
--include-struct Foo # header: ....
And *not*:
--include-typedef Foo # header: ....
So adding a property on the typedef should have no effect?
-------------
PR Review Comment: https://git.openjdk.org/jextract/pull/287#discussion_r2227999700
More information about the jextract-dev
mailing list