I have a C structure (rust, actually) that is manipulated in OCaml with normal stubs, with local parameters, etc. and so far, nothing unusual. The problem is that I want to store a record-of-functions inside this structure (callbacks), which I do by storing the value
and declaring it as a global root using register_global_root
. I remove the root when the structure is destroyed.
Now, when I call a C function on this structure, the C code will access a field of the value within, and use caml_callback<n>_exn
to invoke the OCaml function in the stored record. So it’s caml->C->caml again on the stack. It works, until the inner OCaml code enters the GC, and then it gets stuck in an infinite loop in caml_oldify_local_roots () at roots.c:328
. So my question is: is this use case supported, what is the proper discipline for the stubs in this case, and is *_global_root
the proper way to store OCaml values in C?