diff --git a/docs/findlib-0/index.html b/docs/findlib-0/index.html new file mode 100644 index 00000000..20129b05 --- /dev/null +++ b/docs/findlib-0/index.html @@ -0,0 +1,2 @@ + +
Packages installed in /home/runner/work/quickjs.ml/quickjs.ml/_opam/lib/ocaml
Str
Regular expressions and high-level string processing
The Str
library provides regular expressions on sequences of bytes. It is, in general, unsuitable to match Unicode characters.
val regexp : string -> regexp
Compile a regular expression. The following constructs are recognized:
.
Matches any character except newline.*
(postfix) Matches the preceding expression zero, one or several times+
(postfix) Matches the preceding expression one or several times?
(postfix) Matches the preceding expression once or not at all[..]
Character set. Ranges are denoted with -
, as in [a-z]
. An initial ^
, as in [^0-9]
, complements the set. To include a ]
character in a set, make it the first character of the set. To include a -
character in a set, make it the first or the last character of the set.^
Matches at beginning of line: either at the beginning of the matched string, or just after a '\n' character.$
Matches at end of line: either at the end of the matched string, or just before a '\n' character.\|
(infix) Alternative between two expressions.\(..\)
Grouping and naming of the enclosed expression.\1
The text matched by the first \(...\)
expression (\2
for the second expression, and so on up to \9
).\b
Matches word boundaries.\
Quotes special characters. The special characters are $^\.*+?[]
.In regular expressions you will often use backslash characters; it's easier to use a quoted string literal {|...|}
to avoid having to escape backslashes.
For example, the following expression:
let r = Str.regexp {|hello \([A-Za-z]+\)|} in
+Str.replace_first r {|\1|} "hello world"
returns the string "world"
.
If you want a regular expression that matches a literal backslash character, you need to double it: Str.regexp {|\\|}
.
You can use regular string literals "..."
too, however you will have to escape backslashes. The example above can be rewritten with a regular string literal as:
let r = Str.regexp "hello \\([A-Za-z]+\\)" in
+Str.replace_first r "\\1" "hello world"
And the regular expression for matching a backslash becomes a quadruple backslash: Str.regexp "\\\\"
.
val regexp_case_fold : string -> regexp
Same as regexp
, but the compiled expression will match text in a case-insensitive way: uppercase and lowercase letters will be considered equivalent.
Str.quote s
returns a regexp string that matches exactly s
and nothing else.
val regexp_string : string -> regexp
Str.regexp_string s
returns a regular expression that matches exactly s
and nothing else.
val regexp_string_case_fold : string -> regexp
Str.regexp_string_case_fold
is similar to Str.regexp_string
, but the regexp matches in a case-insensitive way.
val string_match : regexp -> string -> int -> bool
string_match r s start
tests whether a substring of s
that starts at position start
matches the regular expression r
. The first character of a string has position 0
, as usual.
val search_forward : regexp -> string -> int -> int
search_forward r s start
searches the string s
for a substring matching the regular expression r
. The search starts at position start
and proceeds towards the end of the string. Return the position of the first character of the matched substring.
val search_backward : regexp -> string -> int -> int
search_backward r s last
searches the string s
for a substring matching the regular expression r
. The search first considers substrings that start at position last
and proceeds towards the beginning of string. Return the position of the first character of the matched substring.
val string_partial_match : regexp -> string -> int -> bool
Similar to Str.string_match
, but also returns true if the argument string is a prefix of a string that matches. This includes the case of a true complete match.
matched_string s
returns the substring of s
that was matched by the last call to one of the following matching or searching functions:
Str.string_match
Str.search_forward
Str.search_backward
Str.string_partial_match
Str.global_substitute
Str.substitute_first
provided that none of the following functions was called in between:
Str.global_replace
Str.replace_first
Str.split
Str.bounded_split
Str.split_delim
Str.bounded_split_delim
Str.full_split
Str.bounded_full_split
Note: in the case of global_substitute
and substitute_first
, a call to matched_string
is only valid within the subst
argument, not after global_substitute
or substitute_first
returns.
The user must make sure that the parameter s
is the same string that was passed to the matching or searching function.
match_beginning()
returns the position of the first character of the substring that was matched by the last call to a matching or searching function (see Str.matched_string
for details).
match_end()
returns the position of the character following the last character of the substring that was matched by the last call to a matching or searching function (see Str.matched_string
for details).
matched_group n s
returns the substring of s
that was matched by the n
th group \(...\)
of the regular expression that was matched by the last call to a matching or searching function (see Str.matched_string
for details). When n
is 0
, it returns the substring matched by the whole regular expression. The user must make sure that the parameter s
is the same string that was passed to the matching or searching function.
group_beginning n
returns the position of the first character of the substring that was matched by the n
th group of the regular expression that was matched by the last call to a matching or searching function (see Str.matched_string
for details).
group_end n
returns the position of the character following the last character of substring that was matched by the n
th group of the regular expression that was matched by the last call to a matching or searching function (see Str.matched_string
for details).
val global_replace : regexp -> string -> string -> string
global_replace regexp templ s
returns a string identical to s
, except that all substrings of s
that match regexp
have been replaced by templ
. The replacement template templ
can contain \1
, \2
, etc; these sequences will be replaced by the text matched by the corresponding group in the regular expression. \0
stands for the text matched by the whole regular expression.
val replace_first : regexp -> string -> string -> string
Same as Str.global_replace
, except that only the first substring matching the regular expression is replaced.
val global_substitute : regexp -> (string -> string) -> string -> string
global_substitute regexp subst s
returns a string identical to s
, except that all substrings of s
that match regexp
have been replaced by the result of function subst
. The function subst
is called once for each matching substring, and receives s
(the whole text) as argument.
val substitute_first : regexp -> (string -> string) -> string -> string
Same as Str.global_substitute
, except that only the first substring matching the regular expression is replaced.
replace_matched repl s
returns the replacement text repl
in which \1
, \2
, etc. have been replaced by the text matched by the corresponding groups in the regular expression that was matched by the last call to a matching or searching function (see Str.matched_string
for details). s
must be the same string that was passed to the matching or searching function.
val split : regexp -> string -> string list
split r s
splits s
into substrings, taking as delimiters the substrings that match r
, and returns the list of substrings. For instance, split (regexp "[ \t]+") s
splits s
into blank-separated words. An occurrence of the delimiter at the beginning or at the end of the string is ignored.
val bounded_split : regexp -> string -> int -> string list
Same as Str.split
, but splits into at most n
substrings, where n
is the extra integer parameter.
val split_delim : regexp -> string -> string list
Same as Str.split
but occurrences of the delimiter at the beginning and at the end of the string are recognized and returned as empty strings in the result. For instance, split_delim (regexp " ") " abc "
returns [""; "abc"; ""]
, while split
with the same arguments returns ["abc"]
.
val bounded_split_delim : regexp -> string -> int -> string list
Same as Str.bounded_split
, but occurrences of the delimiter at the beginning and at the end of the string are recognized and returned as empty strings in the result.
val full_split : regexp -> string -> split_result list
Same as Str.split_delim
, but returns the delimiters as well as the substrings contained between delimiters. The former are tagged Delim
in the result list; the latter are tagged Text
. For instance, full_split (regexp "[{}]") "{ab}"
returns [Delim "{"; Text "ab"; Delim "}"]
.
val bounded_full_split : regexp -> string -> int -> split_result list
Same as Str.bounded_split_delim
, but returns the delimiters as well as the substrings contained between delimiters. The former are tagged Delim
in the result list; the latter are tagged Text
.
string_before s n
returns the substring of all characters of s
that precede position n
(excluding the character at position n
).
string_after s n
returns the substring of all characters of s
that follow position n
(including the character at position n
).
first_chars s n
returns the first n
characters of s
. This is the same function as Str.string_before
.
The following libraries are found in this directory.
The following is a list of all of the modules found at this filesystem path.
Str
Regular expressions and high-level string processingBigarray_compat
include module type of struct include Bigarray end
Bigarrays can contain elements of the following kinds:
Bigarray.float32_elt
),Bigarray.float64_elt
),Bigarray.complex32_elt
),Bigarray.complex64_elt
),Bigarray.int8_signed_elt
or Bigarray.int8_unsigned_elt
),Bigarray.int16_signed_elt
or Bigarray.int16_unsigned_elt
),Bigarray.int_elt
),Bigarray.int32_elt
),Bigarray.int64_elt
),Bigarray.nativeint_elt
).Each element kind is represented at the type level by one of the *_elt
types defined below (defined with a single constructor instead of abstract types for technical injectivity reasons).
type ('a, 'b) kind = ('a, 'b) Bigarray.kind =
| Float32 : (float, float32_elt) kind
| Float64 : (float, float64_elt) kind
| Int8_signed : (int, int8_signed_elt) kind
| Int8_unsigned : (int, int8_unsigned_elt) kind
| Int16_signed : (int, int16_signed_elt) kind
| Int16_unsigned : (int, int16_unsigned_elt) kind
| Int32 : (int32, int32_elt) kind
| Int64 : (int64, int64_elt) kind
| Int : (int, int_elt) kind
| Nativeint : (nativeint, nativeint_elt) kind
| Complex32 : (Complex.t, complex32_elt) kind
| Complex64 : (Complex.t, complex64_elt) kind
| Char : (char, int8_unsigned_elt) kind
To each element kind is associated an OCaml type, which is the type of OCaml values that can be stored in the Bigarray or read back from it. This type is not necessarily the same as the type of the array elements proper: for instance, a Bigarray whose elements are of kind float32_elt
contains 32-bit single precision floats, but reading or writing one of its elements from OCaml uses the OCaml type float
, which is 64-bit double precision floats.
The GADT type ('a, 'b) kind
captures this association of an OCaml type 'a
for values read or written in the Bigarray, and of an element kind 'b
which represents the actual contents of the Bigarray. Its constructors list all possible associations of OCaml types with element kinds, and are re-exported below for backward-compatibility reasons.
Using a generalized algebraic datatype (GADT) here allows writing well-typed polymorphic functions whose return type depend on the argument type, such as:
let zero : type a b. (a, b) kind -> a = function
+ | Float32 -> 0.0 | Complex32 -> Complex.zero
+ | Float64 -> 0.0 | Complex64 -> Complex.zero
+ | Int8_signed -> 0 | Int8_unsigned -> 0
+ | Int16_signed -> 0 | Int16_unsigned -> 0
+ | Int32 -> 0l | Int64 -> 0L
+ | Int -> 0 | Nativeint -> 0n
+ | Char -> '\000'
val float32 : (float, float32_elt) kind
See Bigarray.char
.
val float64 : (float, float64_elt) kind
See Bigarray.char
.
val complex32 : (Complex.t, complex32_elt) kind
See Bigarray.char
.
val complex64 : (Complex.t, complex64_elt) kind
See Bigarray.char
.
val int8_signed : (int, int8_signed_elt) kind
See Bigarray.char
.
val int8_unsigned : (int, int8_unsigned_elt) kind
See Bigarray.char
.
val int16_signed : (int, int16_signed_elt) kind
See Bigarray.char
.
val int16_unsigned : (int, int16_unsigned_elt) kind
See Bigarray.char
.
See Bigarray.char
.
See Bigarray.char
.
See Bigarray.char
.
val nativeint : (nativeint, nativeint_elt) kind
See Bigarray.char
.
val char : (char, int8_unsigned_elt) kind
As shown by the types of the values above, Bigarrays of kind float32_elt
and float64_elt
are accessed using the OCaml type float
. Bigarrays of complex kinds complex32_elt
, complex64_elt
are accessed with the OCaml type Complex.t
. Bigarrays of integer kinds are accessed using the smallest OCaml integer type large enough to represent the array elements: int
for 8- and 16-bit integer Bigarrays, as well as OCaml-integer Bigarrays; int32
for 32-bit integer Bigarrays; int64
for 64-bit integer Bigarrays; and nativeint
for platform-native integer Bigarrays. Finally, Bigarrays of kind int8_unsigned_elt
can also be accessed as arrays of characters instead of arrays of small integers, by using the kind value char
instead of int8_unsigned
.
val kind_size_in_bytes : ('a, 'b) kind -> int
kind_size_in_bytes k
is the number of bytes used to store an element of type k
.
To facilitate interoperability with existing C and Fortran code, this library supports two different memory layouts for Bigarrays, one compatible with the C conventions, the other compatible with the Fortran conventions.
In the C-style layout, array indices start at 0, and multi-dimensional arrays are laid out in row-major format. That is, for a two-dimensional array, all elements of row 0 are contiguous in memory, followed by all elements of row 1, etc. In other terms, the array elements at (x,y)
and (x, y+1)
are adjacent in memory.
In the Fortran-style layout, array indices start at 1, and multi-dimensional arrays are laid out in column-major format. That is, for a two-dimensional array, all elements of column 0 are contiguous in memory, followed by all elements of column 1, etc. In other terms, the array elements at (x,y)
and (x+1, y)
are adjacent in memory.
Each layout style is identified at the type level by the phantom types Bigarray.c_layout
and Bigarray.fortran_layout
respectively.
The GADT type 'a layout
represents one of the two supported memory layouts: C-style or Fortran-style. Its constructors are re-exported as values below for backward-compatibility reasons.
type 'a layout = 'a Bigarray.layout =
| C_layout : c_layout layout
| Fortran_layout : fortran_layout layout
val fortran_layout : fortran_layout layout
module Genarray = Bigarray.Genarray
module Array0 = Bigarray.Array0
Zero-dimensional arrays. The Array0
structure provides operations similar to those of Bigarray.Genarray
, but specialized to the case of zero-dimensional arrays that only contain a single scalar value. Statically knowing the number of dimensions of the array allows faster operations, and more precise static type-checking.
module Array1 = Bigarray.Array1
One-dimensional arrays. The Array1
structure provides operations similar to those of Bigarray.Genarray
, but specialized to the case of one-dimensional arrays. (The Array2
and Array3
structures below provide operations specialized for two- and three-dimensional arrays.) Statically knowing the number of dimensions of the array allows faster operations, and more precise static type-checking.
module Array2 = Bigarray.Array2
Two-dimensional arrays. The Array2
structure provides operations similar to those of Bigarray.Genarray
, but specialized to the case of two-dimensional arrays.
module Array3 = Bigarray.Array3
Three-dimensional arrays. The Array3
structure provides operations similar to those of Bigarray.Genarray
, but specialized to the case of three-dimensional arrays.
val genarray_of_array0 : ('a, 'b, 'c) Array0.t -> ('a, 'b, 'c) Genarray.t
Return the generic Bigarray corresponding to the given zero-dimensional Bigarray.
val genarray_of_array1 : ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t
Return the generic Bigarray corresponding to the given one-dimensional Bigarray.
val genarray_of_array2 : ('a, 'b, 'c) Array2.t -> ('a, 'b, 'c) Genarray.t
Return the generic Bigarray corresponding to the given two-dimensional Bigarray.
val genarray_of_array3 : ('a, 'b, 'c) Array3.t -> ('a, 'b, 'c) Genarray.t
Return the generic Bigarray corresponding to the given three-dimensional Bigarray.
val array0_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array0.t
Return the zero-dimensional Bigarray corresponding to the given generic Bigarray.
val array1_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array1.t
Return the one-dimensional Bigarray corresponding to the given generic Bigarray.
val array2_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array2.t
Return the two-dimensional Bigarray corresponding to the given generic Bigarray.
val array3_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array3.t
Return the three-dimensional Bigarray corresponding to the given generic Bigarray.
val reshape : ('a, 'b, 'c) Genarray.t -> int array -> ('a, 'b, 'c) Genarray.t
reshape b [|d1;...;dN|]
converts the Bigarray b
to a N
-dimensional array of dimensions d1
...dN
. The returned array and the original array b
share their data and have the same layout. For instance, assuming that b
is a one-dimensional array of dimension 12, reshape b [|3;4|]
returns a two-dimensional array b'
of dimensions 3 and 4. If b
has C layout, the element (x,y)
of b'
corresponds to the element x * 3 + y
of b
. If b
has Fortran layout, the element (x,y)
of b'
corresponds to the element x + (y - 1) * 4
of b
. The returned Bigarray must have exactly the same number of elements as the original Bigarray b
. That is, the product of the dimensions of b
must be equal to i1 * ... * iN
. Otherwise, Invalid_argument
is raised.
val reshape_0 : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array0.t
Specialized version of Bigarray.reshape
for reshaping to zero-dimensional arrays.
val reshape_1 : ('a, 'b, 'c) Genarray.t -> int -> ('a, 'b, 'c) Array1.t
Specialized version of Bigarray.reshape
for reshaping to one-dimensional arrays.
val reshape_2 : ('a, 'b, 'c) Genarray.t -> int -> int -> ('a, 'b, 'c) Array2.t
Specialized version of Bigarray.reshape
for reshaping to two-dimensional arrays.
val reshape_3 :
+ ('a, 'b, 'c) Genarray.t ->
+ int ->
+ int ->
+ int ->
+ ('a, 'b, 'c) Array3.t
Specialized version of Bigarray.reshape
for reshaping to three-dimensional arrays.
Care must be taken when concurrently accessing bigarrays from multiple domains: accessing a bigarray will never crash a program, but unsynchronized accesses might yield surprising (non-sequentially-consistent) results.
Every bigarray operation that accesses more than one array element is not atomic. This includes slicing, bliting, and filling bigarrays.
For example, consider the following program:
open Bigarray
+let size = 100_000_000
+let a = Array1.init Int C_layout size (fun _ -> 1)
+let update f a () =
+ for i = 0 to size - 1 do a.{i} <- f a.{i} done
+let d1 = Domain.spawn (update (fun x -> x + 1) a)
+let d2 = Domain.spawn (update (fun x -> 2 * x + 1) a)
+let () = Domain.join d1; Domain.join d2
After executing this code, each field of the bigarray a
is either 2
, 3
, 4
or 5
. If atomicity is required, then the user must implement their own synchronization (for example, using Mutex.t
).
If two domains only access disjoint parts of the bigarray, then the observed behaviour is the equivalent to some sequential interleaving of the operations from the two domains.
A data race is said to occur when two domains access the same bigarray element without synchronization and at least one of the accesses is a write. In the absence of data races, the observed behaviour is equivalent to some sequential interleaving of the operations from different domains.
Whenever possible, data races should be avoided by using synchronization to mediate the accesses to the bigarray elements.
Indeed, in the presence of data races, programs will not crash but the observed behaviour may not be equivalent to any sequential interleaving of operations from different domains.
Bigarrays have a distinct caveat in the presence of data races: concurrent bigarray operations might produce surprising values due to tearing. More precisely, the interleaving of partial writes and reads might create values that would not exist with a sequential execution. For instance, at the end of
let res = Array1.init Complex64 c_layout size (fun _ -> Complex.zero)
+let d1 = Domain.spawn (fun () -> Array1.fill res Complex.one)
+let d2 = Domain.spawn (fun () -> Array1.fill res Complex.i)
+let () = Domain.join d1; Domain.join d2
the res
bigarray might contain values that are neither Complex.i
nor Complex.one
(for instance 1 + i
).
The entry point of this library is the module: Bigarray_compat
.
ComplexL
Convert a long double complex to a Complex.t. The real and imaginary components are converted by calling LDouble.to_float
which can produce unspecified results.
val zero : t
0 + i0
val one : t
1 + i0
val i : t
0 + i
polar norm arg
returns the complex having norm norm
and argument arg
.
Argument. The argument of a complex number is the angle in the complex plane between the positive real axis and a line passing through zero and the number.
Cstubs_internals
type voidp = Ctypes_ptr.voidp
type managed_buffer = Ctypes_memory_stubs.managed_buffer
type ('m, 'a) fatptr = ('m, 'a Ctypes.typ) Ctypes_ptr.Fat.t
type ('m, 'a) fatfunptr = ('m, 'a Ctypes.fn) Ctypes_ptr.Fat.t
val make_structured :
+ ('a, 's) Ctypes.structured Ctypes.typ ->
+ managed_buffer ->
+ ('a, 's) Ctypes.structured
val make_ptr : 'a Ctypes.typ -> voidp -> 'a Ctypes.ptr
val make_fun_ptr : 'a Ctypes.fn -> voidp -> 'a Ctypes_static.static_funptr
type 'a ocaml_type = 'a Ctypes_static.ocaml_type =
| String : string ocaml_type
| Bytes : bytes ocaml_type
| FloatArray : float array ocaml_type
type 'a typ = 'a Ctypes_static.typ =
| Void : unit typ
| Primitive : 'a Ctypes_primitive_types.prim -> 'a typ
| Pointer : 'a typ -> 'a ptr typ
| Funptr : 'a Ctypes.fn -> 'a static_funptr typ
| Struct : 'a Ctypes_static.structure_type -> 'a Ctypes_static.structure typ
| Union : 'a Ctypes_static.union_type -> 'a Ctypes_static.union typ
| Abstract : Ctypes_static.abstract_type -> 'a Ctypes_static.abstract typ
| View : ('a, 'b) view -> 'a typ
| Array : 'a typ * int -> 'a Ctypes_static.carray typ
| Bigarray : (_, 'a, _) Ctypes_bigarray.t -> 'a typ
| OCaml : 'a ocaml_type -> 'a ocaml typ
and ('a, 'b) pointer = ('a, 'b) Ctypes_static.pointer =
| CPointer : (Obj.t option, 'a typ) Ctypes_ptr.Fat.t -> ('a, [ `C ]) pointer
| OCamlRef : int * 'a * 'a ocaml_type -> ('a, [ `OCaml ]) pointer
and 'a ptr = ('a, [ `C ]) pointer
and 'a ocaml = ('a, [ `OCaml ]) pointer
and 'a static_funptr = 'a Ctypes_static.static_funptr =
| Static_funptr : (Obj.t option, 'a Ctypes.fn) Ctypes_ptr.Fat.t -> 'a
+ static_funptr
and ('a, 'b) view = ('a, 'b) Ctypes_static.view = {
read : 'b -> 'a;
write : 'a -> 'b;
format_typ : ((Format.formatter -> unit) -> Format.formatter -> unit) option;
format : (Format.formatter -> 'a -> unit) option;
ty : 'b typ;
}
type 'a prim = 'a Ctypes_primitive_types.prim =
| Char : char prim
| Schar : int prim
| Uchar : Unsigned.uchar prim
| Bool : bool prim
| Short : int prim
| Int : int prim
| Long : Signed.long prim
| Llong : Signed.llong prim
| Ushort : Unsigned.ushort prim
| Sint : Signed.sint prim
| Uint : Unsigned.uint prim
| Ulong : Unsigned.ulong prim
| Ullong : Unsigned.ullong prim
| Size_t : Unsigned.size_t prim
| Int8_t : int prim
| Int16_t : int prim
| Int32_t : int32 prim
| Int64_t : int64 prim
| Uint8_t : Unsigned.uint8 prim
| Uint16_t : Unsigned.uint16 prim
| Uint32_t : Unsigned.uint32 prim
| Uint64_t : Unsigned.uint64 prim
| Camlint : int prim
| Nativeint : nativeint prim
| Float : float prim
| Double : float prim
| LDouble : LDouble.t prim
| Complex32 : Complex.t prim
| Complex64 : Complex.t prim
| Complexld : ComplexL.t prim
val build_enum_type :
+ string ->
+ Ctypes_static.arithmetic ->
+ ?typedef:bool ->
+ ?unexpected:(int64 -> 'a) ->
+ ('a * int64) list ->
+ 'a typ
Ctypes.CArray
Operations on C arrays.
type 'a t = 'a carray
val get : 'a t -> int -> 'a
get a n
returns the n
th element of the zero-indexed array a
. The semantics for non-scalar types are non-copying, as for (!@)
.
If you rebind the CArray
module to Array
then you can also use the syntax a.(n)
instead of Array.get a n
.
Raise Invalid_argument "index out of bounds"
if n
is outside of the range 0
to (CArray.length a - 1)
.
val set : 'a t -> int -> 'a -> unit
set a n v
overwrites the n
th element of the zero-indexed array a
with v
.
If you rebind the CArray
module to Array
then you can also use the a.(n) <- v
syntax instead of Array.set a n v
.
Raise Invalid_argument "index out of bounds"
if n
is outside of the range 0
to (CArray.length a - 1)
.
val unsafe_get : 'a t -> int -> 'a
unsafe_get a n
behaves like get a n
except that the check that n
between 0
and (CArray.length a - 1)
is not performed.
val unsafe_set : 'a t -> int -> 'a -> unit
unsafe_set a n v
behaves like set a n v
except that the check that n
between 0
and (CArray.length a - 1)
is not performed.
val of_string : string -> char t
of_string s
builds an array of the same length as s
plus one, and writes the elements of s
to the corresponding elements of the array with the null character '\0' as a last element.
of_list t l
builds an array of type t
of the same length as l
, and writes the elements of l
to the corresponding elements of the array.
val to_list : 'a t -> 'a list
to_list a
builds a list of the same length as a
such that each element of the list is the result of reading the corresponding element of a
.
val iter : ('a -> unit) -> 'a t -> unit
iter f a
is analogous to Array.iter f a
: it applies f
in turn to all the elements of a
.
map t f a
is analogous to Array.map f a
: it creates a new array with element type t
whose elements are obtained by applying f
to the elements of a
.
mapi
behaves like Array.mapi
, except that it also passes the index of each element as the first argument to f
and the element itself as the second argument.
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
CArray.fold_left (@) x a
computes (((x @ a.(0)) @ a.(1)) ...) @ a.(n-1)
where n
is the length of the array a
.
val fold_right : ('b -> 'a -> 'a) -> 'b t -> 'a -> 'a
CArray.fold_right f a x
computes a.(0) @ (a.(1) @ ( ... (a.(n-1) @ x) ...))
where n
is the length of the array a
.
val length : 'a t -> int
Return the number of elements of the given array.
from_ptr p n
creates an n
-length array reference to the memory at address p
.
make t n
creates an n
-length array of type t
. If the optional argument ?initial
is supplied, it indicates a value that should be used to initialise every element of the array. The argument ?finalise
, if present, will be called just before the memory is freed.
sub a ~pos ~length
creates a fresh array of length length
containing the elements a.(pos)
to a.(pos + length - 1)
of a
.
Raise Invalid_argument "CArray.sub"
if pos
and length
do not designate a valid subarray of a
.
Intptr.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Ctypes.Intptr
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Ptrdiff.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Ctypes.Ptrdiff
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Ctypes.Root
val create : 'a -> unit ptr
create v
allocates storage for the address of the OCaml value v
, registers the storage as a root, and returns its address.
val get : unit ptr -> 'a
get p
retrieves the OCaml value whose address is stored at p
.
val set : unit ptr -> 'a -> unit
set p v
updates the OCaml value stored as a root at p
.
val release : unit ptr -> unit
release p
unregsiters the root p
.
Uintptr.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Ctypes.Uintptr
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
Ctypes
The core ctypes module.
The main points of interest are the set of functions for describing C types (see Values representing C types) and the set of functions for accessing C values (see Values representing C values). The Foreign.foreign
function uses C type descriptions to bind external C values.
type ('a, 'b) pointer = ('a, 'b) Ctypes_static.pointer
The type of pointer values. A value of type ('a, [`C]) pointer
contains a C-compatible pointer, and a value of type ('a, [`OCaml]) pointer
contains a pointer to a value that can be moved by OCaml runtime.
type 'a ptr = ('a, [ `C ]) pointer
The type of C-compatible pointer values. A value of type t ptr
can be used to read and write values of type t
at particular addresses.
type 'a ocaml = 'a Ctypes_static.ocaml
The type of pointer values pointing directly into OCaml values. Pointers of this type should never be captured by external code. In particular, functions accepting 'a ocaml
pointers must not invoke any OCaml code.
type 'a carray = 'a Ctypes_static.carray
The type of C array values. A value of type t carray
can be used to read and write array objects in C-managed storage.
type 'a bigarray_class = 'a Ctypes_static.bigarray_class
The type of Bigarray classes. There are four instances, one for each of the Bigarray submodules.
val genarray :
+ < element : 'a
+ ; layout : 'l
+ ; ba_repr : 'b
+ ; bigarray : ('a, 'b, 'l) Bigarray_compat.Genarray.t
+ ; carray : 'a carray
+ ; dims : int array >
+ bigarray_class
The class of Bigarray.Genarray.t
values
val array1 :
+ < element : 'a
+ ; layout : 'l
+ ; ba_repr : 'b
+ ; bigarray : ('a, 'b, 'l) Bigarray_compat.Array1.t
+ ; carray : 'a carray
+ ; dims : int >
+ bigarray_class
The class of Bigarray.Array1.t
values
val array2 :
+ < element : 'a
+ ; layout : 'l
+ ; ba_repr : 'b
+ ; bigarray : ('a, 'b, 'l) Bigarray_compat.Array2.t
+ ; carray : 'a carray carray
+ ; dims : int * int >
+ bigarray_class
The class of Bigarray.Array2.t
values
val array3 :
+ < element : 'a
+ ; layout : 'l
+ ; ba_repr : 'b
+ ; bigarray : ('a, 'b, 'l) Bigarray_compat.Array3.t
+ ; carray : 'a carray carray carray
+ ; dims : int * int * int >
+ bigarray_class
The class of Bigarray.Array3.t
values
type ('a, 'kind) structured = ('a, 'kind) Ctypes_static.structured
The base type of values representing C struct and union types. The 'kind
parameter is a polymorphic variant type indicating whether the type represents a struct (`Struct
) or a union (`Union
).
type 'a structure = ('a, [ `Struct ]) structured
The type of values representing C struct types.
type 'a union = ('a, [ `Union ]) structured
The type of values representing C union types.
type ('a, 't) field = ('a, 't) Ctypes_static.field
The type of values representing C struct or union members (called "fields" here). A value of type (a, s) field
represents a field of type a
in a struct or union of type s
.
type 'a abstract = 'a Ctypes_static.abstract
The type of abstract values. The purpose of the abstract
type is to represent values whose type varies from platform to platform.
For example, the type pthread_t
is a pointer on some platforms, an integer on other platforms, and a struct on a third set of platforms. One way to deal with this kind of situation is to have possibly-platform-specific code which interrogates the C type in some way to help determine an appropriate representation. Another way is to use abstract
, leaving the representation opaque.
(Note, however, that although pthread_t
is a convenient example, since the type used to implement it varies significantly across platforms, it's not actually a good match for abstract
, since values of type pthread_t
are passed and returned by value.)
include Ctypes_types.TYPE
+ with type 'a typ = 'a Ctypes_static.typ
+ and type ('a, 's) field := ('a, 's) field
type 'a typ = 'a Ctypes_static.typ
The type of values representing C types. There are two types associated with each typ
value: the C type used to store and pass values, and the corresponding OCaml type. The type parameter indicates the OCaml type, so a value of type t typ
is used to read and write OCaml values of type t
. There are various uses of typ
values, including
Foreign.foreign
ptr
val void : unit typ
Value representing the C void type. Void values appear in OCaml as the unit type, so using void in an argument or result type specification produces a function which accepts or returns unit.
Dereferencing a pointer to void is an error, as in C, and will raise IncompleteType
.
The scalar types consist of the Arithmetic types and the Pointer types.
The arithmetic types consist of the signed and unsigned integer types (including character types) and the floating types. There are values representing both exact-width integer types (of 8, 16, 32 and 64 bits) and types whose size depend on the platform (signed and unsigned short, int, long, long long).
val char : char typ
Value representing the C type char
.
val schar : int typ
Value representing the C type signed char
.
val short : int typ
Value representing the C type (signed
) short
.
val int : int typ
Value representing the C type (signed
) int
.
val long : Signed.long typ
Value representing the C type (signed
) long
.
val llong : Signed.llong typ
Value representing the C type (signed
) long long
.
val nativeint : nativeint typ
Value representing the C type (signed
) int
.
val int8_t : int typ
Value representing an 8-bit signed integer C type.
val int16_t : int typ
Value representing a 16-bit signed integer C type.
val int32_t : int32 typ
Value representing a 32-bit signed integer C type.
val int64_t : int64 typ
Value representing a 64-bit signed integer C type.
val camlint : int typ
Value representing an integer type with the same storage requirements as an OCaml int
.
val uchar : Unsigned.uchar typ
Value representing the C type unsigned char
.
val bool : bool typ
Value representing the C type bool
.
val uint8_t : Unsigned.uint8 typ
Value representing an 8-bit unsigned integer C type.
val uint16_t : Unsigned.uint16 typ
Value representing a 16-bit unsigned integer C type.
val uint32_t : Unsigned.uint32 typ
Value representing a 32-bit unsigned integer C type.
val uint64_t : Unsigned.uint64 typ
Value representing a 64-bit unsigned integer C type.
val size_t : Unsigned.size_t typ
Value representing the C type size_t
, an alias for one of the unsigned integer types. The actual size and alignment requirements for size_t
vary between platforms.
val ushort : Unsigned.ushort typ
Value representing the C type unsigned short
.
val sint : Signed.sint typ
Value representing the C type int
.
val uint : Unsigned.uint typ
Value representing the C type unsigned int
.
val ulong : Unsigned.ulong typ
Value representing the C type unsigned long
.
val ullong : Unsigned.ullong typ
Value representing the C type unsigned long long
.
module Uintptr : Unsigned.S
val float : float typ
Value representing the C single-precision float
type.
val double : float typ
Value representing the C type double
.
val complexld : ComplexL.t typ
Value representing the C99 long-double-precision long double complex
type.
val ptr : 'a typ -> 'a Ctypes_static.ptr typ
Construct a pointer type from an existing type (called the reference type).
val ptr_opt : 'a typ -> 'a Ctypes_static.ptr option typ
Construct a pointer type from an existing type (called the reference type). This behaves like ptr
, except that null pointers appear in OCaml as None
.
val string : string typ
A high-level representation of the string type.
On the C side this behaves like char *
; on the OCaml side values read and written using string
are simply native OCaml strings.
To avoid problems with the garbage collector, values passed using string
are copied into immovable C-managed storage before being passed to C.
The string type representation is suitable for use in function argument types such as the following:
string @-> returning int
where the lifetime of the C-managed storage does not need to extend beyond the duration of the function call. However, it is not suitable for use in struct or union fields
field s "x" string
because it does not provide a way to manage the lifetime of the C-managed storage.
val string_opt : string option typ
A high-level representation of the string type. This behaves like string
, except that null pointers appear in OCaml as None
.
val ocaml_string : string Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml string.
val ocaml_bytes : bytes Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml byte array.
val array : int -> 'a typ -> 'a Ctypes_static.carray typ
Construct a sized array type from a length and an existing type (called the element type).
val bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.c_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized C-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val fortran_bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.fortran_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized Fortran-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val typ_of_bigarray_kind : ('a, 'b) Bigarray_compat.kind -> 'a typ
typ_of_bigarray_kind k
is the type corresponding to the Bigarray kind k
.
val structure : string -> 's Ctypes_static.structure typ
Construct a new structure type. The type value returned is incomplete and can be updated using field
until it is passed to seal
, at which point the set of fields is fixed.
The type ('_s structure typ
) of the expression returned by the call structure tag
includes a weak type variable, which can be explicitly instantiated to ensure that the OCaml values representing different C structure types have incompatible types. Typical usage is as follows:
type tagname
let tagname : tagname structure typ = structure "tagname"
val union : string -> 's Ctypes_static.union typ
val field :
+ 't typ ->
+ string ->
+ 'a typ ->
+ ('a, ('s, [< `Struct | `Union ]) Ctypes_static.structured as 't) field
field ty label ty'
adds a field of type ty'
with label label
to the structure or union type ty
and returns a field value that can be used to read and write the field in structure or union instances (e.g. using getf
and setf
).
Attempting to add a field to a union type that has been sealed with seal
is an error, and will raise ModifyingSealedType
.
val seal : (_, [< `Struct | `Union ]) Ctypes_static.structured typ -> unit
seal t
completes the struct or union type t
so that no further fields can be added. Struct and union types must be sealed before they can be used in a way that involves their size or alignment; see the documentation for IncompleteType
for further details.
val view :
+ ?format_typ:((Format.formatter -> unit) -> Format.formatter -> unit) ->
+ ?format:(Format.formatter -> 'b -> unit) ->
+ read:('a -> 'b) ->
+ write:('b -> 'a) ->
+ 'a typ ->
+ 'b typ
view ~read:r ~write:w t
creates a C type representation t'
which behaves like t
except that values read using t'
are subsequently transformed using the function r
and values written using t'
are first transformed using the function w
.
For example, given suitable definitions of string_of_char_ptr
and char_ptr_of_string
, the type representation
view ~read:string_of_char_ptr ~write:char_ptr_of_string (ptr char)
can be used to pass OCaml strings directly to and from bound C functions, or to read and write string members in structs and arrays. (In fact, the string
type representation is defined in exactly this way.)
The optional argument format_typ
is used by the Ctypes.format_typ
and string_of_typ
functions to print the type at the top level and elsewhere. If format_typ
is not supplied the printer for t
is used instead.
The optional argument format
is used by the Ctypes.format
and string_of
functions to print the values. If format_val
is not supplied the printer for t
is used instead.
typedef t name
creates a C type representation t'
which is equivalent to t
except its name is printed as name
.
This is useful when generating C stubs involving "anonymous" types, for example: typedef struct { int f } typedef_name;
val abstract :
+ name:string ->
+ size:int ->
+ alignment:int ->
+ 'a Ctypes_static.abstract typ
Create an abstract type specification from the size and alignment requirements for the type.
val lift_typ : 'a Ctypes_static.typ -> 'a typ
lift_typ t
turns a concrete type representation into an abstract type representation.
For example, retrieving struct layout from C involves working with an abstract representation of types which do not support operations such as sizeof
. The lift_typ
function makes it possible to use concrete type representations wherever such abstract type representations are needed.
Abstract interface to C function type descriptions
type 'a fn = 'a Ctypes_static.fn
The type of values representing C function types. A value of type t fn
can be used to bind to C functions and to describe type of OCaml functions passed to C.
Construct a function type from a type and an existing function type. This corresponds to prepending a parameter to a C function parameter list. For example,
int @-> ptr void @-> returning float
describes a function type that accepts two arguments -- an integer and a pointer to void -- and returns a float.
type 'a static_funptr = 'a Ctypes_static.static_funptr
Function pointer types
The type of values representing C function pointer types.
val static_funptr : 'a fn -> 'a Ctypes_static.static_funptr typ
Construct a function pointer type from an existing function type (called the reference type).
val sizeof : 'a typ -> int
sizeof t
computes the size in bytes of the type t
. The exception IncompleteType
is raised if t
is incomplete.
val alignment : 'a typ -> int
alignment t
computes the alignment requirements of the type t
. The exception IncompleteType
is raised if t
is incomplete.
val format_typ : ?name:string -> Format.formatter -> 'a typ -> unit
Pretty-print a C representation of the type to the specified formatter.
val format_fn : ?name:string -> Format.formatter -> 'a fn -> unit
Pretty-print a C representation of the function type to the specified formatter.
val string_of_typ : ?name:string -> 'a typ -> string
Return a C representation of the type.
val string_of_fn : ?name:string -> 'a fn -> string
Return a C representation of the function type.
val format : 'a typ -> Format.formatter -> 'a -> unit
Pretty-print a representation of the C value to the specified formatter.
val string_of : 'a typ -> 'a -> string
Return a string representation of the C value.
val null : unit ptr
A null pointer.
val (!@) : 'a ptr -> 'a
!@ p
dereferences the pointer p
. If the reference type is a scalar type then dereferencing constructs a new value. If the reference type is an aggregate type then dereferencing returns a value that references the memory pointed to by p
.
val (<-@) : 'a ptr -> 'a -> unit
p <-@ v
writes the value v
to the address p
.
If p
is a pointer to an array element then p +@ n
computes the address of the n
th next element.
If p
is a pointer to an array element then p -@ n
computes the address of the nth previous element.
ptr_diff p q
computes q - p
. As in C, both p
and q
must point into the same array, and the result value is the difference of the subscripts of the two array elements.
allocate t v
allocates a fresh value of type t
, initialises it with v
and returns its address. The argument ?finalise
, if present, will be called just before the memory is freed. The value will be automatically freed after no references to the pointer remain within the calling OCaml program.
allocate_n t ~count:n
allocates a fresh array with element type t
and length n
, and returns its address. The argument ?finalise
, if present, will be called just before the memory is freed. The array will be automatically freed after no references to the pointer remain within the calling OCaml program. The memory is allocated with libc's calloc
and is guaranteed to be zero-filled.
If p
and q
are pointers to elements i
and j
of the same array then ptr_compare p q
compares the indexes of the elements. The result is negative if i
is less than j
, positive if i
is greater than j
, and zero if i
and j
are equal.
val is_null : 'a ptr -> bool
is_null p
is true when p
is a null pointer.
val ptr_of_raw_address : nativeint -> unit ptr
Convert the numeric representation of an address to a pointer
val funptr_of_raw_address :
+ nativeint ->
+ (unit -> unit) Ctypes_static.static_funptr
Convert the numeric representation of an address to a function pointer
val raw_address_of_ptr : unit ptr -> nativeint
raw_address_of_ptr p
returns the numeric representation of p.
Note that the return value remains valid only as long as the pointed-to object is alive. If p
is a managed object (e.g. a value returned by make
) then unless the caller retains a reference to p
, the object may be collected, invalidating the returned address.
val string_from_ptr : char ptr -> length:int -> string
string_from_ptr p ~length
creates a string initialized with the length
characters at address p
.
Raise Invalid_argument "Ctypes.string_from_ptr"
if length
is negative.
val ocaml_string_start : string -> string ocaml
ocaml_string_start s
allows to pass a pointer to the contents of an OCaml string directly to a C function.
val ocaml_bytes_start : bytes -> bytes ocaml
ocaml_bytes_start s
allows to pass a pointer to the contents of an OCaml byte array directly to a C function.
module CArray : sig ... end
Operations on C arrays.
val bigarray_start :
+ < element : 'a
+ ; layout : 'l
+ ; ba_repr : _
+ ; bigarray : 'b
+ ; carray : _
+ ; dims : _ >
+ bigarray_class ->
+ 'b ->
+ 'a ptr
Return the address of the first element of the given Bigarray value.
val bigarray_of_ptr :
+ < element : 'a
+ ; layout : Bigarray_compat.c_layout
+ ; ba_repr : 'f
+ ; bigarray : 'b
+ ; carray : _
+ ; dims : 'i >
+ bigarray_class ->
+ 'i ->
+ ('a, 'f) Bigarray_compat.kind ->
+ 'a ptr ->
+ 'b
bigarray_of_ptr c dims k p
converts the C pointer p
to a C-layout bigarray value. No copy is made; the bigarray references the memory pointed to by p
.
val fortran_bigarray_of_ptr :
+ < element : 'a
+ ; layout : Bigarray_compat.fortran_layout
+ ; ba_repr : 'f
+ ; bigarray : 'b
+ ; carray : _
+ ; dims : 'i >
+ bigarray_class ->
+ 'i ->
+ ('a, 'f) Bigarray_compat.kind ->
+ 'a ptr ->
+ 'b
fortran_bigarray_of_ptr c dims k p
converts the C pointer p
to a Fortran-layout bigarray value. No copy is made; the bigarray references the memory pointed to by p
.
val array_of_bigarray :
+ < element : _
+ ; layout : Bigarray_compat.c_layout
+ ; ba_repr : _
+ ; bigarray : 'b
+ ; carray : 'c
+ ; dims : _ >
+ bigarray_class ->
+ 'b ->
+ 'c
array_of_bigarray c b
converts the bigarray value b
to a value of type CArray.t
. No copy is made; the result occupies the same memory as b
.
Convert a Bigarray value to a C array.
val bigarray_of_array :
+ < element : 'a
+ ; layout : Bigarray_compat.c_layout
+ ; ba_repr : 'f
+ ; bigarray : 'b
+ ; carray : 'c carray
+ ; dims : 'i >
+ bigarray_class ->
+ ('a, 'f) Bigarray_compat.kind ->
+ 'c carray ->
+ 'b
bigarray_of_array c k a
converts the CArray.t
value a
to a C-layout bigarray value. No copy is made; the result occupies the same memory as a
.
val make : ?finalise:('s -> unit) -> (_, _) structured as 's typ -> 's
Allocate a fresh, uninitialised structure or union value. The argument ?finalise
, if present, will be called just before the underlying memory is freed.
val setf : (_, _) structured as 's -> ('a, 's) field -> 'a -> unit
setf s f v
overwrites the value of the field f
in the structure or union s
with v
.
val getf : (_, _) structured as 's -> ('a, 's) field -> 'a
getf s f
retrieves the value of the field f
in the structure or union s
. The semantics for non-scalar types are non-copying, as for (!@)
.
val (@.) : (_, _) structured as 's -> ('a, 's) field -> 'a ptr
s @. f
computes the address of the field f
in the structure or union value s
.
val (|->) : (_, _) structured as 's ptr -> ('a, 's) field -> 'a ptr
p |-> f
computes the address of the field f
in the structure or union value pointed to by p
.
offsetof f
returns the offset, in bytes, of the field f
from the beginning of the associated struct type.
val field_name : (_, _) field -> string
field_name f
returns the name of the field f
.
val addr : (_, _) structured as 's -> 's ptr
addr s
returns the address of the structure or union s
.
coerce t1 t2
returns a coercion function between the types represented by t1
and t2
. If t1
cannot be coerced to t2
, coerce
raises Uncoercible
.
The following coercions are currently supported:
void
view
and another type t
(in either direction) if there is a coercion between the representation type underlying the view and t
.t1
is coercible to t2
and t2
is coercible to t3
, then t1
is directly coercible to t3
.The set of supported coercions is subject to change. Future versions of ctypes may both add new types of coercion and restrict the existing coercions.
coerce_fn f1 f2
returns a coercion function between the function types represented by f1
and f2
. If f1
cannot be coerced to f2
, coerce_fn
raises Uncoercible
.
A function type f1
may be coerced to another function type f2
if all of the following hold:
f1
and f2
have the same arityf2
may be coerced to the corresponding argument of f1
f1
may be coerced to the return type of f2
The set of supported coercions is subject to change. Future versions of ctypes may both add new types of coercion and restrict the existing coercions.
module type FOREIGN = sig ... end
module type TYPE = sig ... end
Foreign types binding interface.
module Root : sig ... end
An attempt was made to use a feature not currently supported by ctypes. In practice this refers to attempts to use an union, array or abstract type as an argument or return type of a function.
An attempt was made to modify a sealed struct or union type description.
An attempt was made to compute the size or alignment of an incomplete type.
The incomplete types are struct and union types that have not been sealed, and the void type.
It is not permitted to compute the size or alignment requirements of an incomplete type, to use it as a struct or union member, to read or write a value of the type through a pointer or to use it as the referenced type in pointer arithmetic. Additionally, incomplete struct and union types cannot be used as argument or return types.
exception Uncoercible of uncoercible_info
An attempt was made to coerce between uncoercible types.
Ctypes.FOREIGN
Foreign function binding interface.
The Foreign
and Cstubs
modules provide concrete implementations.
Intptr.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
TYPE.Intptr
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Ptrdiff.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
TYPE.Ptrdiff
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Uintptr.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
TYPE.Uintptr
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
Ctypes.TYPE
Foreign types binding interface.
The Cstubs
module builds concrete implementations.
include Ctypes_types.TYPE
The type of values representing C types. There are two types associated with each typ
value: the C type used to store and pass values, and the corresponding OCaml type. The type parameter indicates the OCaml type, so a value of type t typ
is used to read and write OCaml values of type t
. There are various uses of typ
values, including
Foreign.foreign
ptr
val void : unit typ
Value representing the C void type. Void values appear in OCaml as the unit type, so using void in an argument or result type specification produces a function which accepts or returns unit.
Dereferencing a pointer to void is an error, as in C, and will raise IncompleteType
.
The scalar types consist of the Arithmetic types and the Pointer types.
The arithmetic types consist of the signed and unsigned integer types (including character types) and the floating types. There are values representing both exact-width integer types (of 8, 16, 32 and 64 bits) and types whose size depend on the platform (signed and unsigned short, int, long, long long).
val char : char typ
Value representing the C type char
.
val schar : int typ
Value representing the C type signed char
.
val short : int typ
Value representing the C type (signed
) short
.
val int : int typ
Value representing the C type (signed
) int
.
val long : Signed.long typ
Value representing the C type (signed
) long
.
val llong : Signed.llong typ
Value representing the C type (signed
) long long
.
val nativeint : nativeint typ
Value representing the C type (signed
) int
.
val int8_t : int typ
Value representing an 8-bit signed integer C type.
val int16_t : int typ
Value representing a 16-bit signed integer C type.
val int32_t : int32 typ
Value representing a 32-bit signed integer C type.
val int64_t : int64 typ
Value representing a 64-bit signed integer C type.
val camlint : int typ
Value representing an integer type with the same storage requirements as an OCaml int
.
val uchar : Unsigned.uchar typ
Value representing the C type unsigned char
.
val bool : bool typ
Value representing the C type bool
.
val uint8_t : Unsigned.uint8 typ
Value representing an 8-bit unsigned integer C type.
val uint16_t : Unsigned.uint16 typ
Value representing a 16-bit unsigned integer C type.
val uint32_t : Unsigned.uint32 typ
Value representing a 32-bit unsigned integer C type.
val uint64_t : Unsigned.uint64 typ
Value representing a 64-bit unsigned integer C type.
val size_t : Unsigned.size_t typ
Value representing the C type size_t
, an alias for one of the unsigned integer types. The actual size and alignment requirements for size_t
vary between platforms.
val ushort : Unsigned.ushort typ
Value representing the C type unsigned short
.
val sint : Signed.sint typ
Value representing the C type int
.
val uint : Unsigned.uint typ
Value representing the C type unsigned int
.
val ulong : Unsigned.ulong typ
Value representing the C type unsigned long
.
val ullong : Unsigned.ullong typ
Value representing the C type unsigned long long
.
module Uintptr : Unsigned.S
val float : float typ
Value representing the C single-precision float
type.
val double : float typ
Value representing the C type double
.
val complexld : ComplexL.t typ
Value representing the C99 long-double-precision long double complex
type.
val ptr : 'a typ -> 'a Ctypes_static.ptr typ
Construct a pointer type from an existing type (called the reference type).
val ptr_opt : 'a typ -> 'a Ctypes_static.ptr option typ
Construct a pointer type from an existing type (called the reference type). This behaves like ptr
, except that null pointers appear in OCaml as None
.
val string : string typ
A high-level representation of the string type.
On the C side this behaves like char *
; on the OCaml side values read and written using string
are simply native OCaml strings.
To avoid problems with the garbage collector, values passed using string
are copied into immovable C-managed storage before being passed to C.
The string type representation is suitable for use in function argument types such as the following:
string @-> returning int
where the lifetime of the C-managed storage does not need to extend beyond the duration of the function call. However, it is not suitable for use in struct or union fields
field s "x" string
because it does not provide a way to manage the lifetime of the C-managed storage.
val string_opt : string option typ
A high-level representation of the string type. This behaves like string
, except that null pointers appear in OCaml as None
.
val ocaml_string : string Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml string.
val ocaml_bytes : bytes Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml byte array.
val array : int -> 'a typ -> 'a Ctypes_static.carray typ
Construct a sized array type from a length and an existing type (called the element type).
val bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.c_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized C-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val fortran_bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.fortran_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized Fortran-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val typ_of_bigarray_kind : ('a, 'b) Bigarray_compat.kind -> 'a typ
typ_of_bigarray_kind k
is the type corresponding to the Bigarray kind k
.
val structure : string -> 's Ctypes_static.structure typ
Construct a new structure type. The type value returned is incomplete and can be updated using field
until it is passed to seal
, at which point the set of fields is fixed.
The type ('_s structure typ
) of the expression returned by the call structure tag
includes a weak type variable, which can be explicitly instantiated to ensure that the OCaml values representing different C structure types have incompatible types. Typical usage is as follows:
type tagname
let tagname : tagname structure typ = structure "tagname"
val union : string -> 's Ctypes_static.union typ
val field :
+ 't typ ->
+ string ->
+ 'a typ ->
+ ('a, ('s, [< `Struct | `Union ]) Ctypes_static.structured as 't) field
field ty label ty'
adds a field of type ty'
with label label
to the structure or union type ty
and returns a field value that can be used to read and write the field in structure or union instances (e.g. using getf
and setf
).
Attempting to add a field to a union type that has been sealed with seal
is an error, and will raise ModifyingSealedType
.
val seal : (_, [< `Struct | `Union ]) Ctypes_static.structured typ -> unit
seal t
completes the struct or union type t
so that no further fields can be added. Struct and union types must be sealed before they can be used in a way that involves their size or alignment; see the documentation for IncompleteType
for further details.
val view :
+ ?format_typ:((Format.formatter -> unit) -> Format.formatter -> unit) ->
+ ?format:(Format.formatter -> 'b -> unit) ->
+ read:('a -> 'b) ->
+ write:('b -> 'a) ->
+ 'a typ ->
+ 'b typ
view ~read:r ~write:w t
creates a C type representation t'
which behaves like t
except that values read using t'
are subsequently transformed using the function r
and values written using t'
are first transformed using the function w
.
For example, given suitable definitions of string_of_char_ptr
and char_ptr_of_string
, the type representation
view ~read:string_of_char_ptr ~write:char_ptr_of_string (ptr char)
can be used to pass OCaml strings directly to and from bound C functions, or to read and write string members in structs and arrays. (In fact, the string
type representation is defined in exactly this way.)
The optional argument format_typ
is used by the Ctypes.format_typ
and string_of_typ
functions to print the type at the top level and elsewhere. If format_typ
is not supplied the printer for t
is used instead.
The optional argument format
is used by the Ctypes.format
and string_of
functions to print the values. If format_val
is not supplied the printer for t
is used instead.
typedef t name
creates a C type representation t'
which is equivalent to t
except its name is printed as name
.
This is useful when generating C stubs involving "anonymous" types, for example: typedef struct { int f } typedef_name;
val abstract :
+ name:string ->
+ size:int ->
+ alignment:int ->
+ 'a Ctypes_static.abstract typ
Create an abstract type specification from the size and alignment requirements for the type.
val lift_typ : 'a Ctypes_static.typ -> 'a typ
lift_typ t
turns a concrete type representation into an abstract type representation.
For example, retrieving struct layout from C involves working with an abstract representation of types which do not support operations such as sizeof
. The lift_typ
function makes it possible to use concrete type representations wherever such abstract type representations are needed.
Abstract interface to C function type descriptions
type 'a fn = 'a Ctypes_static.fn
The type of values representing C function types. A value of type t fn
can be used to bind to C functions and to describe type of OCaml functions passed to C.
Construct a function type from a type and an existing function type. This corresponds to prepending a parameter to a C function parameter list. For example,
int @-> ptr void @-> returning float
describes a function type that accepts two arguments -- an integer and a pointer to void -- and returns a float.
type 'a static_funptr = 'a Ctypes_static.static_funptr
Function pointer types
The type of values representing C function pointer types.
val static_funptr : 'a fn -> 'a Ctypes_static.static_funptr typ
Construct a function pointer type from an existing function type (called the reference type).
constant name typ
retrieves the value of the compile-time constant name
of type typ
. It can be used to retrieve enum constants, #defined values and other integer constant expressions.
The type typ
must be either an integer type such as bool
, char
, int
, uint8
, etc., or a view (or perhaps multiple views) where the underlying type is an integer type.
When the value of the constant cannot be represented in the type there will typically be a diagnostic from either the C compiler or the OCaml compiler. For example, gcc will say
warning: overflow in implicit constant conversion
val enum :
+ string ->
+ ?typedef:bool ->
+ ?unexpected:(int64 -> 'a) ->
+ ('a * int64 const) list ->
+ 'a typ
enum name ?unexpected alist
builds a type representation for the enum named name
. The size and alignment are retrieved so that the resulting type can be used everywhere an integer type can be used: as an array element or struct member, as an argument or return value, etc.
The value alist
is an association list of OCaml values and values retrieved by the constant
function. For example, to expose the enum
enum letters { A, B, C = 10, D };
you might first retrieve the values of the enumeration constants:
let a = constant "A" int64_t
+and b = constant "B" int64_t
+and c = constant "C" int64_t
+and d = constant "D" int64_t
and then build the enumeration type
let letters = enum "letters" [
+ `A, a;
+ `B, b;
+ `C, c;
+ `D, d;
+] ~unexpected:(fun i -> `E i)
The unexpected
function specifies the value to return in the case that some unexpected value is encountered -- for example, if a function with the return type 'enum letters' actually returns the value -1
.
The optional flag typedef
specifies whether the first argument, name
, indicates an tag or an alias. If typedef
is false
(the default) then name
is treated as an enumeration tag:
enum letters { ... }
If typedef
is true
then name
is instead treated as an alias:
typedef enum { ... } letters
Ctypes_bigarray
The type of bigarray values of particular sizes. A value of type (a, b, l) t
can be used to read and write values of type b
.
val bigarray :
+ int array ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'l Bigarray_compat.layout ->
+ ('a, ('a, 'b, 'l) Bigarray_compat.Genarray.t, 'l) t
Create a t
value for the Bigarray.Genarray.t
type.
val bigarray1 :
+ int ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'l Bigarray_compat.layout ->
+ ('a, ('a, 'b, 'l) Bigarray_compat.Array1.t, 'l) t
Create a t
value for the Bigarray.Array1.t
type.
val bigarray2 :
+ int ->
+ int ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'l Bigarray_compat.layout ->
+ ('a, ('a, 'b, 'l) Bigarray_compat.Array2.t, 'l) t
Create a t
value for the Bigarray.Array2.t
type.
val bigarray3 :
+ int ->
+ int ->
+ int ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'l Bigarray_compat.layout ->
+ ('a, ('a, 'b, 'l) Bigarray_compat.Array3.t, 'l) t
Create a t
value for the Bigarray.Array3.t
type.
val prim_of_kind :
+ ('a, _) Bigarray_compat.kind ->
+ 'a Ctypes_primitive_types.prim
Create a Ctypes_ptr.Types.ctype
for a Bigarray.kind
.
val sizeof : (_, _, _) t -> int
Compute the size of a bigarray type.
val alignment : (_, _, _) t -> int
Compute the alignment of a bigarray type.
val element_type : ('a, _, _) t -> 'a Ctypes_primitive_types.prim
Compute the element type of a bigarray type.
val dimensions : (_, _, _) t -> int array
Compute the dimensions of a bigarray type.
val type_expression :
+ ('a, 'b, 'l) t ->
+ [> `Appl of string list * 'c list | `Ident of string list ] as 'c
Compute a type expression that denotes a bigarray type.
val unsafe_address : 'a -> Ctypes_ptr.voidp
Return the address of a bigarray value. This function is unsafe because it dissociates the raw address of the C array from the OCaml object that manages the lifetime of the array. If the caller does not hold a reference to the OCaml object then the array might be freed, invalidating the address.
val view : (_, 'a, _) t -> (_ option, _) Ctypes_ptr.Fat.t -> 'a
view b ptr
creates a bigarray view onto existing memory.
If ptr
references an OCaml object then view
will ensure that that object is not collected before the bigarray returned by view
.
Ctypes_bigarray_stubs
type _ kind =
| Kind_float32 : float kind
| Kind_float64 : float kind
| Kind_int8_signed : int kind
| Kind_int8_unsigned : int kind
| Kind_int16_signed : int kind
| Kind_int16_unsigned : int kind
| Kind_int32 : int32 kind
| Kind_int64 : int64 kind
| Kind_int : int kind
| Kind_nativeint : nativeint kind
| Kind_complex32 : Complex.t kind
| Kind_complex64 : Complex.t kind
| Kind_char : char kind
val kind : 'a 'b. ('a, 'b) Bigarray_compat.kind -> 'a kind
val address : 'b -> Ctypes_ptr.voidp
val view :
+ 'a kind ->
+ dims:int array ->
+ (_, _) Ctypes_ptr.Fat.t ->
+ 'l Bigarray_compat.layout ->
+ ('a, 'b, 'l) Bigarray_compat.Genarray.t
val view1 :
+ 'a kind ->
+ dims:int array ->
+ (_, _) Ctypes_ptr.Fat.t ->
+ 'l Bigarray_compat.layout ->
+ ('a, 'b, 'l) Bigarray_compat.Array1.t
val view2 :
+ 'a kind ->
+ dims:int array ->
+ (_, _) Ctypes_ptr.Fat.t ->
+ 'l Bigarray_compat.layout ->
+ ('a, 'b, 'l) Bigarray_compat.Array2.t
val view3 :
+ 'a kind ->
+ dims:int array ->
+ (_, _) Ctypes_ptr.Fat.t ->
+ 'l Bigarray_compat.layout ->
+ ('a, 'b, 'l) Bigarray_compat.Array3.t
Ctypes_coerce
exception Uncoercible of uncoercible_info
val coerce : 'a Ctypes_static.typ -> 'b Ctypes_static.typ -> 'a -> 'b
val coerce_fn : 'a Ctypes_static.fn -> 'b Ctypes_static.fn -> 'a -> 'b
Ctypes_memory.CArray
type 'a t = 'a Ctypes_static.carray
val check_bound : 'a Ctypes_static.carray -> int -> unit
val unsafe_get : 'a Ctypes_static.carray -> int -> 'b
val unsafe_set : 'a Ctypes_static.carray -> int -> 'b -> unit
val get : 'a Ctypes_static.carray -> int -> 'b
val set : 'a Ctypes_static.carray -> int -> 'b -> unit
val start : 'a Ctypes_static.carray -> 'a Ctypes_static.ptr
val length : 'a Ctypes_static.carray -> int
val from_ptr : 'a Ctypes_static.ptr -> int -> 'a Ctypes_static.carray
val fill : 'a Ctypes_static.carray -> 'b -> unit
val make :
+ 'a. ?finalise:('a t -> unit) ->
+ 'a Ctypes_static.typ ->
+ ?initial:'a ->
+ int ->
+ 'a t
val copy : 'a Ctypes_static.carray -> 'b Ctypes_static.carray
val sub :
+ 'a Ctypes_static.carray ->
+ pos:int ->
+ length:int ->
+ 'b Ctypes_static.carray
val element_type : 'a Ctypes_static.carray -> 'b Ctypes_static.typ
val of_string : string -> char t
val of_list : 'a Ctypes_static.typ -> 'b list -> 'a t
val to_list : 'a Ctypes_static.carray -> 'b list
val iter : ('a -> 'b) -> 'c Ctypes_static.carray -> unit
val map : 'a Ctypes_static.typ -> ('b -> 'c) -> 'd Ctypes_static.carray -> 'a t
val mapi :
+ 'a Ctypes_static.typ ->
+ (int -> 'b -> 'c) ->
+ 'd Ctypes_static.carray ->
+ 'a t
val fold_left : ('a -> 'b -> 'c) -> 'd -> 'e Ctypes_static.carray -> 'f
val fold_right : ('a -> 'b -> 'c) -> 'd Ctypes_static.carray -> 'e -> 'f
Ctypes_memory.Root
module Stubs = Ctypes_roots_stubs
val raw_addr : unit Ctypes_static.ptr -> Raw.t
val create : 'a. 'a -> unit Ctypes_static.ptr
val get : 'a. unit Ctypes_static.ptr -> 'a
val set : 'a. unit Ctypes_static.ptr -> 'a -> unit
val release : unit Ctypes_static.ptr -> unit
Ctypes_memory
module Stubs = Ctypes_memory_stubs
module Raw = Ctypes_ptr.Raw
module Fat = Ctypes_ptr.Fat
val castp :
+ 'a Ctypes_static.typ ->
+ ('b, [ `C ]) Ctypes_static.pointer ->
+ ('a, [ `C ]) Ctypes_static.pointer
val make_unmanaged : reftyp:'a -> Ctypes_ptr.voidp -> ('b option, 'c) Fat.t
val build :
+ 'a 'b. 'a Ctypes_static.typ ->
+ ('c, 'b Ctypes_static.typ) Fat.t ->
+ 'a
val write : 'a 'b. 'a Ctypes_static.typ -> 'a -> ('c, 'b) Fat.t -> unit
val null : unit Ctypes_static.ptr
val (!@) : 'a. 'a Ctypes_static.ptr -> 'a
val ptr_diff :
+ 'a 'b. ('a, 'b) Ctypes_static.pointer ->
+ ('a, 'b) Ctypes_static.pointer ->
+ int
val (+@) :
+ 'a 'b. ('a, 'b) Ctypes_static.pointer ->
+ int ->
+ ('a, 'b) Ctypes_static.pointer
val (-@) :
+ ('a, 'b) Ctypes_static.pointer ->
+ int ->
+ ('a, 'b) Ctypes_static.pointer
val (<-@) : 'a. 'a Ctypes_static.ptr -> 'a -> unit
val from_voidp :
+ 'a Ctypes_static.typ ->
+ ('b, [ `C ]) Ctypes_static.pointer ->
+ ('a, [ `C ]) Ctypes_static.pointer
val to_voidp :
+ ('a, [ `C ]) Ctypes_static.pointer ->
+ (unit, [ `C ]) Ctypes_static.pointer
val allocate_n :
+ 'a. ?finalise:('a Ctypes_static.ptr -> unit) ->
+ 'a Ctypes_static.typ ->
+ count:int ->
+ 'a Ctypes_static.ptr
val allocate :
+ 'a. ?finalise:('a Ctypes_static.ptr -> unit) ->
+ 'a Ctypes_static.typ ->
+ 'a ->
+ 'a Ctypes_static.ptr
val ptr_compare :
+ ('a, [ `C ]) Ctypes_static.pointer ->
+ ('b, [ `C ]) Ctypes_static.pointer ->
+ int
val reference_type : ('a, [ `C ]) Ctypes_static.pointer -> 'b Ctypes_static.typ
val ptr_of_raw_address :
+ Ctypes_ptr.voidp ->
+ (unit, [ `C ]) Ctypes_static.pointer
val funptr_of_raw_address :
+ Ctypes_ptr.voidp ->
+ (unit -> unit) Ctypes_static.static_funptr
val raw_address_of_ptr : ('a, [ `C ]) Ctypes_static.pointer -> Ctypes_ptr.voidp
module CArray : sig ... end
val make :
+ ?finalise:(('a, 'b) Ctypes_static.structured -> unit) ->
+ ('c, 'd) Ctypes_static.structured Ctypes_static.typ ->
+ ('c, 'd) Ctypes_static.structured
val (|->) :
+ ('a, [ `C ]) Ctypes_static.pointer ->
+ ('b, 'c) Ctypes_static.field ->
+ ('d, [ `C ]) Ctypes_static.pointer
val (@.) :
+ ('a, 'b) Ctypes_static.structured ->
+ ('c, 'd) Ctypes_static.field ->
+ ('c, [ `C ]) Ctypes_static.pointer
val setf :
+ ('a, 'b) Ctypes_static.structured ->
+ ('c, 'd) Ctypes_static.field ->
+ 'e ->
+ unit
val getf :
+ ('a, 'b) Ctypes_static.structured ->
+ ('c, 'd) Ctypes_static.field ->
+ 'e
val addr :
+ ('a, 'b) Ctypes_static.structured ->
+ ('a, 'b) Ctypes_static.structured Ctypes_static.ptr
val _bigarray_start :
+ ('a, 'b) Bigarray_compat.kind ->
+ 'c ->
+ ('d, [ `C ]) Ctypes_static.pointer
val bigarray_kind :
+ 'a 'b 'c 'd 'f 'l. < ba_repr : 'f
+ ; bigarray : 'b
+ ; carray : 'c
+ ; dims : 'd
+ ; element : 'a
+ ; layout : 'l >
+ Ctypes_static.bigarray_class ->
+ 'b ->
+ ('a, 'f) Bigarray.kind
val bigarray_start :
+ < ba_repr : 'a
+ ; bigarray : 'b
+ ; carray : 'c
+ ; dims : 'd
+ ; element : 'e
+ ; layout : 'f >
+ Ctypes_static.bigarray_class ->
+ 'g ->
+ ('h, [ `C ]) Ctypes_static.pointer
val array_of_bigarray :
+ 'a 'b 'c 'd 'e. < ba_repr : 'e
+ ; bigarray : 'b
+ ; carray : 'c
+ ; dims : 'd
+ ; element : 'a
+ ; layout : Bigarray.c_layout >
+ Ctypes_static.bigarray_class ->
+ 'b ->
+ 'c
val bigarray_elements :
+ 'a 'b 'c 'd 'f 'l. < ba_repr : 'f
+ ; bigarray : 'b
+ ; carray : 'c
+ ; dims : 'd
+ ; element : 'a
+ ; layout : 'l >
+ Ctypes_static.bigarray_class ->
+ 'd ->
+ int
val bigarray_of_ptr :
+ < ba_repr : 'a
+ ; bigarray : 'b
+ ; carray : 'c
+ ; dims : 'd
+ ; element : 'e
+ ; layout : Bigarray_compat.c_layout >
+ Ctypes_static.bigarray_class ->
+ 'f ->
+ ('e, 'a) Bigarray_compat.kind ->
+ ('g, [ `C ]) Ctypes_static.pointer ->
+ 'h
val fortran_bigarray_of_ptr :
+ < ba_repr : 'a
+ ; bigarray : 'b
+ ; carray : 'c
+ ; dims : 'd
+ ; element : 'e
+ ; layout : Bigarray_compat.fortran_layout >
+ Ctypes_static.bigarray_class ->
+ 'f ->
+ ('e, 'a) Bigarray_compat.kind ->
+ ('g, [ `C ]) Ctypes_static.pointer ->
+ 'h
val array_dims :
+ 'a 'b 'c 'd 'f 'l. < ba_repr : 'f
+ ; bigarray : 'b
+ ; carray : 'c Ctypes_static.carray
+ ; dims : 'd
+ ; element : 'a
+ ; layout : 'l >
+ Ctypes_static.bigarray_class ->
+ 'c Ctypes_static.carray ->
+ 'd
val bigarray_of_array :
+ < ba_repr : 'a
+ ; bigarray : 'b
+ ; carray : 'c Ctypes_static.carray
+ ; dims : 'd
+ ; element : 'e
+ ; layout : Bigarray_compat.c_layout >
+ Ctypes_static.bigarray_class ->
+ ('e, 'a) Bigarray_compat.kind ->
+ 'f Ctypes_static.carray ->
+ 'g
val genarray :
+ < ba_repr : 'a
+ ; bigarray : ('b, 'a, 'c) Bigarray_compat.Genarray.t
+ ; carray : 'b Ctypes_static.carray
+ ; dims : int array
+ ; element : 'b
+ ; layout : 'c >
+ Ctypes_static.bigarray_class
val array1 :
+ < ba_repr : 'a
+ ; bigarray : ('b, 'a, 'c) Bigarray_compat.Array1.t
+ ; carray : 'b Ctypes_static.carray
+ ; dims : int
+ ; element : 'b
+ ; layout : 'c >
+ Ctypes_static.bigarray_class
val array2 :
+ < ba_repr : 'a
+ ; bigarray : ('b, 'a, 'c) Bigarray_compat.Array2.t
+ ; carray : 'b Ctypes_static.carray Ctypes_static.carray
+ ; dims : int * int
+ ; element : 'b
+ ; layout : 'c >
+ Ctypes_static.bigarray_class
val array3 :
+ < ba_repr : 'a
+ ; bigarray : ('b, 'a, 'c) Bigarray_compat.Array3.t
+ ; carray :
+ 'b Ctypes_static.carray Ctypes_static.carray Ctypes_static.carray
+ ; dims : int * int * int
+ ; element : 'b
+ ; layout : 'c >
+ Ctypes_static.bigarray_class
val typ_of_bigarray_kind :
+ ('a, 'b) Bigarray_compat.kind ->
+ 'c Ctypes_static.typ
val string_from_ptr :
+ ('a, [ `C ]) Ctypes_static.pointer ->
+ length:int ->
+ string
val ocaml_string_start : string -> (string, [ `OCaml ]) Ctypes_static.pointer
val ocaml_bytes_start : bytes -> (bytes, [ `OCaml ]) Ctypes_static.pointer
val ocaml_float_array_start :
+ float array ->
+ (float array, [ `OCaml ]) Ctypes_static.pointer
module Root : sig ... end
val is_null : ('a, [ `C ]) Ctypes_static.pointer -> bool
Ctypes_memory_stubs.Pointer
val read : (_, _) Ctypes_ptr.Fat.t -> Ctypes_ptr.voidp
val write : (_, _) Ctypes_ptr.Fat.t -> (_, _) Ctypes_ptr.Fat.t -> unit
Ctypes_memory_stubs
val allocate : int -> int -> managed_buffer
val block_address : managed_buffer -> Ctypes_ptr.voidp
val read : 'a Ctypes_primitive_types.prim -> (_, _) Ctypes_ptr.Fat.t -> 'a
val write :
+ 'a Ctypes_primitive_types.prim ->
+ 'a ->
+ (_, _) Ctypes_ptr.Fat.t ->
+ unit
module Pointer : sig ... end
val memcpy :
+ dst:(_, _) Ctypes_ptr.Fat.t ->
+ src:(_, _) Ctypes_ptr.Fat.t ->
+ size:int ->
+ unit
val string_of_array : (_, _) Ctypes_ptr.Fat.t -> len:int -> string
Ctypes_primitive_types
type _ prim =
| Char : char prim
| Schar : int prim
| Uchar : Unsigned.uchar prim
| Bool : bool prim
| Short : int prim
| Int : int prim
| Long : Signed.long prim
| Llong : Signed.llong prim
| Ushort : Unsigned.ushort prim
| Sint : Signed.sint prim
| Uint : Unsigned.uint prim
| Ulong : Unsigned.ulong prim
| Ullong : Unsigned.ullong prim
| Size_t : Unsigned.size_t prim
| Int8_t : int prim
| Int16_t : int prim
| Int32_t : int32 prim
| Int64_t : int64 prim
| Uint8_t : Unsigned.uint8 prim
| Uint16_t : Unsigned.uint16 prim
| Uint32_t : Unsigned.uint32 prim
| Uint64_t : Unsigned.uint64 prim
| Camlint : int prim
| Nativeint : nativeint prim
| Float : float prim
| Double : float prim
| LDouble : LDouble.t prim
| Complex32 : Complex.t prim
| Complex64 : Complex.t prim
| Complexld : ComplexL.t prim
type _ ml_prim =
| ML_char : char ml_prim
| ML_complex : Complex.t ml_prim
| ML_complexld : ComplexL.t ml_prim
| ML_float : float ml_prim
| ML_ldouble : LDouble.t ml_prim
| ML_int : int ml_prim
| ML_int32 : int32 ml_prim
| ML_int64 : int64 ml_prim
| ML_llong : Signed.llong ml_prim
| ML_long : Signed.long ml_prim
| ML_sint : Signed.sint ml_prim
| ML_nativeint : nativeint ml_prim
| ML_size_t : Unsigned.size_t ml_prim
| ML_uchar : Unsigned.uchar ml_prim
| ML_bool : bool ml_prim
| ML_uint : Unsigned.uint ml_prim
| ML_uint16 : Unsigned.uint16 ml_prim
| ML_uint32 : Unsigned.uint32 ml_prim
| ML_uint64 : Unsigned.uint64 ml_prim
| ML_uint8 : Unsigned.uint8 ml_prim
| ML_ullong : Unsigned.ullong ml_prim
| ML_ulong : Unsigned.ulong ml_prim
| ML_ushort : Unsigned.ushort ml_prim
Ctypes_primitives
val sizeof : 'a. 'a Ctypes_primitive_types.prim -> int
val alignment : 'a. 'a Ctypes_primitive_types.prim -> int
val name : 'a. 'a Ctypes_primitive_types.prim -> string
val format_string : 'a. 'a Ctypes_primitive_types.prim -> string option
Ctypes_ptr.Fat
A fat pointer, which holds a reference to the reference type, the C memory location, and an OCaml object.
make ?managed ~reftyp raw
builds a fat pointer from the reference type reftyp
, the C memory location raw
, and (optionally) an OCaml value, managed
. The managed
argument may be used to manage the lifetime of the C object; a typical use it to attach a finaliser to managed
which releases the memory associated with the C object whose address is stored in raw_ptr
.
val is_null : (_, _) t -> bool
val reftype : (_, 'typ) t -> 'typ
val managed : ('m, _) t -> 'm
val set_managed : ('m, _) t -> 'm -> unit
Return the raw pointer address. The function is unsafe in the sense that it dissociates the address from the value which manages the memory, which may trigger associated finalisers, invalidating the address.
Ctypes_ptr.Raw
include module type of struct include Nativeint end
Integer division. This division rounds the real quotient of its arguments towards zero, as specified for Stdlib.(/)
.
Same as div
, except that arguments and result are interpreted as unsigned native integers.
Integer remainder. If y
is not zero, the result of Nativeint.rem x y
satisfies the following properties: Nativeint.zero <= Nativeint.rem x y < Nativeint.abs y
and x = Nativeint.add (Nativeint.mul (Nativeint.div x y) y)
+ (Nativeint.rem x y)
. If y = 0
, Nativeint.rem x y
raises Division_by_zero
.
Same as rem
, except that arguments and result are interpreted as unsigned native integers.
abs x
is the absolute value of x
. On min_int
this is min_int
itself and thus remains negative.
The size in bits of a native integer. This is equal to 32
on a 32-bit platform and to 64
on a 64-bit platform.
The greatest representable native integer, either 231 - 1 on a 32-bit platform, or 263 - 1 on a 64-bit platform.
The smallest representable native integer, either -231 on a 32-bit platform, or -263 on a 64-bit platform.
Nativeint.shift_left x y
shifts x
to the left by y
bits. The result is unspecified if y < 0
or y >= bitsize
, where bitsize
is 32
on a 32-bit platform and 64
on a 64-bit platform.
Nativeint.shift_right x y
shifts x
to the right by y
bits. This is an arithmetic shift: the sign bit of x
is replicated and inserted in the vacated bits. The result is unspecified if y < 0
or y >= bitsize
.
Nativeint.shift_right_logical x y
shifts x
to the right by y
bits. This is a logical shift: zeroes are inserted in the vacated bits regardless of the sign of x
. The result is unspecified if y < 0
or y >= bitsize
.
Convert the given integer (type int
) to a native integer (type nativeint
).
Convert the given native integer (type nativeint
) to an integer (type int
). The high-order bit is lost during the conversion.
Same as to_int
, but interprets the argument as an unsigned integer. Returns None
if the unsigned value of the argument cannot fit into an int
.
Convert the given floating-point number to a native integer, discarding the fractional part (truncate towards 0). If the truncated floating-point number is outside the range [Nativeint.min_int
, Nativeint.max_int
], no exception is raised, and an unspecified, platform-dependent integer is returned.
Convert the given native integer to a 32-bit integer (type int32
). On 64-bit platforms, the 64-bit native integer is taken modulo 232, i.e. the top 32 bits are lost. On 32-bit platforms, the conversion is exact.
Convert the given string to a native integer. The string is read in decimal (by default, or if the string begins with 0u
) or in hexadecimal, octal or binary if the string begins with 0x
, 0o
or 0b
respectively.
The 0u
prefix reads the input as an unsigned integer in the range [0, 2*Nativeint.max_int+1]
. If the input exceeds Nativeint.max_int
it is converted to the signed integer Int64.min_int + input - Nativeint.max_int - 1
.
Same as of_string
, but return None
instead of raising.
The comparison function for native integers, with the same specification as Stdlib.compare
. Along with the type t
, this function compare
allows the module Nativeint
to be passed as argument to the functors Set.Make
and Map.Make
.
Same as compare
, except that arguments are interpreted as unsigned native integers.
val seeded_hash : int -> t -> int
A seeded hash function for native ints, with the same output value as Hashtbl.seeded_hash
. This function allows this module to be passed as argument to the functor Hashtbl.MakeSeeded
.
val hash : t -> int
An unseeded hash function for native ints, with the same output value as Hashtbl.hash
. This function allows this module to be passed as argument to the functor Hashtbl.Make
.
Ctypes_ptr
Ctypes_roots_stubs
val root : 'a -> Ctypes_ptr.voidp
val set : Ctypes_ptr.voidp -> 'a -> unit
val get : Ctypes_ptr.voidp -> 'a
val release : Ctypes_ptr.voidp -> unit
Ctypes_static
type _ ocaml_type =
| String : string ocaml_type
| Bytes : bytes ocaml_type
| FloatArray : float array ocaml_type
type _ typ =
| Void : unit typ
| Primitive : 'a Ctypes_primitive_types.prim -> 'a typ
| Pointer : 'a typ -> 'a ptr typ
| Funptr : 'a fn -> 'a static_funptr typ
| Struct : 'a structure_type -> 'a structure typ
| Union : 'a union_type -> 'a union typ
| Abstract : abstract_type -> 'a abstract typ
| View : ('a, 'b) view -> 'a typ
| Array : 'a typ * int -> 'a carray typ
| Bigarray : (_, 'a, _) Ctypes_bigarray.t -> 'a typ
| OCaml : 'a ocaml_type -> 'a ocaml typ
and 'a union = ('a, [ `Union ]) structured
and 'a structure = ('a, [ `Struct ]) structured
and 'a abstract = ('a, [ `Abstract ]) structured
and (_, _) pointer =
| CPointer : (Obj.t option, 'a typ) Ctypes_ptr.Fat.t -> ('a, [ `C ]) pointer
| OCamlRef : int * 'a * 'a ocaml_type -> ('a, [ `OCaml ]) pointer
and 'a ptr = ('a, [ `C ]) pointer
and 'a ocaml = ('a, [ `OCaml ]) pointer
and ('a, 'b) view = {
read : 'b -> 'a;
write : 'a -> 'b;
format_typ : ((Format.formatter -> unit) -> Format.formatter -> unit) option;
format : (Format.formatter -> 'a -> unit) option;
ty : 'b typ;
}
and 'a structure_type = {
tag : string;
mutable spec : 'a structspec;
mutable fields : 'a structure boxed_field list;
}
and 'a union_type = {
utag : string;
mutable uspec : structured_spec option;
mutable ufields : 'a union boxed_field list;
}
type _ bigarray_class =
| Genarray : < element : 'a
+ ; layout : 'l
+ ; dims : int array
+ ; ba_repr : 'b
+ ; bigarray : ('a, 'b, 'l) Bigarray_compat.Genarray.t
+ ; carray : 'a carray >
+ bigarray_class
| Array1 : < element : 'a
+ ; layout : 'l
+ ; dims : int
+ ; ba_repr : 'b
+ ; bigarray : ('a, 'b, 'l) Bigarray_compat.Array1.t
+ ; carray : 'a carray >
+ bigarray_class
| Array2 : < element : 'a
+ ; layout : 'l
+ ; dims : int * int
+ ; ba_repr : 'b
+ ; bigarray : ('a, 'b, 'l) Bigarray_compat.Array2.t
+ ; carray : 'a carray carray >
+ bigarray_class
| Array3 : < element : 'a
+ ; layout : 'l
+ ; dims : int * int * int
+ ; ba_repr : 'b
+ ; bigarray : ('a, 'b, 'l) Bigarray_compat.Array3.t
+ ; carray : 'a carray carray carray >
+ bigarray_class
val sizeof : 'a typ -> int
val alignment : 'a typ -> int
val passable : 'a typ -> bool
val ocaml_value : 'a typ -> bool
val has_ocaml_argument : 'a fn -> bool
val void : unit typ
val char : char typ
val schar : int typ
val float : float typ
val double : float typ
val complexld : ComplexL.t typ
val short : int typ
val int : int typ
val sint : Signed.sint typ
val long : Signed.long typ
val llong : Signed.llong typ
val nativeint : nativeint typ
val int8_t : int typ
val int16_t : int typ
val int32_t : Signed.Int32.t typ
val int64_t : Signed.Int64.t typ
val camlint : int typ
val uchar : Unsigned.uchar typ
val bool : bool typ
val uint8_t : Unsigned.UInt8.t typ
val uint16_t : Unsigned.UInt16.t typ
val uint32_t : Unsigned.UInt32.t typ
val uint64_t : Unsigned.UInt64.t typ
val size_t : Unsigned.size_t typ
val ushort : Unsigned.ushort typ
val uint : Unsigned.uint typ
val ulong : Unsigned.ulong typ
val ullong : Unsigned.ullong typ
val view :
+ ?format_typ:((Format.formatter -> unit) -> Format.formatter -> unit) ->
+ ?format:(Format.formatter -> 'b -> unit) ->
+ read:('a -> 'b) ->
+ write:('b -> 'a) ->
+ 'a typ ->
+ 'b typ
val bigarray :
+ < ba_repr : 'c
+ ; bigarray : 'd
+ ; carray : 'e
+ ; dims : 'b
+ ; layout : Bigarray_compat.c_layout
+ ; element : 'a >
+ bigarray_class ->
+ 'b ->
+ ('a, 'c) Bigarray_compat.kind ->
+ 'd typ
val fortran_bigarray :
+ < ba_repr : 'c
+ ; bigarray : 'd
+ ; carray : 'e
+ ; dims : 'b
+ ; layout : Bigarray_compat.fortran_layout
+ ; element : 'a >
+ bigarray_class ->
+ 'b ->
+ ('a, 'c) Bigarray_compat.kind ->
+ 'd typ
val static_funptr : 'a fn -> 'a static_funptr typ
val offsetof : ('a, 'b) field -> int
val field_name : ('a, 'b) field -> string
val unsupported : ('a, unit, string, _) format4 -> 'a
Ctypes_std_view_stubs
val string_of_cstring : (_, char Ctypes_static.typ) Ctypes_ptr.Fat.t -> string
val cstring_of_string : string -> Ctypes_memory_stubs.managed_buffer
Intptr.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Ctypes_std_views.Intptr
include Signed.S
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
val t : t Ctypes_static.typ
Ptrdiff.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Ctypes_std_views.Ptrdiff
include Signed.S
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
val t : t Ctypes_static.typ
Uintptr.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Ctypes_std_views.Uintptr
include Unsigned.S
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
val t : t Ctypes_static.typ
Ctypes_std_views
val string_of_char_ptr : (char, [ `C ]) Ctypes_static.pointer -> string
val char_ptr_of_string : string -> (char, [ `C ]) Ctypes_static.pointer
val string : string Ctypes_static.typ
val read_nullable :
+ 'a Ctypes_static.typ ->
+ 'b Ctypes_static.typ ->
+ 'b Ctypes_static.ptr ->
+ 'c option
val write_nullable :
+ 'a Ctypes_static.typ ->
+ 'b Ctypes_static.typ ->
+ 'c option ->
+ 'd Ctypes_static.ptr
val nullable_view :
+ ?format_typ:((Format.formatter -> unit) -> Format.formatter -> unit) ->
+ ?format:(Format.formatter -> 'a option -> unit) ->
+ 'b Ctypes_static.typ ->
+ 'c Ctypes_static.typ ->
+ 'a option Ctypes_static.typ
val read_nullable_funptr :
+ 'a Ctypes_static.typ ->
+ 'b Ctypes_static.fn ->
+ 'c Ctypes_static.static_funptr ->
+ 'd option
val write_nullable_funptr :
+ 'a Ctypes_static.typ ->
+ 'b Ctypes_static.fn ->
+ 'c option ->
+ 'b Ctypes_static.static_funptr
val nullable_funptr_view :
+ ?format_typ:((Format.formatter -> unit) -> Format.formatter -> unit) ->
+ ?format:(Format.formatter -> 'a option -> unit) ->
+ 'b Ctypes_static.typ ->
+ 'c Ctypes_static.fn ->
+ 'a option Ctypes_static.typ
val ptr_opt :
+ 'a Ctypes_static.typ ->
+ 'b Ctypes_static.ptr option Ctypes_static.typ
val string_opt : string option Ctypes_static.typ
module type Signed_type = sig ... end
module type Unsigned_type = sig ... end
val signed_typedef : string -> size:int -> (module Signed_type)
val unsigned_typedef : string -> size:int -> (module Unsigned_type)
module Intptr : Signed_type
module Uintptr : Unsigned_type
val intptr_t : Intptr.t Ctypes_static.typ
val uintptr_t : Uintptr.t Ctypes_static.typ
module Ptrdiff : Signed_type
val ptrdiff_t : Ptrdiff.t Ctypes_static.typ
Signed_type.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Ctypes_std_views.Signed_type
include Signed.S
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
val t : t Ctypes_static.typ
Unsigned_type.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Ctypes_std_views.Unsigned_type
include Unsigned.S
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
val t : t Ctypes_static.typ
Ctypes_structs
module type S = sig ... end
Ctypes_structs.S
val field :
+ 't Ctypes_static.typ ->
+ string ->
+ 'a Ctypes_static.typ ->
+ ('a, ('s, [< `Struct | `Union ]) Ctypes_static.structured as 't) field
val seal :
+ (_, [< `Struct | `Union ]) Ctypes_static.structured Ctypes_static.typ ->
+ unit
Ctypes_structs_computed
Structs and unions whose layouts are computed from the sizes and alignment requirements of the constituent field types.
include Ctypes_structs.S
+ with type ('a, 's) field := ('a, 's) Ctypes_static.field
val field :
+ 't Ctypes_static.typ ->
+ string ->
+ 'a Ctypes_static.typ ->
+ ('a, ('s, [< `Struct | `Union ]) Ctypes_static.structured as 't)
+ Ctypes_static.field
val seal :
+ (_, [< `Struct | `Union ]) Ctypes_static.structured Ctypes_static.typ ->
+ unit
Ctypes_type_printing
val format_name : ?name:string -> Format.formatter -> unit
val format_typ' :
+ 'a Ctypes_static.typ ->
+ (format_context -> Format.formatter -> unit) ->
+ format_context ->
+ Format.formatter ->
+ unit
val format_typ :
+ ?name:string ->
+ Format.formatter ->
+ 'a Ctypes_static.typ ->
+ unit
val format_fn' :
+ 'a Ctypes_static.fn ->
+ (Format.formatter -> unit) ->
+ Format.formatter ->
+ unit
val format_fn : ?name:string -> Format.formatter -> 'a Ctypes_static.fn -> unit
val string_of_typ : ?name:string -> 'a Ctypes_static.typ -> string
val string_of_fn : ?name:string -> 'a Ctypes_static.fn -> string
Ctypes_types
module type TYPE = sig ... end
Abstract interface to C object type descriptions
Intptr.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
TYPE.Intptr
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Ptrdiff.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
TYPE.Ptrdiff
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Uintptr.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
TYPE.Uintptr
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
Ctypes_types.TYPE
Abstract interface to C object type descriptions
The type of values representing C types. There are two types associated with each typ
value: the C type used to store and pass values, and the corresponding OCaml type. The type parameter indicates the OCaml type, so a value of type t typ
is used to read and write OCaml values of type t
. There are various uses of typ
values, including
Foreign.foreign
ptr
val void : unit typ
Value representing the C void type. Void values appear in OCaml as the unit type, so using void in an argument or result type specification produces a function which accepts or returns unit.
Dereferencing a pointer to void is an error, as in C, and will raise IncompleteType
.
The scalar types consist of the Arithmetic types and the Pointer types.
The arithmetic types consist of the signed and unsigned integer types (including character types) and the floating types. There are values representing both exact-width integer types (of 8, 16, 32 and 64 bits) and types whose size depend on the platform (signed and unsigned short, int, long, long long).
val char : char typ
Value representing the C type char
.
val schar : int typ
Value representing the C type signed char
.
val short : int typ
Value representing the C type (signed
) short
.
val int : int typ
Value representing the C type (signed
) int
.
val long : Signed.long typ
Value representing the C type (signed
) long
.
val llong : Signed.llong typ
Value representing the C type (signed
) long long
.
val nativeint : nativeint typ
Value representing the C type (signed
) int
.
val int8_t : int typ
Value representing an 8-bit signed integer C type.
val int16_t : int typ
Value representing a 16-bit signed integer C type.
val int32_t : int32 typ
Value representing a 32-bit signed integer C type.
val int64_t : int64 typ
Value representing a 64-bit signed integer C type.
val camlint : int typ
Value representing an integer type with the same storage requirements as an OCaml int
.
val uchar : Unsigned.uchar typ
Value representing the C type unsigned char
.
val bool : bool typ
Value representing the C type bool
.
val uint8_t : Unsigned.uint8 typ
Value representing an 8-bit unsigned integer C type.
val uint16_t : Unsigned.uint16 typ
Value representing a 16-bit unsigned integer C type.
val uint32_t : Unsigned.uint32 typ
Value representing a 32-bit unsigned integer C type.
val uint64_t : Unsigned.uint64 typ
Value representing a 64-bit unsigned integer C type.
val size_t : Unsigned.size_t typ
Value representing the C type size_t
, an alias for one of the unsigned integer types. The actual size and alignment requirements for size_t
vary between platforms.
val ushort : Unsigned.ushort typ
Value representing the C type unsigned short
.
val sint : Signed.sint typ
Value representing the C type int
.
val uint : Unsigned.uint typ
Value representing the C type unsigned int
.
val ulong : Unsigned.ulong typ
Value representing the C type unsigned long
.
val ullong : Unsigned.ullong typ
Value representing the C type unsigned long long
.
module Uintptr : Unsigned.S
val float : float typ
Value representing the C single-precision float
type.
val double : float typ
Value representing the C type double
.
val complexld : ComplexL.t typ
Value representing the C99 long-double-precision long double complex
type.
val ptr : 'a typ -> 'a Ctypes_static.ptr typ
Construct a pointer type from an existing type (called the reference type).
val ptr_opt : 'a typ -> 'a Ctypes_static.ptr option typ
Construct a pointer type from an existing type (called the reference type). This behaves like ptr
, except that null pointers appear in OCaml as None
.
val string : string typ
A high-level representation of the string type.
On the C side this behaves like char *
; on the OCaml side values read and written using string
are simply native OCaml strings.
To avoid problems with the garbage collector, values passed using string
are copied into immovable C-managed storage before being passed to C.
The string type representation is suitable for use in function argument types such as the following:
string @-> returning int
where the lifetime of the C-managed storage does not need to extend beyond the duration of the function call. However, it is not suitable for use in struct or union fields
field s "x" string
because it does not provide a way to manage the lifetime of the C-managed storage.
val string_opt : string option typ
A high-level representation of the string type. This behaves like string
, except that null pointers appear in OCaml as None
.
val ocaml_string : string Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml string.
val ocaml_bytes : bytes Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml byte array.
val array : int -> 'a typ -> 'a Ctypes_static.carray typ
Construct a sized array type from a length and an existing type (called the element type).
val bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.c_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized C-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val fortran_bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.fortran_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized Fortran-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val typ_of_bigarray_kind : ('a, 'b) Bigarray_compat.kind -> 'a typ
typ_of_bigarray_kind k
is the type corresponding to the Bigarray kind k
.
val structure : string -> 's Ctypes_static.structure typ
Construct a new structure type. The type value returned is incomplete and can be updated using field
until it is passed to seal
, at which point the set of fields is fixed.
The type ('_s structure typ
) of the expression returned by the call structure tag
includes a weak type variable, which can be explicitly instantiated to ensure that the OCaml values representing different C structure types have incompatible types. Typical usage is as follows:
type tagname
let tagname : tagname structure typ = structure "tagname"
val union : string -> 's Ctypes_static.union typ
val field :
+ 't typ ->
+ string ->
+ 'a typ ->
+ ('a, ('s, [< `Struct | `Union ]) Ctypes_static.structured as 't) field
field ty label ty'
adds a field of type ty'
with label label
to the structure or union type ty
and returns a field value that can be used to read and write the field in structure or union instances (e.g. using getf
and setf
).
Attempting to add a field to a union type that has been sealed with seal
is an error, and will raise ModifyingSealedType
.
val seal : (_, [< `Struct | `Union ]) Ctypes_static.structured typ -> unit
seal t
completes the struct or union type t
so that no further fields can be added. Struct and union types must be sealed before they can be used in a way that involves their size or alignment; see the documentation for IncompleteType
for further details.
val view :
+ ?format_typ:((Format.formatter -> unit) -> Format.formatter -> unit) ->
+ ?format:(Format.formatter -> 'b -> unit) ->
+ read:('a -> 'b) ->
+ write:('b -> 'a) ->
+ 'a typ ->
+ 'b typ
view ~read:r ~write:w t
creates a C type representation t'
which behaves like t
except that values read using t'
are subsequently transformed using the function r
and values written using t'
are first transformed using the function w
.
For example, given suitable definitions of string_of_char_ptr
and char_ptr_of_string
, the type representation
view ~read:string_of_char_ptr ~write:char_ptr_of_string (ptr char)
can be used to pass OCaml strings directly to and from bound C functions, or to read and write string members in structs and arrays. (In fact, the string
type representation is defined in exactly this way.)
The optional argument format_typ
is used by the Ctypes.format_typ
and string_of_typ
functions to print the type at the top level and elsewhere. If format_typ
is not supplied the printer for t
is used instead.
The optional argument format
is used by the Ctypes.format
and string_of
functions to print the values. If format_val
is not supplied the printer for t
is used instead.
typedef t name
creates a C type representation t'
which is equivalent to t
except its name is printed as name
.
This is useful when generating C stubs involving "anonymous" types, for example: typedef struct { int f } typedef_name;
val abstract :
+ name:string ->
+ size:int ->
+ alignment:int ->
+ 'a Ctypes_static.abstract typ
Create an abstract type specification from the size and alignment requirements for the type.
val lift_typ : 'a Ctypes_static.typ -> 'a typ
lift_typ t
turns a concrete type representation into an abstract type representation.
For example, retrieving struct layout from C involves working with an abstract representation of types which do not support operations such as sizeof
. The lift_typ
function makes it possible to use concrete type representations wherever such abstract type representations are needed.
Abstract interface to C function type descriptions
type 'a fn = 'a Ctypes_static.fn
The type of values representing C function types. A value of type t fn
can be used to bind to C functions and to describe type of OCaml functions passed to C.
Construct a function type from a type and an existing function type. This corresponds to prepending a parameter to a C function parameter list. For example,
int @-> ptr void @-> returning float
describes a function type that accepts two arguments -- an integer and a pointer to void -- and returns a float.
type 'a static_funptr = 'a Ctypes_static.static_funptr
Function pointer types
The type of values representing C function pointer types.
val static_funptr : 'a fn -> 'a Ctypes_static.static_funptr typ
Construct a function pointer type from an existing function type (called the reference type).
Ctypes_value_printing
val format : 'a. 'a Ctypes_static.typ -> Format.formatter -> 'a -> unit
val format_structured :
+ 'a 'b. Format.formatter ->
+ ('a, 'b) Ctypes_static.structured ->
+ unit
val format_array : 'a. Format.formatter -> 'a Ctypes_static.carray -> unit
val format_ocaml : 'a. Format.formatter -> 'a Ctypes_static.ocaml -> unit
val format_fields :
+ 'a 'b. string ->
+ ('a, 'b) Ctypes_static.structured Ctypes_static.boxed_field list ->
+ Format.formatter ->
+ ('a, 'b) Ctypes_static.structured ->
+ unit
val format_ptr : 'a. Format.formatter -> 'a Ctypes_static.ptr -> unit
val format_funptr :
+ 'a. Format.formatter ->
+ 'a Ctypes_static.static_funptr ->
+ unit
val string_of : 'a Ctypes_static.typ -> 'b -> string
Ctypes_value_printing_stubs
val string_of_prim : 'a Ctypes_primitive_types.prim -> 'a -> string
val string_of_pointer : (_, _) Ctypes_ptr.Fat.t -> string
LDouble
val to_float : t -> float
Convert a long double to a float. The result is unspecified if the argument is either too large or too small to be represented as a float
.
val of_float : float -> t
Create a long double from a float
val to_int : t -> int
Convert a long double to an int. The result is unspecified if the argument is NAN or falls outside the range of representable integers.
val of_int : int -> t
Create a long double from an int
val to_string : ?width:int -> ?prec:int -> t -> string
Convert a long double to a string.
width
specifies the minimum number of digits to format the string with. A negative value left aligns. The default is 0.
prec
specifies the number of digits after the decimal point. The default is 6.
val of_string : string -> t
Create a long double from a string
expm1 x
computes exp x -. 1.0
, giving numerically-accurate results even if x
is close to 0.0
.
log1p x
computes log(1.0 +. x)
(natural logarithm), giving numerically-accurate results even if x
is close to 0.0
.
copysign x y
returns a float whose absolute value is that of x
and whose sign is that of y
.
return (fractional,integer)
parts of number.
Known fatal bug on mingw32; see https://sourceforge.net/p/mingw-w64/bugs/478
Return the class of the given floating-point number: normal, subnormal, zero, infinite, or not a number.
val min_float : t
The smallest positive, non-zero, non-denormalized value
val max_float : t
The largest positive finite value
val epsilon : t
The difference between 1.0
and the smallest exactly representable floating-point number greater than 1.0
.
val nan : t
A special floating-point value denoting the result of an undefined operation such as 0.0 /. 0.0
. Stands for 'not a number'.
val infinity : t
Positive infinity
val neg_infinity : t
Negative infinity
val zero : t
0.0
val one : t
1.0
size, in bytes, used for storing long doubles, and the actual number of bytes used by the value. (unused bytes may contain undefined values)
Dev.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
PosixTypes.Dev
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
Ino.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
PosixTypes.Ino
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
Mode.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
PosixTypes.Mode
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
Nlink.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
PosixTypes.Nlink
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
Off.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
PosixTypes.Off
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Pid.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
PosixTypes.Pid
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Ssize.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
PosixTypes.Ssize
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Time.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
PosixTypes.Time
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
PosixTypes
Some POSIX types.
module Dev : Unsigned.S
module Ino : Unsigned.S
module Mode : Unsigned.S
module Nlink : Unsigned.S
module Time : Unsigned.S
type dev_t = Dev.t
type ino_t = Ino.t
type mode_t = Mode.t
type nlink_t = Nlink.t
type off_t = Off.t
type pid_t = Pid.t
type size_t = Unsigned.size_t
type ssize_t = Ssize.t
type time_t = Time.t
val clock_t : clock_t Ctypes.typ
val dev_t : dev_t Ctypes.typ
val ino_t : ino_t Ctypes.typ
val mode_t : mode_t Ctypes.typ
val nlink_t : nlink_t Ctypes.typ
val off_t : off_t Ctypes.typ
val pid_t : pid_t Ctypes.typ
val size_t : size_t Ctypes.typ
val ssize_t : ssize_t Ctypes.typ
val time_t : time_t Ctypes.typ
val useconds_t : useconds_t Ctypes.typ
val sigset_t : sigset_t Ctypes.typ
This library exposes the following toplevel modules:
ComplexL
Cstubs_internals
Ctypes
The core ctypes module.Ctypes_bigarray
Ctypes_bigarray_stubs
Ctypes_coerce
Ctypes_memory
Ctypes_memory_stubs
Ctypes_primitive_types
Ctypes_primitives
Ctypes_ptr
Ctypes_roots_stubs
Ctypes_static
Ctypes_std_view_stubs
Ctypes_std_views
Ctypes_structs
Ctypes_structs_computed
Structs and unions whose layouts are computed from the sizes and alignment requirements of the constituent field types.Ctypes_type_printing
Ctypes_types
Ctypes_value_printing
Ctypes_value_printing_stubs
LDouble
PosixTypes
Some POSIX types.This library exposes the following toplevel modules:
Cstubs
Operations for generating C bindings stubs.Cstubs_analysis
Cstubs_c_language
Cstubs_emit_c
Cstubs_errors
Cstubs_generate_c
Cstubs_generate_ml
Cstubs_inverted
Operations for exposing OCaml code as C libraries.Cstubs_public_name
Cstubs_structs
Ctypes_path
Cstubs.Types
module type TYPE = Ctypes.TYPE
val write_c : Format.formatter -> (module BINDINGS) -> unit
Intptr.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
F.Intptr
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Ptrdiff.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
F.Ptrdiff
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Uintptr.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
F.Uintptr
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
BINDINGS.F
include Ctypes_types.TYPE
The type of values representing C types. There are two types associated with each typ
value: the C type used to store and pass values, and the corresponding OCaml type. The type parameter indicates the OCaml type, so a value of type t typ
is used to read and write OCaml values of type t
. There are various uses of typ
values, including
Foreign.foreign
ptr
val void : unit typ
Value representing the C void type. Void values appear in OCaml as the unit type, so using void in an argument or result type specification produces a function which accepts or returns unit.
Dereferencing a pointer to void is an error, as in C, and will raise IncompleteType
.
The scalar types consist of the Arithmetic types and the Pointer types.
The arithmetic types consist of the signed and unsigned integer types (including character types) and the floating types. There are values representing both exact-width integer types (of 8, 16, 32 and 64 bits) and types whose size depend on the platform (signed and unsigned short, int, long, long long).
val char : char typ
Value representing the C type char
.
val schar : int typ
Value representing the C type signed char
.
val short : int typ
Value representing the C type (signed
) short
.
val int : int typ
Value representing the C type (signed
) int
.
val long : Signed.long typ
Value representing the C type (signed
) long
.
val llong : Signed.llong typ
Value representing the C type (signed
) long long
.
val nativeint : nativeint typ
Value representing the C type (signed
) int
.
val int8_t : int typ
Value representing an 8-bit signed integer C type.
val int16_t : int typ
Value representing a 16-bit signed integer C type.
val int32_t : int32 typ
Value representing a 32-bit signed integer C type.
val int64_t : int64 typ
Value representing a 64-bit signed integer C type.
val camlint : int typ
Value representing an integer type with the same storage requirements as an OCaml int
.
val uchar : Unsigned.uchar typ
Value representing the C type unsigned char
.
val bool : bool typ
Value representing the C type bool
.
val uint8_t : Unsigned.uint8 typ
Value representing an 8-bit unsigned integer C type.
val uint16_t : Unsigned.uint16 typ
Value representing a 16-bit unsigned integer C type.
val uint32_t : Unsigned.uint32 typ
Value representing a 32-bit unsigned integer C type.
val uint64_t : Unsigned.uint64 typ
Value representing a 64-bit unsigned integer C type.
val size_t : Unsigned.size_t typ
Value representing the C type size_t
, an alias for one of the unsigned integer types. The actual size and alignment requirements for size_t
vary between platforms.
val ushort : Unsigned.ushort typ
Value representing the C type unsigned short
.
val sint : Signed.sint typ
Value representing the C type int
.
val uint : Unsigned.uint typ
Value representing the C type unsigned int
.
val ulong : Unsigned.ulong typ
Value representing the C type unsigned long
.
val ullong : Unsigned.ullong typ
Value representing the C type unsigned long long
.
module Uintptr : Unsigned.S
val float : float typ
Value representing the C single-precision float
type.
val double : float typ
Value representing the C type double
.
val complexld : ComplexL.t typ
Value representing the C99 long-double-precision long double complex
type.
val ptr : 'a typ -> 'a Ctypes_static.ptr typ
Construct a pointer type from an existing type (called the reference type).
val ptr_opt : 'a typ -> 'a Ctypes_static.ptr option typ
Construct a pointer type from an existing type (called the reference type). This behaves like ptr
, except that null pointers appear in OCaml as None
.
val string : string typ
A high-level representation of the string type.
On the C side this behaves like char *
; on the OCaml side values read and written using string
are simply native OCaml strings.
To avoid problems with the garbage collector, values passed using string
are copied into immovable C-managed storage before being passed to C.
The string type representation is suitable for use in function argument types such as the following:
string @-> returning int
where the lifetime of the C-managed storage does not need to extend beyond the duration of the function call. However, it is not suitable for use in struct or union fields
field s "x" string
because it does not provide a way to manage the lifetime of the C-managed storage.
val string_opt : string option typ
A high-level representation of the string type. This behaves like string
, except that null pointers appear in OCaml as None
.
val ocaml_string : string Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml string.
val ocaml_bytes : bytes Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml byte array.
val array : int -> 'a typ -> 'a Ctypes_static.carray typ
Construct a sized array type from a length and an existing type (called the element type).
val bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.c_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized C-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val fortran_bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.fortran_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized Fortran-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val typ_of_bigarray_kind : ('a, 'b) Bigarray_compat.kind -> 'a typ
typ_of_bigarray_kind k
is the type corresponding to the Bigarray kind k
.
val structure : string -> 's Ctypes_static.structure typ
Construct a new structure type. The type value returned is incomplete and can be updated using field
until it is passed to seal
, at which point the set of fields is fixed.
The type ('_s structure typ
) of the expression returned by the call structure tag
includes a weak type variable, which can be explicitly instantiated to ensure that the OCaml values representing different C structure types have incompatible types. Typical usage is as follows:
type tagname
let tagname : tagname structure typ = structure "tagname"
val union : string -> 's Ctypes_static.union typ
val field :
+ 't typ ->
+ string ->
+ 'a typ ->
+ ('a, ('s, [< `Struct | `Union ]) Ctypes_static.structured as 't) field
field ty label ty'
adds a field of type ty'
with label label
to the structure or union type ty
and returns a field value that can be used to read and write the field in structure or union instances (e.g. using getf
and setf
).
Attempting to add a field to a union type that has been sealed with seal
is an error, and will raise ModifyingSealedType
.
val seal : (_, [< `Struct | `Union ]) Ctypes_static.structured typ -> unit
seal t
completes the struct or union type t
so that no further fields can be added. Struct and union types must be sealed before they can be used in a way that involves their size or alignment; see the documentation for IncompleteType
for further details.
val view :
+ ?format_typ:((Format.formatter -> unit) -> Format.formatter -> unit) ->
+ ?format:(Format.formatter -> 'b -> unit) ->
+ read:('a -> 'b) ->
+ write:('b -> 'a) ->
+ 'a typ ->
+ 'b typ
view ~read:r ~write:w t
creates a C type representation t'
which behaves like t
except that values read using t'
are subsequently transformed using the function r
and values written using t'
are first transformed using the function w
.
For example, given suitable definitions of string_of_char_ptr
and char_ptr_of_string
, the type representation
view ~read:string_of_char_ptr ~write:char_ptr_of_string (ptr char)
can be used to pass OCaml strings directly to and from bound C functions, or to read and write string members in structs and arrays. (In fact, the string
type representation is defined in exactly this way.)
The optional argument format_typ
is used by the Ctypes.format_typ
and string_of_typ
functions to print the type at the top level and elsewhere. If format_typ
is not supplied the printer for t
is used instead.
The optional argument format
is used by the Ctypes.format
and string_of
functions to print the values. If format_val
is not supplied the printer for t
is used instead.
typedef t name
creates a C type representation t'
which is equivalent to t
except its name is printed as name
.
This is useful when generating C stubs involving "anonymous" types, for example: typedef struct { int f } typedef_name;
val abstract :
+ name:string ->
+ size:int ->
+ alignment:int ->
+ 'a Ctypes_static.abstract typ
Create an abstract type specification from the size and alignment requirements for the type.
val lift_typ : 'a Ctypes_static.typ -> 'a typ
lift_typ t
turns a concrete type representation into an abstract type representation.
For example, retrieving struct layout from C involves working with an abstract representation of types which do not support operations such as sizeof
. The lift_typ
function makes it possible to use concrete type representations wherever such abstract type representations are needed.
Abstract interface to C function type descriptions
type 'a fn = 'a Ctypes_static.fn
The type of values representing C function types. A value of type t fn
can be used to bind to C functions and to describe type of OCaml functions passed to C.
Construct a function type from a type and an existing function type. This corresponds to prepending a parameter to a C function parameter list. For example,
int @-> ptr void @-> returning float
describes a function type that accepts two arguments -- an integer and a pointer to void -- and returns a float.
type 'a static_funptr = 'a Ctypes_static.static_funptr
Function pointer types
The type of values representing C function pointer types.
val static_funptr : 'a fn -> 'a Ctypes_static.static_funptr typ
Construct a function pointer type from an existing function type (called the reference type).
constant name typ
retrieves the value of the compile-time constant name
of type typ
. It can be used to retrieve enum constants, #defined values and other integer constant expressions.
The type typ
must be either an integer type such as bool
, char
, int
, uint8
, etc., or a view (or perhaps multiple views) where the underlying type is an integer type.
When the value of the constant cannot be represented in the type there will typically be a diagnostic from either the C compiler or the OCaml compiler. For example, gcc will say
warning: overflow in implicit constant conversion
val enum :
+ string ->
+ ?typedef:bool ->
+ ?unexpected:(int64 -> 'a) ->
+ ('a * int64 const) list ->
+ 'a typ
enum name ?unexpected alist
builds a type representation for the enum named name
. The size and alignment are retrieved so that the resulting type can be used everywhere an integer type can be used: as an array element or struct member, as an argument or return value, etc.
The value alist
is an association list of OCaml values and values retrieved by the constant
function. For example, to expose the enum
enum letters { A, B, C = 10, D };
you might first retrieve the values of the enumeration constants:
let a = constant "A" int64_t
+and b = constant "B" int64_t
+and c = constant "C" int64_t
+and d = constant "D" int64_t
and then build the enumeration type
let letters = enum "letters" [
+ `A, a;
+ `B, b;
+ `C, c;
+ `D, d;
+] ~unexpected:(fun i -> `E i)
The unexpected
function specifies the value to return in the case that some unexpected value is encountered -- for example, if a function with the return type 'enum letters' actually returns the value -1
.
The optional flag typedef
specifies whether the first argument, name
, indicates an tag or an alias. If typedef
is false
(the default) then name
is treated as an enumeration tag:
enum letters { ... }
If typedef
is true
then name
is instead treated as an alias:
typedef enum { ... } letters
Types.BINDINGS
Cstubs
Operations for generating C bindings stubs.
module Types : sig ... end
module type FOREIGN = Ctypes.FOREIGN
Values of the errno_policy
type specify the errno support provided by the generated code. See ignore_errno
for the available option.
val ignore_errno : errno_policy
Generate code with no special support for errno. This is the default.
val return_errno : errno_policy
Generate code that returns errno in addition to the return value of each function.
Passing return_errno
as the errno
argument to Cstubs.write_c
and Cstubs.write_ml
changes the return type of bound functions from a single value to a pair of values. For example, the binding specification
let realpath = foreign "reaplath" (string @-> string @-> returning string)
generates a value of the following type by default:
val realpath : string -> string -> stirng
but when using return_errno
the generated type is as follows:
val realpath : string -> string -> stirng * int
and when using both return_errno
and lwt_jobs
the generated type is as follows:
val realpath : string -> string -> (stirng * int) Lwt.t
Values of the concurrency_policy
type specify the concurrency support provided by the generated code. See sequential
and lwt_jobs
for the available options.
val sequential : concurrency_policy
Generate code with no special support for concurrency. This is the default.
val unlocked : concurrency_policy
Generate code that releases the runtime lock during C calls.
val lwt_preemptive : concurrency_policy
Generate code which runs C function calls with the Lwt_preemptive module:
http://ocsigen.org/lwt/2.5.1/api/Lwt_preemptive
Passing lwt_preemptive
as the concurrency
argument to Cstubs.write_c
and Cstubs.write_ml
changes the return type of bound functions to include the Lwt.t
constructor. For example, the binding specification
let unlink = foreign "unlink" (string @-> returning int)
generates a value of the following type by default:
val unlink : string -> int
but when using lwt_preemptive
the generated type is as follows:
val unlink : string -> int Lwt.t
Additionally, the OCaml runtime lock is released during calls to functions bound with lwt_preemptive
.
val lwt_jobs : concurrency_policy
Generate code which implements C function calls as Lwt jobs:
http://ocsigen.org/lwt/2.5.1/api/Lwt_unix#TYPEjob
Passing lwt_jobs
as the concurrency
argument to Cstubs.write_c
and Cstubs.write_ml
changes the return type of bound functions to include the Lwt.t
constructor. For example, the binding specification
let unlink = foreign "unlink" (string @-> returning int)
generates a value of the following type by default:
val unlink : string -> int
but when using lwt_jobs
the generated type is as follows:
val unlink : string -> int Lwt.t
val write_c :
+ ?concurrency:concurrency_policy ->
+ ?errno:errno_policy ->
+ Format.formatter ->
+ prefix:string ->
+ (module BINDINGS) ->
+ unit
write_c fmt ~prefix bindings
generates C stubs for the functions bound with foreign
in bindings
. The stubs are intended to be used in conjunction with the ML code generated by write_ml
.
The optional argument concurrency
specifies the concurrency support provided by the generated code. The default is sequential
.
The generated code uses definitions exposed in the header file ctypes_cstubs_internals.h
.
val write_ml :
+ ?concurrency:concurrency_policy ->
+ ?errno:errno_policy ->
+ Format.formatter ->
+ prefix:string ->
+ (module BINDINGS) ->
+ unit
write_ml fmt ~prefix bindings
generates ML bindings for the functions bound with foreign
in bindings
. The generated code conforms to the FOREIGN
interface.
The optional argument concurrency
specifies the concurrency support provided by the generated code. The default is sequential
.
The generated code uses definitions exposed in the module Cstubs_internals
.
BINDINGS.F
val (@->) : 'a Ctypes.typ -> 'b fn -> ('a -> 'b) fn
val returning : 'a Ctypes.typ -> 'a return fn
val foreign_value : string -> 'a Ctypes.typ -> 'a Ctypes.ptr result
Cstubs.BINDINGS
Cstubs_analysis
val float : 'a Ctypes_static.fn -> bool
val may_allocate : 'a Ctypes_static.fn -> bool
Cstubs_c_language.Type_C
val lookup_field :
+ 's 'a. string ->
+ 'a Ctypes_static.typ ->
+ 's Ctypes_static.boxed_field list ->
+ ty
Cstubs_c_language.Unchecked_function_types
val (@->) :
+ 'a Ctypes_static.typ ->
+ 'b Ctypes_static.fn ->
+ ('a -> 'b) Ctypes_static.fn
val returning : 'a Ctypes_static.typ -> 'a Ctypes_static.fn
Cstubs_c_language
val return_type : 'a. 'a Ctypes_static.fn -> ty
val args : 'a. 'a Ctypes_static.fn -> (string * ty) list
module Type_C : sig ... end
val value : [ `value ] Ctypes_static.abstract Ctypes_static.typ
val reader : string -> 'a Ctypes_static.fn -> cfunction
val conser : string -> 'a Ctypes_static.fn -> cfunction
val immediater : string -> 'a Ctypes_static.fn -> cfunction
module Unchecked_function_types : sig ... end
val prim_prj : 'a. 'a Ctypes_primitive_types.prim -> cfunction
val prim_inj : 'a. 'a Ctypes_primitive_types.prim -> cfunction
Cstubs_emit_c
val format_seq :
+ string ->
+ (Format.formatter -> 'a -> unit) ->
+ string ->
+ string ->
+ Format.formatter ->
+ 'b list ->
+ unit
val format_ty : Format.formatter -> Cstubs_c_language.ty -> unit
val cvar_name :
+ [< `Global of Cstubs_c_language.cglobal | `Local of string * 'a ] ->
+ string
val cvar :
+ Format.formatter ->
+ [< `Global of Cstubs_c_language.cglobal | `Local of string * 'a ] ->
+ unit
val cconst : Format.formatter -> [< `Int of Signed.SInt.t ] -> unit
val camlxParam : Format.formatter -> string list -> unit
val camlParam : Format.formatter -> string list -> unit
val cast_unnecessary : Cstubs_c_language.ty -> Cstubs_c_language.cexp -> bool
val cexp : Format.formatter -> Cstubs_c_language.cexp -> unit
val clvalue : Format.formatter -> Cstubs_c_language.clvalue -> unit
val camlop : Format.formatter -> Cstubs_c_language.camlop -> unit
val ceff : Format.formatter -> Cstubs_c_language.ceff -> unit
val ccomp : Format.formatter -> Cstubs_c_language.ccomp -> unit
val format_parameter_list :
+ (string * Cstubs_c_language.ty) list ->
+ (Format.formatter -> unit) ->
+ Format.formatter ->
+ unit
val cfundec : Format.formatter -> Cstubs_c_language.cfundec -> unit
val storage_class : Format.formatter -> [< `Extern | `Static ] -> unit
val cfundef : Format.formatter -> Cstubs_c_language.cfundef -> unit
Cstubs_errors
val internal_error : ('a, unit, string, 'b) format4 -> 'a
Cstubs_generate_c
val fn :
+ concurrency:[ `Sequential | `Lwt_jobs | `Lwt_preemptive | `Unlocked ] ->
+ errno:[ `Ignore_errno | `Return_errno ] ->
+ cname:string ->
+ stub_name:string ->
+ Format.formatter ->
+ 'a Ctypes.fn ->
+ unit
val value :
+ cname:string ->
+ stub_name:string ->
+ Format.formatter ->
+ 'a Ctypes.typ ->
+ unit
val inverse_fn :
+ stub_name:string ->
+ runtime_lock:bool ->
+ Format.formatter ->
+ 'a Ctypes.fn ->
+ unit
val inverse_fn_decl :
+ stub_name:string ->
+ Format.formatter ->
+ 'a Ctypes.fn ->
+ unit
Cstubs_generate_ml
val extern :
+ concurrency:[ `Sequential | `Lwt_jobs | `Lwt_preemptive | `Unlocked ] ->
+ errno:[ `Ignore_errno | `Return_errno ] ->
+ stub_name:string ->
+ external_name:string ->
+ Format.formatter ->
+ ('a -> 'b) Ctypes.fn ->
+ unit
val case :
+ concurrency:[ `Sequential | `Lwt_jobs | `Lwt_preemptive | `Unlocked ] ->
+ errno:[ `Ignore_errno | `Return_errno ] ->
+ stub_name:string ->
+ external_name:string ->
+ Format.formatter ->
+ ('a -> 'b) Ctypes.fn ->
+ unit
val val_case :
+ stub_name:string ->
+ external_name:string ->
+ Format.formatter ->
+ 'a Ctypes.typ ->
+ unit
val constructor_decl :
+ concurrency:[ `Sequential | `Lwt_jobs | `Lwt_preemptive | `Unlocked ] ->
+ errno:[ `Ignore_errno | `Return_errno ] ->
+ string ->
+ 'a Ctypes.fn ->
+ Format.formatter ->
+ unit
val inverse_case :
+ register_name:string ->
+ constructor:string ->
+ string ->
+ Format.formatter ->
+ ('a -> 'b) Ctypes.fn ->
+ unit
Cstubs_inverted
Operations for exposing OCaml code as C libraries.
module type INTERNAL = sig ... end
val write_c : Format.formatter -> prefix:string -> (module BINDINGS) -> unit
write_c fmt ~prefix bindings
generates C stubs for the functions bound with internal
in bindings
. The stubs are intended to be used in conjunction with the ML code generated by write_ml
.
The generated code uses definitions exposed in the header file cstubs_internals.h
.
val write_c_header :
+ Format.formatter ->
+ prefix:string ->
+ (module BINDINGS) ->
+ unit
write_c_header fmt ~prefix bindings
generates a C header file for the functions bound with internal
in bindings
. The stubs are intended to be used in conjunction with the C code generated by write_c
.
val write_ml : Format.formatter -> prefix:string -> (module BINDINGS) -> unit
write_ml fmt ~prefix bindings
generates ML bindings for the functions bound with internal
in bindings
. The generated code conforms to the INTERNAL
interface.
The generated code uses definitions exposed in the module Cstubs_internals
.
BINDINGS.F
val enum : (string * int64) list -> 'a Ctypes.typ -> unit
val structure : _ Ctypes.structure Ctypes.typ -> unit
val union : _ Ctypes.union Ctypes.typ -> unit
val typedef : _ Ctypes.typ -> string -> unit
val internal :
+ ?runtime_lock:bool ->
+ string ->
+ ('a -> 'b) Ctypes.fn ->
+ ('a -> 'b) ->
+ unit
Cstubs_inverted.BINDINGS
Cstubs_inverted.INTERNAL
val enum : (string * int64) list -> 'a Ctypes.typ -> unit
val structure : _ Ctypes.structure Ctypes.typ -> unit
val union : _ Ctypes.union Ctypes.typ -> unit
val typedef : _ Ctypes.typ -> string -> unit
val internal :
+ ?runtime_lock:bool ->
+ string ->
+ ('a -> 'b) Ctypes.fn ->
+ ('a -> 'b) ->
+ unit
Cstubs_public_name
val ident_of_ml_prim : 'a Ctypes_primitive_types.ml_prim -> Ctypes_path.path
val constructor_ident_of_prim :
+ 'a Ctypes_primitive_types.prim ->
+ Ctypes_path.path
val constructor_cident_of_prim :
+ ?module_name:string ->
+ 'a Ctypes_primitive_types.prim ->
+ Ctypes_path.path
Cstubs_structs
module type TYPE = sig ... end
val write_c : Format.formatter -> (module BINDINGS) -> unit
Intptr.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
F.Intptr
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Ptrdiff.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
F.Ptrdiff
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Uintptr.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
F.Uintptr
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
BINDINGS.F
include Ctypes_types.TYPE
The type of values representing C types. There are two types associated with each typ
value: the C type used to store and pass values, and the corresponding OCaml type. The type parameter indicates the OCaml type, so a value of type t typ
is used to read and write OCaml values of type t
. There are various uses of typ
values, including
Foreign.foreign
ptr
val void : unit typ
Value representing the C void type. Void values appear in OCaml as the unit type, so using void in an argument or result type specification produces a function which accepts or returns unit.
Dereferencing a pointer to void is an error, as in C, and will raise IncompleteType
.
The scalar types consist of the Arithmetic types and the Pointer types.
The arithmetic types consist of the signed and unsigned integer types (including character types) and the floating types. There are values representing both exact-width integer types (of 8, 16, 32 and 64 bits) and types whose size depend on the platform (signed and unsigned short, int, long, long long).
val char : char typ
Value representing the C type char
.
val schar : int typ
Value representing the C type signed char
.
val short : int typ
Value representing the C type (signed
) short
.
val int : int typ
Value representing the C type (signed
) int
.
val long : Signed.long typ
Value representing the C type (signed
) long
.
val llong : Signed.llong typ
Value representing the C type (signed
) long long
.
val nativeint : nativeint typ
Value representing the C type (signed
) int
.
val int8_t : int typ
Value representing an 8-bit signed integer C type.
val int16_t : int typ
Value representing a 16-bit signed integer C type.
val int32_t : int32 typ
Value representing a 32-bit signed integer C type.
val int64_t : int64 typ
Value representing a 64-bit signed integer C type.
val camlint : int typ
Value representing an integer type with the same storage requirements as an OCaml int
.
val uchar : Unsigned.uchar typ
Value representing the C type unsigned char
.
val bool : bool typ
Value representing the C type bool
.
val uint8_t : Unsigned.uint8 typ
Value representing an 8-bit unsigned integer C type.
val uint16_t : Unsigned.uint16 typ
Value representing a 16-bit unsigned integer C type.
val uint32_t : Unsigned.uint32 typ
Value representing a 32-bit unsigned integer C type.
val uint64_t : Unsigned.uint64 typ
Value representing a 64-bit unsigned integer C type.
val size_t : Unsigned.size_t typ
Value representing the C type size_t
, an alias for one of the unsigned integer types. The actual size and alignment requirements for size_t
vary between platforms.
val ushort : Unsigned.ushort typ
Value representing the C type unsigned short
.
val sint : Signed.sint typ
Value representing the C type int
.
val uint : Unsigned.uint typ
Value representing the C type unsigned int
.
val ulong : Unsigned.ulong typ
Value representing the C type unsigned long
.
val ullong : Unsigned.ullong typ
Value representing the C type unsigned long long
.
module Uintptr : Unsigned.S
val float : float typ
Value representing the C single-precision float
type.
val double : float typ
Value representing the C type double
.
val complexld : ComplexL.t typ
Value representing the C99 long-double-precision long double complex
type.
val ptr : 'a typ -> 'a Ctypes_static.ptr typ
Construct a pointer type from an existing type (called the reference type).
val ptr_opt : 'a typ -> 'a Ctypes_static.ptr option typ
Construct a pointer type from an existing type (called the reference type). This behaves like ptr
, except that null pointers appear in OCaml as None
.
val string : string typ
A high-level representation of the string type.
On the C side this behaves like char *
; on the OCaml side values read and written using string
are simply native OCaml strings.
To avoid problems with the garbage collector, values passed using string
are copied into immovable C-managed storage before being passed to C.
The string type representation is suitable for use in function argument types such as the following:
string @-> returning int
where the lifetime of the C-managed storage does not need to extend beyond the duration of the function call. However, it is not suitable for use in struct or union fields
field s "x" string
because it does not provide a way to manage the lifetime of the C-managed storage.
val string_opt : string option typ
A high-level representation of the string type. This behaves like string
, except that null pointers appear in OCaml as None
.
val ocaml_string : string Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml string.
val ocaml_bytes : bytes Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml byte array.
val array : int -> 'a typ -> 'a Ctypes_static.carray typ
Construct a sized array type from a length and an existing type (called the element type).
val bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.c_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized C-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val fortran_bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.fortran_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized Fortran-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val typ_of_bigarray_kind : ('a, 'b) Bigarray_compat.kind -> 'a typ
typ_of_bigarray_kind k
is the type corresponding to the Bigarray kind k
.
val structure : string -> 's Ctypes_static.structure typ
Construct a new structure type. The type value returned is incomplete and can be updated using field
until it is passed to seal
, at which point the set of fields is fixed.
The type ('_s structure typ
) of the expression returned by the call structure tag
includes a weak type variable, which can be explicitly instantiated to ensure that the OCaml values representing different C structure types have incompatible types. Typical usage is as follows:
type tagname
let tagname : tagname structure typ = structure "tagname"
val union : string -> 's Ctypes_static.union typ
val field :
+ 't typ ->
+ string ->
+ 'a typ ->
+ ('a, ('s, [< `Struct | `Union ]) Ctypes_static.structured as 't) field
field ty label ty'
adds a field of type ty'
with label label
to the structure or union type ty
and returns a field value that can be used to read and write the field in structure or union instances (e.g. using getf
and setf
).
Attempting to add a field to a union type that has been sealed with seal
is an error, and will raise ModifyingSealedType
.
val seal : (_, [< `Struct | `Union ]) Ctypes_static.structured typ -> unit
seal t
completes the struct or union type t
so that no further fields can be added. Struct and union types must be sealed before they can be used in a way that involves their size or alignment; see the documentation for IncompleteType
for further details.
val view :
+ ?format_typ:((Format.formatter -> unit) -> Format.formatter -> unit) ->
+ ?format:(Format.formatter -> 'b -> unit) ->
+ read:('a -> 'b) ->
+ write:('b -> 'a) ->
+ 'a typ ->
+ 'b typ
view ~read:r ~write:w t
creates a C type representation t'
which behaves like t
except that values read using t'
are subsequently transformed using the function r
and values written using t'
are first transformed using the function w
.
For example, given suitable definitions of string_of_char_ptr
and char_ptr_of_string
, the type representation
view ~read:string_of_char_ptr ~write:char_ptr_of_string (ptr char)
can be used to pass OCaml strings directly to and from bound C functions, or to read and write string members in structs and arrays. (In fact, the string
type representation is defined in exactly this way.)
The optional argument format_typ
is used by the Ctypes.format_typ
and string_of_typ
functions to print the type at the top level and elsewhere. If format_typ
is not supplied the printer for t
is used instead.
The optional argument format
is used by the Ctypes.format
and string_of
functions to print the values. If format_val
is not supplied the printer for t
is used instead.
typedef t name
creates a C type representation t'
which is equivalent to t
except its name is printed as name
.
This is useful when generating C stubs involving "anonymous" types, for example: typedef struct { int f } typedef_name;
val abstract :
+ name:string ->
+ size:int ->
+ alignment:int ->
+ 'a Ctypes_static.abstract typ
Create an abstract type specification from the size and alignment requirements for the type.
val lift_typ : 'a Ctypes_static.typ -> 'a typ
lift_typ t
turns a concrete type representation into an abstract type representation.
For example, retrieving struct layout from C involves working with an abstract representation of types which do not support operations such as sizeof
. The lift_typ
function makes it possible to use concrete type representations wherever such abstract type representations are needed.
Abstract interface to C function type descriptions
type 'a fn = 'a Ctypes_static.fn
The type of values representing C function types. A value of type t fn
can be used to bind to C functions and to describe type of OCaml functions passed to C.
Construct a function type from a type and an existing function type. This corresponds to prepending a parameter to a C function parameter list. For example,
int @-> ptr void @-> returning float
describes a function type that accepts two arguments -- an integer and a pointer to void -- and returns a float.
type 'a static_funptr = 'a Ctypes_static.static_funptr
Function pointer types
The type of values representing C function pointer types.
val static_funptr : 'a fn -> 'a Ctypes_static.static_funptr typ
Construct a function pointer type from an existing function type (called the reference type).
Cstubs_structs.BINDINGS
Intptr.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
TYPE.Intptr
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Ptrdiff.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
TYPE.Ptrdiff
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Uintptr.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
TYPE.Uintptr
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
Cstubs_structs.TYPE
include Ctypes_types.TYPE
The type of values representing C types. There are two types associated with each typ
value: the C type used to store and pass values, and the corresponding OCaml type. The type parameter indicates the OCaml type, so a value of type t typ
is used to read and write OCaml values of type t
. There are various uses of typ
values, including
Foreign.foreign
ptr
val void : unit typ
Value representing the C void type. Void values appear in OCaml as the unit type, so using void in an argument or result type specification produces a function which accepts or returns unit.
Dereferencing a pointer to void is an error, as in C, and will raise IncompleteType
.
The scalar types consist of the Arithmetic types and the Pointer types.
The arithmetic types consist of the signed and unsigned integer types (including character types) and the floating types. There are values representing both exact-width integer types (of 8, 16, 32 and 64 bits) and types whose size depend on the platform (signed and unsigned short, int, long, long long).
val char : char typ
Value representing the C type char
.
val schar : int typ
Value representing the C type signed char
.
val short : int typ
Value representing the C type (signed
) short
.
val int : int typ
Value representing the C type (signed
) int
.
val long : Signed.long typ
Value representing the C type (signed
) long
.
val llong : Signed.llong typ
Value representing the C type (signed
) long long
.
val nativeint : nativeint typ
Value representing the C type (signed
) int
.
val int8_t : int typ
Value representing an 8-bit signed integer C type.
val int16_t : int typ
Value representing a 16-bit signed integer C type.
val int32_t : int32 typ
Value representing a 32-bit signed integer C type.
val int64_t : int64 typ
Value representing a 64-bit signed integer C type.
val camlint : int typ
Value representing an integer type with the same storage requirements as an OCaml int
.
val uchar : Unsigned.uchar typ
Value representing the C type unsigned char
.
val bool : bool typ
Value representing the C type bool
.
val uint8_t : Unsigned.uint8 typ
Value representing an 8-bit unsigned integer C type.
val uint16_t : Unsigned.uint16 typ
Value representing a 16-bit unsigned integer C type.
val uint32_t : Unsigned.uint32 typ
Value representing a 32-bit unsigned integer C type.
val uint64_t : Unsigned.uint64 typ
Value representing a 64-bit unsigned integer C type.
val size_t : Unsigned.size_t typ
Value representing the C type size_t
, an alias for one of the unsigned integer types. The actual size and alignment requirements for size_t
vary between platforms.
val ushort : Unsigned.ushort typ
Value representing the C type unsigned short
.
val sint : Signed.sint typ
Value representing the C type int
.
val uint : Unsigned.uint typ
Value representing the C type unsigned int
.
val ulong : Unsigned.ulong typ
Value representing the C type unsigned long
.
val ullong : Unsigned.ullong typ
Value representing the C type unsigned long long
.
module Uintptr : Unsigned.S
val float : float typ
Value representing the C single-precision float
type.
val double : float typ
Value representing the C type double
.
val complexld : ComplexL.t typ
Value representing the C99 long-double-precision long double complex
type.
val ptr : 'a typ -> 'a Ctypes_static.ptr typ
Construct a pointer type from an existing type (called the reference type).
val ptr_opt : 'a typ -> 'a Ctypes_static.ptr option typ
Construct a pointer type from an existing type (called the reference type). This behaves like ptr
, except that null pointers appear in OCaml as None
.
val string : string typ
A high-level representation of the string type.
On the C side this behaves like char *
; on the OCaml side values read and written using string
are simply native OCaml strings.
To avoid problems with the garbage collector, values passed using string
are copied into immovable C-managed storage before being passed to C.
The string type representation is suitable for use in function argument types such as the following:
string @-> returning int
where the lifetime of the C-managed storage does not need to extend beyond the duration of the function call. However, it is not suitable for use in struct or union fields
field s "x" string
because it does not provide a way to manage the lifetime of the C-managed storage.
val string_opt : string option typ
A high-level representation of the string type. This behaves like string
, except that null pointers appear in OCaml as None
.
val ocaml_string : string Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml string.
val ocaml_bytes : bytes Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml byte array.
val array : int -> 'a typ -> 'a Ctypes_static.carray typ
Construct a sized array type from a length and an existing type (called the element type).
val bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.c_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized C-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val fortran_bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.fortran_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized Fortran-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val typ_of_bigarray_kind : ('a, 'b) Bigarray_compat.kind -> 'a typ
typ_of_bigarray_kind k
is the type corresponding to the Bigarray kind k
.
val structure : string -> 's Ctypes_static.structure typ
Construct a new structure type. The type value returned is incomplete and can be updated using field
until it is passed to seal
, at which point the set of fields is fixed.
The type ('_s structure typ
) of the expression returned by the call structure tag
includes a weak type variable, which can be explicitly instantiated to ensure that the OCaml values representing different C structure types have incompatible types. Typical usage is as follows:
type tagname
let tagname : tagname structure typ = structure "tagname"
val union : string -> 's Ctypes_static.union typ
val field :
+ 't typ ->
+ string ->
+ 'a typ ->
+ ('a, ('s, [< `Struct | `Union ]) Ctypes_static.structured as 't) field
field ty label ty'
adds a field of type ty'
with label label
to the structure or union type ty
and returns a field value that can be used to read and write the field in structure or union instances (e.g. using getf
and setf
).
Attempting to add a field to a union type that has been sealed with seal
is an error, and will raise ModifyingSealedType
.
val seal : (_, [< `Struct | `Union ]) Ctypes_static.structured typ -> unit
seal t
completes the struct or union type t
so that no further fields can be added. Struct and union types must be sealed before they can be used in a way that involves their size or alignment; see the documentation for IncompleteType
for further details.
val view :
+ ?format_typ:((Format.formatter -> unit) -> Format.formatter -> unit) ->
+ ?format:(Format.formatter -> 'b -> unit) ->
+ read:('a -> 'b) ->
+ write:('b -> 'a) ->
+ 'a typ ->
+ 'b typ
view ~read:r ~write:w t
creates a C type representation t'
which behaves like t
except that values read using t'
are subsequently transformed using the function r
and values written using t'
are first transformed using the function w
.
For example, given suitable definitions of string_of_char_ptr
and char_ptr_of_string
, the type representation
view ~read:string_of_char_ptr ~write:char_ptr_of_string (ptr char)
can be used to pass OCaml strings directly to and from bound C functions, or to read and write string members in structs and arrays. (In fact, the string
type representation is defined in exactly this way.)
The optional argument format_typ
is used by the Ctypes.format_typ
and string_of_typ
functions to print the type at the top level and elsewhere. If format_typ
is not supplied the printer for t
is used instead.
The optional argument format
is used by the Ctypes.format
and string_of
functions to print the values. If format_val
is not supplied the printer for t
is used instead.
typedef t name
creates a C type representation t'
which is equivalent to t
except its name is printed as name
.
This is useful when generating C stubs involving "anonymous" types, for example: typedef struct { int f } typedef_name;
val abstract :
+ name:string ->
+ size:int ->
+ alignment:int ->
+ 'a Ctypes_static.abstract typ
Create an abstract type specification from the size and alignment requirements for the type.
val lift_typ : 'a Ctypes_static.typ -> 'a typ
lift_typ t
turns a concrete type representation into an abstract type representation.
For example, retrieving struct layout from C involves working with an abstract representation of types which do not support operations such as sizeof
. The lift_typ
function makes it possible to use concrete type representations wherever such abstract type representations are needed.
Abstract interface to C function type descriptions
type 'a fn = 'a Ctypes_static.fn
The type of values representing C function types. A value of type t fn
can be used to bind to C functions and to describe type of OCaml functions passed to C.
Construct a function type from a type and an existing function type. This corresponds to prepending a parameter to a C function parameter list. For example,
int @-> ptr void @-> returning float
describes a function type that accepts two arguments -- an integer and a pointer to void -- and returns a float.
type 'a static_funptr = 'a Ctypes_static.static_funptr
Function pointer types
The type of values representing C function pointer types.
val static_funptr : 'a fn -> 'a Ctypes_static.static_funptr typ
Construct a function pointer type from an existing function type (called the reference type).
Ctypes_path
This library exposes the following toplevel modules:
Cstubs
Operations for generating C bindings stubs.Cstubs_analysis
Cstubs_c_language
Cstubs_emit_c
Cstubs_errors
Cstubs_generate_c
Cstubs_generate_ml
Cstubs_inverted
Operations for exposing OCaml code as C libraries.Cstubs_public_name
Cstubs_structs
Ctypes_path
Packages installed in /home/runner/work/quickjs.ml/quickjs.ml/_opam/lib
Int.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Signed.Int
Signed integer type and operations.
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Int32.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Signed.Int32
Signed 32-bit integer type and operations.
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Int64.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Signed.Int64
Signed 64-bit integer type and operations.
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
LLong.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Signed.LLong
The signed long long integer type and operations.
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Long.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Signed.Long
The signed long integer type and operations.
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
SInt.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Signed.SInt
C's signed integer type and operations.
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Signed
Types and operations for signed integers.
module type Infix = sig ... end
module type S = sig ... end
Signed integer operations
type sint = SInt.t
C's signed integer type.
type long = Long.t
The signed long integer type.
type llong = LLong.t
The signed long long integer type.
val of_byte_size : int -> (module S)
of_byte_size b
is a module of type S that implements a signed type with b
bytes.
Raise Invalid_argument
if no suitable type is available.
Signed.Infix
include Unsigned.Infix with type t := t
S.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
Signed.S
Signed integer operations
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Size_t.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Unsigned.Size_t
The size_t unsigned integer type and operations.
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
UChar.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Unsigned.UChar
Unsigned char type and operations.
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
UInt.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Unsigned.UInt
The unsigned int type and operations.
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
UInt16.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Unsigned.UInt16
Unsigned 16-bit integer type and operations.
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
UInt32.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Unsigned.UInt32
Unsigned 32-bit integer type and operations.
include S
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val of_int32 : int32 -> t
Convert the given 32-bit signed integer to an unsigned 32-bit integer.
If the signed integer fits within the unsigned range (in other words, if the signed integer is positive) then the numerical values represented by the signed and unsigned integers are the same.
Whether the signed integer fits or not, the function of_int32
is always the inverse of the function to_int32
. In other words, to_int32 (of_int32 x) = x
holds for all x : int32
.
val to_int32 : t -> int32
Convert the given 32-bit unsigned integer to a signed 32-bit integer.
If the unsigned integer fits within the signed range (in other words, if the unsigned integer is less than Int32.max_int
) then the numerical values represented by unsigned and signed integers are the same.
Whether the unsigned integer fits or not, the function to_int32
is always the inverse of the function of_int32
. In other words, of_int32 (to_int32 x) = x
holds for all x : t
.
UInt64.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Unsigned.UInt64
Unsigned 64-bit integer type and operations.
include S
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val of_int64 : int64 -> t
Convert the given 64-bit signed integer to an unsigned 64-bit integer.
If the signed integer fits within the unsigned range (in other words, if the signed integer is positive) then the numerical values represented by the signed and unsigned integers are the same.
Whether the signed integer fits or not, the function of_int64
is always the inverse of the function to_int64
. In other words, to_int64 (of_int64 x) = x
holds for all x : int64
.
val to_int64 : t -> int64
Convert the given 64-bit unsigned integer to a signed 64-bit integer.
If the unsigned integer fits within the signed range (in other words, if the unsigned integer is less than Int64.max_int
) then the numerical values represented by unsigned and signed integers are the same.
Whether the unsigned integer fits or not, the function to_int64
is always the inverse of the function of_int64
. In other words, of_int64 (to_int64 x) = x
holds for all x : t
.
Convert the given 32-bit unsigned integer to a 64-bit unsigned integer.
UInt8.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Unsigned.UInt8
Unsigned 8-bit integer type and operations.
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
ULLong.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Unsigned.ULLong
The unsigned long long integer type and operations.
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
ULong.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Unsigned.ULong
The unsigned long integer type and operations.
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
UShort.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Unsigned.UShort
The unsigned short integer type and operations.
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
Unsigned
Types and operations for unsigned integers.
module type Infix = sig ... end
Infix names for the unsigned integer operations.
module type S = sig ... end
Unsigned integer operations.
module UInt32 : sig ... end
Unsigned 32-bit integer type and operations.
module UInt64 : sig ... end
Unsigned 64-bit integer type and operations.
type uchar = UChar.t
The unsigned char type.
type uint8 = UInt8.t
Unsigned 8-bit integer type.
type uint16 = UInt16.t
Unsigned 16-bit integer type.
type uint32 = UInt32.t
Unsigned 32-bit integer type.
type uint64 = UInt64.t
Unsigned 64-bit integer type.
type size_t = Size_t.t
The size_t unsigned integer type.
type ushort = UShort.t
The unsigned short unsigned integer type.
type uint = UInt.t
The unsigned int type.
type ulong = ULong.t
The unsigned long integer type.
type ullong = ULLong.t
The unsigned long long integer type.
val of_byte_size : int -> (module S)
of_byte_size b
is a module of type S that implements an unsigned type with b
bytes.
Raise Invalid_argument
if no suitable type is available.
Unsigned.Infix
Infix names for the unsigned integer operations.
S.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
Unsigned.S
Unsigned integer operations.
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
Quickjs.RegExp
val compile : string -> string -> t
Constructs a RegExp.t from a string describing a regex and their flags
val lastIndex : t -> int
returns the index where the next match will start its search
val setLastIndex : t -> int -> unit
sets the index at which the next match (RegExp.exec or RegExp.test) will start its search from
val flags : t -> string
returns the enabled flags as a string
val global : t -> bool
returns a bool indicating whether the global flag (g) is set
val ignorecase : t -> bool
returns a bool indicating whether the ignorecase (i) flag is set
val multiline : t -> bool
returns a bool indicating whether the multiline (m) flag is set
val dotall : t -> bool
returns a bool indicating whether the dot all (s) flag is set
val sticky : t -> bool
returns a bool indicating whether the sticky (y) flag is set
val unicode : t -> bool
returns a bool indicating whether the unicode (u ) flag is set
val source : t -> string
returns the regexp pattern as a string
val test : t -> string -> bool
checks whether the given RegExp.t will match (or not match) a given string
val captures : result -> string array
an array of the match and captures
val input : result -> string
the original input string
val index : result -> int
sets the index at which the next match (RegExp.exec or RegExp.test) will start its search from
Quickjs
module RegExp : sig ... end
C.Functions
val lre_compile :
+ (int Ctypes_static.ptr ->
+ char Ctypes_static.ptr ->
+ int ->
+ string Ctypes_static.ocaml ->
+ Unsigned.size_t ->
+ int ->
+ unit Ctypes_static.ptr ->
+ Unsigned.uint8 Ctypes_static.ptr
+ Bindings.Libregexp__c_generated_functions__Function_description__Functions.return)
+ Bindings.Libregexp__c_generated_functions__Function_description__Functions.result
val lre_exec :
+ (Unsigned.uint8 Ctypes_static.ptr Ctypes_static.ptr ->
+ Unsigned.uint8 Ctypes_static.ptr ->
+ Unsigned.uint8 Ctypes_static.ptr ->
+ int ->
+ int ->
+ int ->
+ unit Ctypes_static.ptr ->
+ int
+ Bindings.Libregexp__c_generated_functions__Function_description__Functions.return)
+ Bindings.Libregexp__c_generated_functions__Function_description__Functions.result
val lre_get_capture_count :
+ (Unsigned.uint8 Ctypes_static.ptr ->
+ int
+ Bindings.Libregexp__c_generated_functions__Function_description__Functions.return)
+ Bindings.Libregexp__c_generated_functions__Function_description__Functions.result
val lre_get_flags :
+ (Unsigned.uint8 Ctypes_static.ptr ->
+ int
+ Bindings.Libregexp__c_generated_functions__Function_description__Functions.return)
+ Bindings.Libregexp__c_generated_functions__Function_description__Functions.result
Bindings.C
module Type = Types_generated
module Functions : sig ... end
Functions.F
val (@->) : 'a Ctypes.typ -> 'b fn -> ('a -> 'b) fn
val returning : 'a Ctypes.typ -> 'a return fn
val foreign_value : string -> 'a Ctypes.typ -> 'a Ctypes.ptr result
Function_description.Functions
module F : Ctypes.FOREIGN
val lre_compile :
+ (int Ctypes_static.ptr ->
+ char Ctypes_static.ptr ->
+ int ->
+ string Ctypes_static.ocaml ->
+ Unsigned.size_t ->
+ int ->
+ unit Ctypes_static.ptr ->
+ Unsigned.uint8 Ctypes_static.ptr F.return)
+ F.result
val lre_exec :
+ (Unsigned.uint8 Ctypes_static.ptr Ctypes_static.ptr ->
+ Unsigned.uint8 Ctypes_static.ptr ->
+ Unsigned.uint8 Ctypes_static.ptr ->
+ int ->
+ int ->
+ int ->
+ unit Ctypes_static.ptr ->
+ int F.return)
+ F.result
val lre_get_capture_count :
+ (Unsigned.uint8 Ctypes_static.ptr -> int F.return) F.result
val lre_get_flags : (Unsigned.uint8 Ctypes_static.ptr -> int F.return) F.result
Bindings.Function_description
module Types = Types_generated
module Functions (F : Ctypes.FOREIGN) : sig ... end
Intptr.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
T.Intptr
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Ptrdiff.Infix
include Unsigned.Infix with type t := t
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
x asr y
shifts x
to the right by y
bits. See shift_right
.
T.Ptrdiff
module Infix : Signed.Infix with type t := t
include Unsigned.S with type t := t with module Infix := Infix
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
val minus_one : t
The value -1
val min_int : t
The smallest representable integer.
shift_right_logical
x
y
shifts x
to the right by y
bits. See Int32.shift_right_logical
.
val of_nativeint : nativeint -> t
Convert the given nativeint value to a signed integer.
val to_nativeint : t -> nativeint
Convert the given signed integer to a nativeint value.
val of_int64 : int64 -> t
Convert the given int64 value to a signed integer.
val to_int64 : t -> int64
Convert the given signed integer to an int64 value.
Uintptr.Infix
x lsl y
shifts x
to the left by y
bits. See shift_left
.
x lsr y
shifts x
to the right by y
bits. See shift_right
.
T.Uintptr
Division. Raise Division_by_zero
if the second argument is zero.
Integer remainder. Raise Division_by_zero
if the second argument is zero.
val max_int : t
The greatest representable integer.
shift_left
x
y
shifts x
to the left by y
bits.
shift_right
x
y
shifts x
to the right by y
bits.
val of_int : int -> t
Convert the given int value to an unsigned integer.
val to_int : t -> int
Convert the given unsigned integer value to an int.
val of_int64 : int64 -> t
Convert the given int64 value to an unsigned integer.
val to_int64 : t -> int64
Convert the given unsigned integer value to an int64.
val of_string : string -> t
Convert the given string to an unsigned integer. Raise Failure
if the given string is not a valid representation of an unsigned integer.
val to_string : t -> string
Return the string representation of its argument.
val to_hexstring : t -> string
Return the hexadecimal string representation of its argument.
val zero : t
The integer 0.
val one : t
The integer 1.
The comparison function for unsigned integers, with the same specification as Stdlib.compare
.
Tests for equality, with the same specification as Stdlib.(=)
.
val of_string_opt : string -> t option
Convert the given string to an unsigned integer. Returns None
if the given string is not a valid representation of an unsigned integer.
val pp : Format.formatter -> t -> unit
Output the result of to_string
on a formatter.
val pp_hex : Format.formatter -> t -> unit
Output the result of to_hexstring
on a formatter.
module Infix : Unsigned.Infix with type t := t
Types.T
include Ctypes_types.TYPE
The type of values representing C types. There are two types associated with each typ
value: the C type used to store and pass values, and the corresponding OCaml type. The type parameter indicates the OCaml type, so a value of type t typ
is used to read and write OCaml values of type t
. There are various uses of typ
values, including
Foreign.foreign
ptr
val void : unit typ
Value representing the C void type. Void values appear in OCaml as the unit type, so using void in an argument or result type specification produces a function which accepts or returns unit.
Dereferencing a pointer to void is an error, as in C, and will raise IncompleteType
.
The scalar types consist of the Arithmetic types and the Pointer types.
The arithmetic types consist of the signed and unsigned integer types (including character types) and the floating types. There are values representing both exact-width integer types (of 8, 16, 32 and 64 bits) and types whose size depend on the platform (signed and unsigned short, int, long, long long).
val char : char typ
Value representing the C type char
.
val schar : int typ
Value representing the C type signed char
.
val short : int typ
Value representing the C type (signed
) short
.
val int : int typ
Value representing the C type (signed
) int
.
val long : Signed.long typ
Value representing the C type (signed
) long
.
val llong : Signed.llong typ
Value representing the C type (signed
) long long
.
val nativeint : nativeint typ
Value representing the C type (signed
) int
.
val int8_t : int typ
Value representing an 8-bit signed integer C type.
val int16_t : int typ
Value representing a 16-bit signed integer C type.
val int32_t : int32 typ
Value representing a 32-bit signed integer C type.
val int64_t : int64 typ
Value representing a 64-bit signed integer C type.
val camlint : int typ
Value representing an integer type with the same storage requirements as an OCaml int
.
val uchar : Unsigned.uchar typ
Value representing the C type unsigned char
.
val bool : bool typ
Value representing the C type bool
.
val uint8_t : Unsigned.uint8 typ
Value representing an 8-bit unsigned integer C type.
val uint16_t : Unsigned.uint16 typ
Value representing a 16-bit unsigned integer C type.
val uint32_t : Unsigned.uint32 typ
Value representing a 32-bit unsigned integer C type.
val uint64_t : Unsigned.uint64 typ
Value representing a 64-bit unsigned integer C type.
val size_t : Unsigned.size_t typ
Value representing the C type size_t
, an alias for one of the unsigned integer types. The actual size and alignment requirements for size_t
vary between platforms.
val ushort : Unsigned.ushort typ
Value representing the C type unsigned short
.
val sint : Signed.sint typ
Value representing the C type int
.
val uint : Unsigned.uint typ
Value representing the C type unsigned int
.
val ulong : Unsigned.ulong typ
Value representing the C type unsigned long
.
val ullong : Unsigned.ullong typ
Value representing the C type unsigned long long
.
module Uintptr : Unsigned.S
val float : float typ
Value representing the C single-precision float
type.
val double : float typ
Value representing the C type double
.
val complexld : ComplexL.t typ
Value representing the C99 long-double-precision long double complex
type.
val ptr : 'a typ -> 'a Ctypes_static.ptr typ
Construct a pointer type from an existing type (called the reference type).
val ptr_opt : 'a typ -> 'a Ctypes_static.ptr option typ
Construct a pointer type from an existing type (called the reference type). This behaves like ptr
, except that null pointers appear in OCaml as None
.
val string : string typ
A high-level representation of the string type.
On the C side this behaves like char *
; on the OCaml side values read and written using string
are simply native OCaml strings.
To avoid problems with the garbage collector, values passed using string
are copied into immovable C-managed storage before being passed to C.
The string type representation is suitable for use in function argument types such as the following:
string @-> returning int
where the lifetime of the C-managed storage does not need to extend beyond the duration of the function call. However, it is not suitable for use in struct or union fields
field s "x" string
because it does not provide a way to manage the lifetime of the C-managed storage.
val string_opt : string option typ
A high-level representation of the string type. This behaves like string
, except that null pointers appear in OCaml as None
.
val ocaml_string : string Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml string.
val ocaml_bytes : bytes Ctypes_static.ocaml typ
Value representing the directly mapped storage of an OCaml byte array.
val array : int -> 'a typ -> 'a Ctypes_static.carray typ
Construct a sized array type from a length and an existing type (called the element type).
val bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.c_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized C-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val fortran_bigarray :
+ < element : 'a
+ ; layout : Bigarray_compat.fortran_layout
+ ; ba_repr : 'b
+ ; dims : 'dims
+ ; bigarray : 'bigarray
+ ; carray : _ >
+ Ctypes_static.bigarray_class ->
+ 'dims ->
+ ('a, 'b) Bigarray_compat.kind ->
+ 'bigarray typ
Construct a sized Fortran-layout bigarray type representation from a bigarray class, the dimensions, and the Bigarray_compat.kind
.
val typ_of_bigarray_kind : ('a, 'b) Bigarray_compat.kind -> 'a typ
typ_of_bigarray_kind k
is the type corresponding to the Bigarray kind k
.
val structure : string -> 's Ctypes_static.structure typ
Construct a new structure type. The type value returned is incomplete and can be updated using field
until it is passed to seal
, at which point the set of fields is fixed.
The type ('_s structure typ
) of the expression returned by the call structure tag
includes a weak type variable, which can be explicitly instantiated to ensure that the OCaml values representing different C structure types have incompatible types. Typical usage is as follows:
type tagname
let tagname : tagname structure typ = structure "tagname"
val union : string -> 's Ctypes_static.union typ
val field :
+ 't typ ->
+ string ->
+ 'a typ ->
+ ('a, ('s, [< `Struct | `Union ]) Ctypes_static.structured as 't) field
field ty label ty'
adds a field of type ty'
with label label
to the structure or union type ty
and returns a field value that can be used to read and write the field in structure or union instances (e.g. using getf
and setf
).
Attempting to add a field to a union type that has been sealed with seal
is an error, and will raise ModifyingSealedType
.
val seal : (_, [< `Struct | `Union ]) Ctypes_static.structured typ -> unit
seal t
completes the struct or union type t
so that no further fields can be added. Struct and union types must be sealed before they can be used in a way that involves their size or alignment; see the documentation for IncompleteType
for further details.
val view :
+ ?format_typ:((Format.formatter -> unit) -> Format.formatter -> unit) ->
+ ?format:(Format.formatter -> 'b -> unit) ->
+ read:('a -> 'b) ->
+ write:('b -> 'a) ->
+ 'a typ ->
+ 'b typ
view ~read:r ~write:w t
creates a C type representation t'
which behaves like t
except that values read using t'
are subsequently transformed using the function r
and values written using t'
are first transformed using the function w
.
For example, given suitable definitions of string_of_char_ptr
and char_ptr_of_string
, the type representation
view ~read:string_of_char_ptr ~write:char_ptr_of_string (ptr char)
can be used to pass OCaml strings directly to and from bound C functions, or to read and write string members in structs and arrays. (In fact, the string
type representation is defined in exactly this way.)
The optional argument format_typ
is used by the Ctypes.format_typ
and string_of_typ
functions to print the type at the top level and elsewhere. If format_typ
is not supplied the printer for t
is used instead.
The optional argument format
is used by the Ctypes.format
and string_of
functions to print the values. If format_val
is not supplied the printer for t
is used instead.
typedef t name
creates a C type representation t'
which is equivalent to t
except its name is printed as name
.
This is useful when generating C stubs involving "anonymous" types, for example: typedef struct { int f } typedef_name;
val abstract :
+ name:string ->
+ size:int ->
+ alignment:int ->
+ 'a Ctypes_static.abstract typ
Create an abstract type specification from the size and alignment requirements for the type.
val lift_typ : 'a Ctypes_static.typ -> 'a typ
lift_typ t
turns a concrete type representation into an abstract type representation.
For example, retrieving struct layout from C involves working with an abstract representation of types which do not support operations such as sizeof
. The lift_typ
function makes it possible to use concrete type representations wherever such abstract type representations are needed.
Abstract interface to C function type descriptions
type 'a fn = 'a Ctypes_static.fn
The type of values representing C function types. A value of type t fn
can be used to bind to C functions and to describe type of OCaml functions passed to C.
Construct a function type from a type and an existing function type. This corresponds to prepending a parameter to a C function parameter list. For example,
int @-> ptr void @-> returning float
describes a function type that accepts two arguments -- an integer and a pointer to void -- and returns a float.
type 'a static_funptr = 'a Ctypes_static.static_funptr
Function pointer types
The type of values representing C function pointer types.
val static_funptr : 'a fn -> 'a Ctypes_static.static_funptr typ
Construct a function pointer type from an existing function type (called the reference type).
constant name typ
retrieves the value of the compile-time constant name
of type typ
. It can be used to retrieve enum constants, #defined values and other integer constant expressions.
The type typ
must be either an integer type such as bool
, char
, int
, uint8
, etc., or a view (or perhaps multiple views) where the underlying type is an integer type.
When the value of the constant cannot be represented in the type there will typically be a diagnostic from either the C compiler or the OCaml compiler. For example, gcc will say
warning: overflow in implicit constant conversion
val enum :
+ string ->
+ ?typedef:bool ->
+ ?unexpected:(int64 -> 'a) ->
+ ('a * int64 const) list ->
+ 'a typ
enum name ?unexpected alist
builds a type representation for the enum named name
. The size and alignment are retrieved so that the resulting type can be used everywhere an integer type can be used: as an array element or struct member, as an argument or return value, etc.
The value alist
is an association list of OCaml values and values retrieved by the constant
function. For example, to expose the enum
enum letters { A, B, C = 10, D };
you might first retrieve the values of the enumeration constants:
let a = constant "A" int64_t
+and b = constant "B" int64_t
+and c = constant "C" int64_t
+and d = constant "D" int64_t
and then build the enumeration type
let letters = enum "letters" [
+ `A, a;
+ `B, b;
+ `C, c;
+ `D, d;
+] ~unexpected:(fun i -> `E i)
The unexpected
function specifies the value to return in the case that some unexpected value is encountered -- for example, if a function with the return type 'enum letters' actually returns the value -1
.
The optional flag typedef
specifies whether the first argument, name
, indicates an tag or an alias. If typedef
is false
(the default) then name
is treated as an enumeration tag:
enum letters { ... }
If typedef
is true
then name
is instead treated as an alias:
typedef enum { ... } letters
Type_description.Types
Bindings.Type_description
module Types (T : Ctypes.TYPE) : sig ... end
Bindings.Types_generated
include sig ... end
Bindings
module C : sig ... end
module Function_description : sig ... end
module Type_description : sig ... end
module Types_generated : sig ... end
The entry point of this library is the module: Bindings
.
quickjs
is a set of OCaml bindings for QuickJS. QuickJS is a small and embeddable JavaScript engine. It supports the ES2020 specification including modules, asynchronous generators, proxies and BigInt.
The project exposes two libraries:
quickjs.bindings
with the QuickJS C API.quickjs.bindings
with the same shape as the JavaScript API.The purpose of this project is to provide the same behaviour as the JavaScript engines from browsers SpiderMonkey, JavaScriptCore, ChakraCore, v8) into OCaml. So code that runs in the browser (via Melange) can be run in native with the same results.
This is a work in progress, and currently only includes bindings to RegExp
(binded to libregexp.c
).