[ocaml-ctypes] Calling from C into OCaml
daniel.buenzli at erratique.ch
Tue Dec 17 16:53:46 GMT 2013
How does ctypes handle callback closures from C when they are stored in C structures ?
1) Do they respect the OCaml runtime lock ?
2) Are they ensured of not being gc'd ?
In tsdl I did that once for the audio callback which gets called on another thread, it *worked* but I wonder if what I do is safe or if it works by chance (tried to Gc.compact () in the callback but the world didn't explode...).
For reference here are the various bits:
The OCaml record where you specify your callback:
Callback and C structure holding it:
Translation of the OCaml record to a C struct that has a pointer on the callback:
Example of use (440Hz sin wave):
More information about the Ctypes