RFR: 7903584: Revisit struct accessors [v2]
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Jan 15 17:46:47 UTC 2024
On Mon, 15 Jan 2024 17:24:59 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> Drop the `$get` and `$set` from the getter/setter names.
>>
>> To ensure that we don't run into any clashes with the indexed accessors on structs (e.g. because a `long` field setter would clash with the indexed getter), we replace the indexed accessors with a 'asSlice' method which can be used to slice a given pointer using an index. This turns the following access pattern:
>>
>> MemorySegment arr = ...
>> int x = Foo.x$get(arr, 10); // old
>>
>> Into this:
>>
>> MemorySegment arr = ...
>> MemorySegment theFoo = Foo.asSlice(arr, 10);
>> int x = Foo.x(theFoo); // new
>>
>> This then allows us to drop the indexed accessors altogether, thus avoiding a name clash.
>>
>> ---
>>
>> This patch also drops the getters (both fro globals and struct fields) which return instances of a functional interface. There is an issue that the new getter name will clash with the FI instance getter (which was already using the nice name), but when discussing this with Maurizio we realized that returning wrappers, like these FI instances, is not really in the spirit of the current 'all-static' approach that jextract takes. So, this patch drops the FI instance getters. For now, the samples will manually wrap the address in an FI instance, until we address: https://bugs.openjdk.org/browse/CODETOOLS-7903628
>>
>> Note: I did not test the LibffmpegMain and PanamaTime changes.
>
> Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
>
> review comments
Looks good (we can probably tweak the name clash if the needs arise in a separate PR)
-------------
Marked as reviewed by mcimadamore (Reviewer).
PR Review: https://git.openjdk.org/jextract/pull/175#pullrequestreview-1822090640
More information about the jextract-dev
mailing list