Module Cstubs
Operations for generating C bindings stubs.
module Types : sig ... end
module type FOREIGN = Ctypes.FOREIGN
type errno_policy
Values of the
errno_policy
type specify the errno support provided by the generated code. Seeignore_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 theerrno
argument toCstubs.write_c
andCstubs.write_ml
changes the return type of bound functions from a single value to a pair of values. For example, the binding specificationlet 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
andlwt_jobs
the generated type is as follows:val realpath : string -> string -> (stirng * int) Lwt.t
type concurrency_policy
Values of the
concurrency_policy
type specify the concurrency support provided by the generated code. Seesequential
andlwt_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 theconcurrency
argument toCstubs.write_c
andCstubs.write_ml
changes the return type of bound functions to include theLwt
.t constructor. For example, the binding specificationlet 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 theconcurrency
argument toCstubs.write_c
andCstubs.write_ml
changes the return type of bound functions to include theLwt
.t constructor. For example, the binding specificationlet 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 -> Stdlib.Format.formatter -> prefix:string -> (module BINDINGS) -> unit
write_c fmt ~prefix bindings
generates C stubs for the functions bound withforeign
inbindings
. The stubs are intended to be used in conjunction with the ML code generated bywrite_ml
.The optional argument
concurrency
specifies the concurrency support provided by the generated code. The default issequential
.The generated code uses definitions exposed in the header file
ctypes_cstubs_internals.h
.
val write_ml : ?concurrency:concurrency_policy -> ?errno:errno_policy -> Stdlib.Format.formatter -> prefix:string -> (module BINDINGS) -> unit
write_ml fmt ~prefix bindings
generates ML bindings for the functions bound withforeign
inbindings
. The generated code conforms to theFOREIGN
interface.The optional argument
concurrency
specifies the concurrency support provided by the generated code. The default issequential
.The generated code uses definitions exposed in the module
Cstubs_internals
.