module type Funptr =sig..end
type fn
fn is the signature of the underlying OCaml function.
type t
Handle to an OCaml function that can be passed to C for use in callbacks.
Each value of type Foreign.Funptr.t allocated by Foreign.Funptr.of_fun must be deallocated by
calling Foreign.Funptr.free. Alternatively Foreign.Funptr.with_fun encapsulates both allocation
and deallocation.
val t : t Ctypes.typA type representation for a function pointer type with explicit lifetime management.
val t_opt : t option Ctypes.typThis behaves like Foreign.Funptr.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.
val of_fun : fn -> tTurn 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 Foreign.Funptr.free once it is no longer in use. Failure to call Foreign.Funptr.free is
an error.
Alternatively, Foreign.Funptr.with_fun encapsulates both allocation and
deallocation.
Implementation detail: to avoid crashes, if Foreign.Funptr.free is not called then
the implementation will retain a reference to the OCaml closure and
report a warning. See Foreign.report_leaked_funptr.
val with_fun : fn -> (t -> 'c) -> 'cwith_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.