graalvm

markus 2022-05-04T08:39:08.962929Z

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?

markus 2022-05-05T09:31:16.458609Z

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?

markus 2022-05-05T12:54:23.702329Z

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.

markus 2022-05-04T08:39:25.463809Z

This is the function I want to supply a callback to: https://www.glfw.org/docs/latest/group__input.html#ga1caf18159767e761185e49a3be019f8d

markus 2022-05-04T08:39:48.611329Z

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

borkdude 2022-05-04T08:43:17.939379Z

Maybe @huahaiy knows this.

Huahai 2022-05-04T14:44:05.482249Z

https://github.com/michael-simons/neo4j-java-driver-native-lib has examples for this use case I believe.

markus 2022-05-04T14:51:46.869729Z

Thanks!

phronmophobic 2022-05-04T19:31:18.153329Z

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