Open mrmr1993 opened 3 years ago
ocaml_value: string -> 'a typ
. But it is more complicated than this one. However this one seems to put the address of the value in the fatptr which put the address in the nativeint. So the address of the value is outside the OCaml GC awarness, which is bad :wink: . Do you agree?
This PR adds support for handling native OCaml values as arguments to and return values from C functions.
This makes it easy to use the OCaml allocator via
caml_alloc_custom
, while still allowing Ctypes to handle the other details of bindings, and without having to entirely rewrite existing binding systems. For example, in the Mina project we use bindings that currently allocate using rust'sBox
; it would be extremely useful to allocate on the OCaml heap without needing large changes to the bindings or the OCaml side.The implementation roughly
typ
constructorValue
, where the parameter may be any OCaml type_
OCaml type on the bindingsValue ()
functor to the main interfacetyp
for the valueintnat
clone and an[int]
Example usage:
Corresponding C header: