some thoughts on panama/jextract

Michael Zucchi notzed at gmail.com
Tue Jan 7 04:24:05 UTC 2020


On 6/1/20 10:59 pm, Maurizio Cimadamore wrote:
>
> On 06/01/2020 06:57, Michael Zucchi wrote:
>> Well for C libclang is constrained by the ABI for the platform but I 
>> was thinking of other things like pointer sizes or exposed platform 
>> pieces (or even compile options).  Although a well designed api will 
>> abstract the latter they don't all do it.  I use jmods already so 
>> that works for the binary part, it's the source-part i was worried 
>> about because as soon as something isn't auto-generated, it's manual 
>> work and i'm lazy. 
>
> I think the core of the issue is there with JNI too - e.g. imagine you 
> have a library with an header that defines the following function:
>
> void foo(long);
>
> How do you model this as a native method in Java? Two options:
>
> native void foo(int)
>
> native void foo(long)
>
> The former is the safest - in the sense that it will work correctly on 
> all platforms (e.g. even on Windows, where longs are 32 bits). The 
> latter will take advantage of the extra 32 bits, but will misbehave on 
> Windows.
>
For JNI the first looks the least safest to me as it strips 32 bits off 
a 64-bit invocation?  For JNI I would always use the latter, and let the 
C handle the differences.  It can make informed decisions as it knows 
everything about the target platform at compile time.

I agree with your main point, when platform differences exist the have 
to be handled somewhere, and that automation can't handle it in the 
general case.  For the specific case of pointer size changes I suppose 
it could be nice to have an abi/pointer-size qualifier on the Native* 
annotation value attribute.  Rather than shipping 2x the same interfaces 
with different value="" strings you could just ship one that had 2x the 
descriptors.  Trade-offs for both I guess and no doubt it's been 
considered already.

I think most of my initial concerns have been addressed so I will work 
on porting some of my code and am interested to see how it works in 
practice.  (but no jextract for now!)

Cheers,
  Michael



More information about the panama-dev mailing list