Module Cstubs
Operations for generating C bindings stubs.
module Types : sig ... endmodule type FOREIGN = Ctypes.FOREIGNtype errno_policyValues of the
errno_policytype specify the errno support provided by the generated code. Seeignore_errnofor the available option.
val ignore_errno : errno_policyGenerate code with no special support for errno. This is the default.
val return_errno : errno_policyGenerate code that returns errno in addition to the return value of each function.
Passing
return_errnoas theerrnoargument toCstubs.write_candCstubs.write_mlchanges 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 -> stirngbut when using
return_errnothe generated type is as follows:val realpath : string -> string -> stirng * intand when using both
return_errnoandlwt_jobsthe generated type is as follows:val realpath : string -> string -> (stirng * int) Lwt.t
type concurrency_policyValues of the
concurrency_policytype specify the concurrency support provided by the generated code. Seesequentialandlwt_jobsfor the available options.
val sequential : concurrency_policyGenerate code with no special support for concurrency. This is the default.
val unlocked : concurrency_policyGenerate code that releases the runtime lock during C calls.
val lwt_preemptive : concurrency_policyGenerate code which runs C function calls with the Lwt_preemptive module:
http://ocsigen.org/lwt/2.5.1/api/Lwt_preemptive
Passing
lwt_preemptiveas theconcurrencyargument toCstubs.write_candCstubs.write_mlchanges 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 -> intbut when using
lwt_preemptivethe generated type is as follows:val unlink : string -> int Lwt.tAdditionally, the OCaml runtime lock is released during calls to functions bound with
lwt_preemptive.
val lwt_jobs : concurrency_policyGenerate code which implements C function calls as Lwt jobs:
http://ocsigen.org/lwt/2.5.1/api/Lwt_unix#TYPEjob
Passing
lwt_jobsas theconcurrencyargument toCstubs.write_candCstubs.write_mlchanges 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 -> intbut when using
lwt_jobsthe 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) -> unitwrite_c fmt ~prefix bindingsgenerates C stubs for the functions bound withforeigninbindings. The stubs are intended to be used in conjunction with the ML code generated bywrite_ml.The optional argument
concurrencyspecifies 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) -> unitwrite_ml fmt ~prefix bindingsgenerates ML bindings for the functions bound withforeigninbindings. The generated code conforms to theFOREIGNinterface.The optional argument
concurrencyspecifies the concurrency support provided by the generated code. The default issequential.The generated code uses definitions exposed in the module
Cstubs_internals.