In a C stub, is it safe when a value is provided several times to the CAMLparam() / CAMLlocal() macros? (due to nested functions calls)
(example: file sdlrect_stub.c in this PR)
In a C stub, is it safe when a value is provided several times to the CAMLparam() / CAMLlocal() macros? (due to nested functions calls)
(example: file sdlrect_stub.c in this PR)
Yes, it is safe. Not doing it would actually be unsafe. The only time it can be skipped is if you are sure that the function does not directly or indirectly perform any allocation on the OCaml heaps.
Also, to be more precise, those are not values that are passed to CAMLparam
or CAMLlocal
, those are variables: memory cells containing OCaml values (i.e., l-values in C parlance). Indeed, whenever the garbage collector moves an OCaml object in memory, it needs to update all the cells that point to it, and thus it needs to be aware of their existence.