Foreign.Funptrval t : t Ctypes.typA type representation for a function pointer type with explicit lifetime management.
val t_opt : t option Ctypes.typThis behaves like t, except that null pointers appear in OCaml as None.
val free : t -> unitIndicate that the fptr is no longer needed.
Once free has been called any C calls to this Dynamic_funptr.t are unsafe. Only call free once the callback is no longer used from C.
Turn an OCaml closure into a function pointer that can be passed to C.
The function pointer returned by of_fun should be deallocated by a call to free once it is no longer in use. Failure to call free is an error.
Alternatively, with_fun encapsulates both allocation and deallocation.
Implementation detail: to avoid crashes, if free is not called then the implementation will retain a reference to the OCaml closure and report a warning. See report_leaked_funptr.
with_fun fn (fun fptr -> e) - Turn an OCaml closure into a function pointer and perform simple life cycle management.
with_fun fn (fun fptr -> e) will call free fptr after e completes.
with_fun is not safe to use if the C function ptr fptr may still be used after e completes.