[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
|
|
@ -26,6 +26,10 @@ void divide_v(int a, int b, int *OUTPUT, int *OUTPUT);
|
||||||
|
|
||||||
void divide_mv(int a, int b, int *OUTPUT, int *OUTPUT);
|
void divide_mv(int a, int b, int *OUTPUT, int *OUTPUT);
|
||||||
|
|
||||||
|
#else
|
||||||
|
void divide_l(int a, int b, int *OUTPUT, int *OUTPUT);
|
||||||
|
void divide_v(int a, int b, int *OUTPUT, int *OUTPUT);
|
||||||
|
void divide_mv(int a, int b, int *OUTPUT, int *OUTPUT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
@ -49,4 +53,3 @@ void divide_mv(int a, int b, int *quotient_p, int *remainder_p)
|
||||||
}
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,12 @@ FAILING_C_TESTS = \
|
||||||
enums \
|
enums \
|
||||||
preproc_constants_c \
|
preproc_constants_c \
|
||||||
|
|
||||||
|
CPP_TEST_CASES += \
|
||||||
|
inout \
|
||||||
|
|
||||||
|
C_TEST_CASES += \
|
||||||
|
multivalue \
|
||||||
|
|
||||||
ml_runme = $(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)
|
ml_runme = $(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)
|
||||||
|
|
||||||
run_testcase = \
|
run_testcase = \
|
||||||
|
|
|
||||||
8
Examples/test-suite/ocaml/inout_runme.ml
Normal file
8
Examples/test-suite/ocaml/inout_runme.ml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
open Swig
|
||||||
|
open Inout
|
||||||
|
|
||||||
|
let _ =
|
||||||
|
assert (_AddOne1 '(1.) as float = 2.);
|
||||||
|
assert (_AddOne3 '(1, 1, 1) = C_list ['2.;'2.;'2.]);
|
||||||
|
assert (_AddOne1r '(1.) as float = 2.);
|
||||||
|
;;
|
||||||
8
Examples/test-suite/ocaml/multivalue_runme.ml
Normal file
8
Examples/test-suite/ocaml/multivalue_runme.ml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
open Swig
|
||||||
|
open Multivalue
|
||||||
|
|
||||||
|
let _ =
|
||||||
|
assert (_divide_l '(37, 5) = C_list ['7;'2]);
|
||||||
|
assert (_divide_v '(41, 7) = C_list ['5;'6]);
|
||||||
|
assert (_divide_mv '(91, 13) = C_list ['7;'0]);
|
||||||
|
;;
|
||||||
|
|
@ -33,10 +33,6 @@
|
||||||
|
|
||||||
%insert(classtemplate) "class.swg"
|
%insert(classtemplate) "class.swg"
|
||||||
|
|
||||||
/* Definitions */
|
|
||||||
#define SWIG_malloc(size) swig_malloc(size, FUNC_NAME)
|
|
||||||
#define SWIG_free(mem) free(mem)
|
|
||||||
|
|
||||||
/* Read in standard typemaps. */
|
/* Read in standard typemaps. */
|
||||||
%include <swig.swg>
|
%include <swig.swg>
|
||||||
%include <typemaps.i>
|
%include <typemaps.i>
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,44 @@
|
||||||
$1 = !caml_ptr_val_internal($input, &ptr, 0);
|
$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
|
* Exception handling
|
||||||
* ------------------------------------------------------------ */
|
* ------------------------------------------------------------ */
|
||||||
|
|
|
||||||
|
|
@ -142,13 +142,6 @@
|
||||||
%typemap(directorout) C_NAME {
|
%typemap(directorout) C_NAME {
|
||||||
$1 = OCAML_TO_C($input);
|
$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 */
|
/* Out */
|
||||||
%typemap(out) C_NAME {
|
%typemap(out) C_NAME {
|
||||||
$result = C_TO_OCAML($1);
|
$result = C_TO_OCAML($1);
|
||||||
|
|
@ -159,9 +152,6 @@
|
||||||
%typemap(varout) C_NAME & {
|
%typemap(varout) C_NAME & {
|
||||||
$result = C_TO_OCAML($1);
|
$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 & {
|
%typemap(out) C_NAME & {
|
||||||
$result = C_TO_OCAML(*$1);
|
$result = C_TO_OCAML(*$1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue