Camlid.Helperval func :
?ml:string ->
?result:Type.mlc ->
?ignored_result:Type.mlc ->
?call_params:Type.param list ->
string ->
Type.param list ->
Expr.exprDescribe the signature of a C function and generate the stub. Three variants:
func ~ml c_name params : the C function has a void result (no result)func ~ml ~result c_name params: the C function has a result with template result, and it is part of the OCaml resultsfunc ~ml ~ignored_result c_name params: C function has a result with template result, and it is ignored for the OCaml functionThe resulting expression is the OCaml declaration for the external. Since it mentions the Camlid.Expr.id of the C stub function, it is automatically added to the C file during the generation by Camlid.Generate.to_file.
The order of the inputs, outputs (result first), and arguments of the C function all use the order given by params.
The following functions create fresh variable, the same parameter should not be used multiple times in the description of the same C function. However it could be used in different descriptions
val input : ?name:string -> Type.mlc -> Type.paraminput ~name ty create an input parameter using the typedef template ty. The parameter:
val output : ?name:string -> Type.mlc -> Type.paraminput ~name ty create an input parameter using the typedef template ty. The parameter:
val inout : ?name:string -> Type.mlc -> Type.paraminput ~name ty create an input parameter using the typedef template ty. The parameter:
val ignored : ?name:string -> Type.mlc -> Type.paraminput ~name ty create an input parameter using the typedef template ty. The parameter:
Common OCaml values
val int : Type.mlcIt is int in OCaml, and intptr_t in C. The highest bit is lost when going from C to OCaml
val size_t : Type.mlcval int_trunc : Type.mlcIt is int in OCaml, and int in C. On 64bit, half of the highest bit are lost (63 bit long in OCaml and 32 bit long in C).
val double : Type.mlcIt is float in OCaml, and double in C. No loss during conversion.
val bool : Type.mlcIt is bool in OCaml, and int in C. No loss during conversion if the int is considered as a boolean.
ptr_def ty it change the C value used when calling the C function to a pointer on the given type. It is useful with output. The pointer is valid for the duration og the call. The OCaml type is the same as for ty.
Allocated C structure
In all the following section, owned indicates if the OCaml sides owns the C allocated memory, and so it it should free it want it is not using it anymore. An OCaml value (e.g. a string) is always owned by the OCaml side, the question is if the memory allocated by the stub and given to the C function, or the memory returned by the C function is owned by the OCaml side and should be freed.
Except in the case of bigarrays, or user defined abstract and custom type the allocated memory is freed at the end of the stub
In all this section, init indicates if the stub need to allocate the memory before calling the C function
val string_nt : ?owned:bool -> unit -> Type.mlcIt is string in OCaml, and char * in C. In both side the conversion stops at the first null character. If there is no null character in the OCaml string it stops at the end.
val input_string :
?owned:bool ->
?input:bool ->
?output:bool ->
?name:string ->
unit ->
with_lengthParameter for a "char*" and its length. Given as such to the stubbed function. Converted from/to a string in ocaml.
val output_string :
?owned:bool ->
?input:bool ->
?output:bool ->
?name:string ->
unit ->
with_lengthParameter for a "char*" and its length. The address of those variables are given to the stubbed function. Converted from/to a string in ocaml.
val fixed_length_string :
?init:bool ->
?owned:bool ->
?input:bool ->
?output:bool ->
?len_used_in_call:bool ->
?name:string ->
unit ->
with_lengthParameter for a "char*" converted (if input) or allocated (if output) with the length given as input. (fixed_length_string ()).len is an input parameter. Converted from/to a string in ocaml.
val input_array :
?owned:bool ->
?output:bool ->
?input:bool ->
?name:string ->
Type.mlc ->
with_lengthinput_array mlc Parameter for an array of mlc and its length. Given as such to the stubbed function. Converted from/to an array of mlc in OCaml.
val output_array :
?owned:bool ->
?output:bool ->
?input:bool ->
?name:string ->
Type.mlc ->
with_lengthoutput_array mlc Parameter for an array of mlc and its length. The address of those variables are given to the stubbed function. Converted from/to an array of mlc in OCaml.
val fixed_length_array :
?init:bool ->
?owned:bool ->
?input:bool ->
?output:bool ->
?len_used_in_call:bool ->
?name:string ->
Type.mlc ->
with_lengthfixed_length_array mlc Parameter for an array of mlc converted (if input) or allocated (if output) with the length given as input. (fixed_length_array ()).len is an input parameter. Converted from/to an array of mlc in OCaml.
val abstract :
?initialize:string ->
?get:string ->
?set:string ->
?internal:string ->
ml:string ->
c:string ->
unit ->
Type.mlcval custom :
?initialize:string ->
?finalize:string ->
?hash:string ->
?compare:string ->
?get:string ->
?set:string ->
?internal:string ->
ml:string ->
c:string ->
unit ->
Type.mlcval custom_ptr :
?initialize:string ->
?finalize:string ->
?hash:string ->
?compare:string ->
?malloc:bool ->
ml:string ->
c:string ->
unit ->
Type.mlcval string_as_FILE_ptr : Type.mlcval input_value : string -> Type.paramval output_value : string -> Type.paramval copy :
Type.mlc ->
?vars:(dst:Expr.Var.t -> src:Expr.Var.t -> Expr.Var.t list) ->
?exprs:(dst:Expr.Var.t -> src:Expr.Var.t -> Expr.expr list) ->
string ->
Type.mlcval ret_option_if : Type.mlc -> Type.param * Type.mlcval map_param_in_call :
?name:string ->
ty:string ->
Type.param ->
(('a -> Expr.expr -> 'b) -> Expr.expr -> 'c, 'a, 'b, 'd, 'd, 'c)
Stdlib.format6 ->
Type.paramval do_nothing : string -> Type.param list -> Expr.exprval convert :
?c_to_mlc:string ->
?mlc_to_c:string ->
?using:Expr.Var.t list ->
mlc:Type.mlc ->
c:Type.c ->
unit ->
Type.mlcval on_stack :
?init_expr:string ->
?initialize:string ->
?clear:string ->
string ->
Type.cDefine a C type that is allocated on the stack. It is initialized and cleared with the given functions.