RFR: 7903584: Revisit struct accessors [v3]

Jorn Vernee jvernee at openjdk.org
Mon Jan 15 17:57:10 UTC 2024


> 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:

  update copyright years

-------------

Changes:
  - all: https://git.openjdk.org/jextract/pull/175/files
  - new: https://git.openjdk.org/jextract/pull/175/files/d527b3f7..9f51c8a4

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jextract&pr=175&range=02
 - incr: https://webrevs.openjdk.org/?repo=jextract&pr=175&range=01-02

  Stats: 31 lines in 31 files changed: 0 ins; 0 del; 31 mod
  Patch: https://git.openjdk.org/jextract/pull/175.diff
  Fetch: git fetch https://git.openjdk.org/jextract.git pull/175/head:pull/175

PR: https://git.openjdk.org/jextract/pull/175


More information about the jextract-dev mailing list