/
foreign.mli
62 lines (49 loc) · 2.19 KB
/
foreign.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(*
* Copyright (c) 2013 Jeremy Yallop.
*
* This file is distributed under the terms of the MIT License.
* See the file LICENSE for details.
*)
(** High-level bindings for C functions and values *)
val foreign :
?from:Dl.library ->
?stub:bool ->
?check_errno:bool ->
string ->
('a -> 'b) Ctypes.fn ->
('a -> 'b)
(** [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].
@raise Dl.DL_error if [name] is not found in [?from] and [?stub] is
[false]. *)
val foreign_value : ?from:Dl.library -> string -> 'a Ctypes.typ -> 'a Ctypes.ptr
(** [foreign_value name typ] exposes the C value of type [typ] named by [name]
as an OCaml value. The argument [?from], if supplied, is a library handle
returned by {!Dl.dlopen}. *)
val funptr :
?name:string ->
?check_errno:bool ->
('a -> 'b) Ctypes.fn ->
('a -> 'b) Ctypes.typ
(** 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]. *)
val funptr_opt : ('a -> 'b) Ctypes.fn -> ('a -> 'b) option Ctypes.typ
(** Construct a function pointer type from a function type.
This behaves like {!funptr}, except that null pointers appear in OCaml as
[None]. *)
exception CallToExpiredClosure
(** A closure passed to C was collected by the OCaml garbage collector before
it was called. *)