Construct a function pointer type from a function type.
The ctypes library, like C itself, distinguishes functions and function pointers. Functions are not first class: it is not possible to use them as arguments or return values of calls, or store them in addressable memory. Function pointers are first class, and so have none of these restrictions.
The value ?check_errno
, which defaults to false
, indicates whether Unix.Unix_error
should be raised if the C function modifies errno
.
The value ?runtime_lock
, which defaults to false
, indicates whether the OCaml runtime lock should be released during the call to the C function, allowing other threads to run. If the runtime lock is released then the C function must not access OCaml heap objects, such as arguments passed using Ctypes.ocaml_string
and Ctypes.ocaml_bytes
, and must not call back into OCaml. If the function pointer is used to call into OCaml from C then the ?runtime_lock
argument indicates whether the lock should be acquired and held during the call.
A note on lifetime: this function ties the lifetime of the C function to the associated OCaml closure, so that the C function may be used only while the closure is still live.
The dynamic_funptr
function is an alternative to funptr
with explicit lifetime management.