Binding a single function symbol with [foreign]

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


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 
     // 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 

Best regards,
Jorn Vernee

More information about the panama-dev mailing list