High-level bindings for C functions and values
foreign name typ
exposes the C function of type typ
named by name
as
an OCaml value.
The argument ?from
, if supplied, is a library handle returned by
Dl.dlopen.
The argument ?stub
, if true
(defaults to false
), indicates that the
function should not raise an exception if name
is not found but return
an OCaml value that raises an exception when called.
The value ?check_errno
, which defaults to false
, indicates whether
Unix.Unix_error should be raised if the C function modifies errno
.
Dl.DL_error
if name
is not found in ?from
and ?stub
is
false
.
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
.
A closure passed to C was collected by the OCaml garbage collector before it was called.