[OCaml] Add missing INPUT, OUTPUT, and INOUT typemaps for primitives
The typemaps are based on PHP's.
This commit is contained in:
parent
b9350614b5
commit
470ce2dd31
7 changed files with 64 additions and 15 deletions
|
|
@ -33,10 +33,6 @@
|
|||
|
||||
%insert(classtemplate) "class.swg"
|
||||
|
||||
/* Definitions */
|
||||
#define SWIG_malloc(size) swig_malloc(size, FUNC_NAME)
|
||||
#define SWIG_free(mem) free(mem)
|
||||
|
||||
/* Read in standard typemaps. */
|
||||
%include <swig.swg>
|
||||
%include <typemaps.i>
|
||||
|
|
|
|||
|
|
@ -153,6 +153,44 @@
|
|||
$1 = !caml_ptr_val_internal($input, &ptr, 0);
|
||||
}
|
||||
|
||||
%define INPUT_OUTPUT_INOUT_TYPEMAPS(type, c_to_ocaml, ocaml_to_c)
|
||||
%typemap(in) type *INPUT(type temp), type &INPUT(type temp) {
|
||||
temp = (type)ocaml_to_c($input);
|
||||
$1 = &temp;
|
||||
}
|
||||
%typemap(typecheck) type *INPUT = type;
|
||||
%typemap(typecheck) type &INPUT = type;
|
||||
|
||||
%typemap(in, numinputs=0) type *OUTPUT($*1_ltype temp), type &OUTPUT($*1_ltype temp) "$1 = &temp;"
|
||||
%typemap(argout) type *OUTPUT, type &OUTPUT {
|
||||
swig_result = caml_list_append(swig_result, c_to_ocaml(*$1));
|
||||
}
|
||||
%typemap(in) type *INOUT = type *INPUT;
|
||||
%typemap(in) type &INOUT = type &INPUT;
|
||||
|
||||
%typemap(argout) type *INOUT = type *OUTPUT;
|
||||
%typemap(argout) type &INOUT = type &OUTPUT;
|
||||
|
||||
%typemap(typecheck) type *INOUT = type;
|
||||
%typemap(typecheck) type &INOUT = type;
|
||||
%enddef
|
||||
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(bool, caml_val_bool, caml_long_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(int, caml_val_int, caml_long_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(long, caml_val_long, caml_long_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(short, caml_val_int, caml_long_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(char, caml_val_char, caml_long_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(signed char, caml_val_char, caml_long_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(float, caml_val_float, caml_double_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(double, caml_val_double, caml_double_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(unsigned int, caml_val_uint, caml_long_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(unsigned long, caml_val_ulong, caml_long_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(unsigned short, caml_val_ushort, caml_long_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(unsigned char, caml_val_uchar, caml_long_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(long long, caml_val_long, caml_long_val);
|
||||
INPUT_OUTPUT_INOUT_TYPEMAPS(unsigned long long, caml_val_ulong, caml_long_val);
|
||||
#undef INPUT_OUTPUT_INOUT_TYPEMAPS
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
|
|
|||
|
|
@ -142,13 +142,6 @@
|
|||
%typemap(directorout) C_NAME {
|
||||
$1 = OCAML_TO_C($input);
|
||||
}
|
||||
%typemap(in) C_NAME *INPUT ($*1_ltype temp) {
|
||||
temp = ($*1_ltype) OCAML_TO_C($input);
|
||||
$1 = &temp;
|
||||
}
|
||||
%typemap(in,numinputs=0) C_NAME *OUTPUT ($*1_ltype temp) {
|
||||
$1 = &temp;
|
||||
}
|
||||
/* Out */
|
||||
%typemap(out) C_NAME {
|
||||
$result = C_TO_OCAML($1);
|
||||
|
|
@ -159,9 +152,6 @@
|
|||
%typemap(varout) C_NAME & {
|
||||
$result = C_TO_OCAML($1);
|
||||
}
|
||||
%typemap(argout) C_NAME *OUTPUT {
|
||||
swig_result = caml_list_append(swig_result, C_TO_OCAML((long)*$1));
|
||||
}
|
||||
%typemap(out) C_NAME & {
|
||||
$result = C_TO_OCAML(*$1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue