RFR: 7903584: Revisit struct accessors

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


On Mon, 15 Jan 2024 15:15:14 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.

Open question: should we add another overload of `asSlice` that takes a size of the returned segment? (right now the returned slice just goes up to the end of the given segment). If we do add an overload, should it accept a byte size or element count?

samples/libcurl/compile_windows.ps1 line 12:

> 10:   "$curlpath\include\curl\curl.h"
> 11:   
> 12: Select-String -Path 'includes_all.conf' -Pattern '(curl|sockaddr )' | %{ $_.Line } | Out-File -FilePath 'includes_filtered.conf' -Encoding ascii

This was an existing issue that went unnoticed previously. The curl_sockaddr type depends on the Windows sockaddr type now (due to the layout referencing it directly), so we need to include that as well.

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

PR Comment: https://git.openjdk.org/jextract/pull/175#issuecomment-1892370311
PR Review Comment: https://git.openjdk.org/jextract/pull/175#discussion_r1452499220


More information about the jextract-dev mailing list