Fork me on GitHub
#graalvm
<
2022-05-04
>
markus08:05:08

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?

markus08:05:48

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

borkdude08:05:17

Maybe @U0A74MRCJ knows this.

phronmophobic19:05:18

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

markus09:05:16

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?

markus12:05:23

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.