RFR: 8308293: A linker should expose the layouts it supports [v4]
Paul Sandoz
psandoz at openjdk.org
Tue May 23 19:47:01 UTC 2023
On Mon, 22 May 2023 09:34:53 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> This patch adds an instance method on `Linker`, namely `Linker::canonicalLayouts` which returns all the layouts known by the linker as implementing some ABI type. For instance, if I call this on my machine (Linux/x64) I get this:
>>
>>
>> jshell> import java.lang.foreign.*;
>>
>> jshell> Linker.nativeLinker().canonicalLayouts()
>> $2 ==> {char16_t=c16, int8_t=b8, long=j64, size_t=j64, bool=z8, int=i32, long long=j64, int64_t=j64, void*=a64, float=f32, char=b8, int16_t=s16, int32_t=i32, short=s16, double=d64}
>>
>>
>> This can be useful to discover the ABI types supported by a linker implementation, as well as for, in the future, add support for more exotic (and platform-dependent) linker types, such as `long double` or `complex long`.
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
>
> Address further review comments
On further reflection i think mapping C `unsigned short` only to Java `char` is a misleading. Although Java `char` is an integral type is not really intended to be used generally as an unsigned 16-bit integer, so arguably Java `char` is not as useful a carrier type for native interoperation as Java `short` might be even though it is signed.
Thus i am inclined to remove that mapping.
What if we say something to the effect of:
> unless explicitly declared in the canonical layouts C's unsigned integral types are mapped to the layouts associated with the required C's signed integral types of the same bit sizes.
?
Arguably C `unsigned short` could map to carriers Java `short` or Java `char`, but i am inclined to say the user should cast between Java `short` to `char` in such cases.
FWIW i checked what the FFM API and jextract does today and it maps unsigned C types to signed Java types.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14037#issuecomment-1560028359
More information about the core-libs-dev
mailing list