RFR: 7903923: Derive C_* layouts directly from the Linker

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Jan 6 11:44:47 UTC 2025


On Mon, 30 Dec 2024 16:16:41 GMT, Nizar Benalla <nbenalla at openjdk.org> wrote:

> Depending on the platform, different `C_*`  correspond to different `JAVA_*` types. We can get those values directly from the linker.
> 
> This patch can allows us to have a common class for different platforms.
> 
> Please review, and thanks in advance!

src/main/java/org/openjdk/jextract/impl/ToplevelBuilder.java line 80:

> 78:             """);
> 79:         if (TypeImpl.IS_WINDOWS) {
> 80:             first.appendIndentedLines("public static final ValueLayout.OfInt C_LONG = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get(\"int\");");

The canonical layout for this has name `long`. But the result is a `ValueLayout.OfInt` (because FFM uses `int` to model values of that type on Windows). In other words, the only thing that changes in Windows is the cast that should be to `OfInt`, not to `OfLong`.

src/main/java/org/openjdk/jextract/impl/ToplevelBuilder.java line 81:

> 79:         if (TypeImpl.IS_WINDOWS) {
> 80:             first.appendIndentedLines("public static final ValueLayout.OfInt C_LONG = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get(\"int\");");
> 81:             first.appendIndentedLines("public static final ValueLayout.OfDouble C_LONG_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get(\"double\");");

Here, there's no canonical layout for `long double`. (but what you did retains compatibility with what we had). But I wonder if FFM should add one? @JornVernee , @minborg  ?

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

PR Review Comment: https://git.openjdk.org/jextract/pull/269#discussion_r1904048922
PR Review Comment: https://git.openjdk.org/jextract/pull/269#discussion_r1904050827


More information about the jextract-dev mailing list