Fork me on GitHub

Hello! Posting a duplicate of a question I posted in the GraalVM Slack here, just in case someone here knows. It's not Clojure specific, but it is used in a Clojure project 🙂 Can someone point me to docs about callbacks from C to Java when using native image? I found an example but it does not work, I guess the interface was changed. Any CEntryPoint now requires an isolate parameter, which obviously the C library will not know anything about because I did not write that code, it's a third party C library that assumes the callback is also written in C. If I can't do this via CEntryPoint, what is the preferred way?


Maybe it's now possible to use jdk.incubator.foreign in native-image?


Maybe @U0A74MRCJ knows this.


I haven't found a better way than creating a small c wrapper. Would be interested to hear if you find another good option!


Turns out I was just not using the svm jar and module... But even with that I can't get anything to work. When the callback comes back from C, global variables that I previously set are now null. Is this something to do with isolates?


Actually, it is really important to have the same isolate everywhere or data will magically vanish. So there is no way to make a reliable callback from C to Java without wrapper functions on the C side taking care of the isolates. That kind of sucks. But at least the C code can get compiled by the native-image builder so there is no separate step for it.