Binding a single function symbol with [foreign]

Jorn Vernee jbvernee at xs4all.nl
Thu Sep 6 13:49:18 UTC 2018


Hello,

I was checking out the [foreign] branch today to see what was currently 
possible with it. I have been following the mailing list for a while 
now, and it's always very interesting to read the emails discussing the 
development of this project (especially the technical details).

It seems that currently the only way to bind a native library is to bind 
the entire library to a Java artifact, like one that is generated by 
jextract, through a call to `Libraries.bind`.

The usage I was looking for was more like this:

     Library lib = Libraries.loadLibrary(lookup(), "msvcrt");

     Symbol printf = lib.lookup("printf"); // possibly need mangled name 
here?
     // imaginary api:
     MethodHandle mh = ((FunctionSymbol) printf).bind(); // Or, manually 
provide layout information to bind?
     Scope scope = Scope.newNativeScope();
     Pointer<Byte> message = scope.toCString("Hello World!");
     int result = (int) mh.invokeExact(message);

i.e. having the ability to bind a single function symbol from some 
library and then being able to call that function, without the need to 
use a tool like jextract and binding the generated artifact.

Do you think also having a more low-level API like this is 
possible/desirable?

Best regards,
Jorn Vernee


More information about the panama-dev mailing list