diff options
author | Zackery Spytz <zspytz@gmail.com> | 2019-02-17 01:41:59 -0700 |
---|---|---|
committer | Zackery Spytz <zspytz@gmail.com> | 2019-02-17 01:41:59 -0700 |
commit | 10d62aecd5808bb5859f34cf1b2c0f9e6371045e (patch) | |
tree | 67749a0bde858ca929b3506ad51a9ee5705edeea | |
parent | 6522afe90a475d38e9b47583fad7b40904098aea (diff) | |
download | swig-10d62aecd5808bb5859f34cf1b2c0f9e6371045e.tar.gz |
[OCaml] Fix the wrapmacro test
Add a typecheck typemap for size_t and const size_t &.
Add the const qualifier to the typemaps for primitive reference
types.
Add multiple runtime tests.
-rw-r--r-- | Doc/Manual/Extending.html | 2 | ||||
-rw-r--r-- | Examples/ocaml/argout_ref/example.i | 6 | ||||
-rw-r--r-- | Examples/test-suite/ocaml/global_vars_runme.ml | 15 | ||||
-rw-r--r-- | Examples/test-suite/ocaml/reference_global_vars_runme.ml | 2 | ||||
-rw-r--r-- | Examples/test-suite/ocaml/sizet_runme.ml | 10 | ||||
-rw-r--r-- | Examples/test-suite/ocaml/typedef_reference_runme.ml | 11 | ||||
-rw-r--r-- | Examples/test-suite/ocaml/wrapmacro_runme.ml | 10 | ||||
-rw-r--r-- | Lib/ocaml/std_common.i | 1 | ||||
-rw-r--r-- | Lib/ocaml/typecheck.i | 3 | ||||
-rw-r--r-- | Lib/ocaml/typemaps.i | 8 |
10 files changed, 58 insertions, 10 deletions
diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index 1deb1cb12..b01328380 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -3711,7 +3711,7 @@ Below are some practical steps that should help meet these requirements. </li> <li> Copying an existing language module and adapting the source for it is likely to be the most efficient - approach to fully developing a new module as a numbe of corner cases are covered in the existing implementations. + approach to fully developing a new module as a number of corner cases are covered in the existing implementations. The most advanced scripting languages are Python and Ruby. The most advanced compiled target languages are Java and C#. </li> diff --git a/Examples/ocaml/argout_ref/example.i b/Examples/ocaml/argout_ref/example.i index 472a83804..a3e6bf8a6 100644 --- a/Examples/ocaml/argout_ref/example.i +++ b/Examples/ocaml/argout_ref/example.i @@ -1,13 +1,13 @@ /* File : example.i */ %module example -%typemap(argout) (int &x, int &y) { +%typemap(argout) (const int &x, const int &y) { swig_result = caml_list_append(swig_result, caml_val_int(*$1)); swig_result = caml_list_append(swig_result, caml_val_int(*$2)); } %{ -extern "C" void factor(int &x, int &y); +extern "C" void factor(const int &x, const int &y); %} -extern "C" void factor(int &x, int &y); +extern "C" void factor(const int &x, const int &y); diff --git a/Examples/test-suite/ocaml/global_vars_runme.ml b/Examples/test-suite/ocaml/global_vars_runme.ml new file mode 100644 index 000000000..75df89499 --- /dev/null +++ b/Examples/test-suite/ocaml/global_vars_runme.ml @@ -0,0 +1,15 @@ +open Swig +open Global_vars + +_init '() + +let _ = + assert (_b '() as string = "string b"); + assert (_b '("a string value") as string = "a string value"); + assert (_b '() as string = "a string value"); + assert (_x '() as int = 1234); + assert (_x '(9876) as int = 9876); + assert (_x '() as int = 9876); + assert (_Hi '() as int = 0); + assert (_Hola '() as int = 1); +;; diff --git a/Examples/test-suite/ocaml/reference_global_vars_runme.ml b/Examples/test-suite/ocaml/reference_global_vars_runme.ml index aa1708774..adde1b82e 100644 --- a/Examples/test-suite/ocaml/reference_global_vars_runme.ml +++ b/Examples/test-suite/ocaml/reference_global_vars_runme.ml @@ -22,7 +22,7 @@ let _ = let _ = _var_short (_createref_short (C_short 10)) in assert (_value_short (_var_short '()) as int = 10); - + let _ = _var_unsigned_short (_createref_unsigned_short (C_ushort 10)) in assert (_value_unsigned_short (_var_unsigned_short '()) as int = 10); diff --git a/Examples/test-suite/ocaml/sizet_runme.ml b/Examples/test-suite/ocaml/sizet_runme.ml new file mode 100644 index 000000000..5f72459c9 --- /dev/null +++ b/Examples/test-suite/ocaml/sizet_runme.ml @@ -0,0 +1,10 @@ +open Swig +open Sizet + +let _ = + let s = C_int64 2000L in + assert (_test1 '(s) as int = 2000); + assert (_test2 '(s) as int = 2000); + assert (_test3 '(s) as int = 2000); + assert (_test4 '(s) as int = 2000); +;; diff --git a/Examples/test-suite/ocaml/typedef_reference_runme.ml b/Examples/test-suite/ocaml/typedef_reference_runme.ml new file mode 100644 index 000000000..4c9cc6fca --- /dev/null +++ b/Examples/test-suite/ocaml/typedef_reference_runme.ml @@ -0,0 +1,11 @@ +open Swig +open Typedef_reference + +let _ = + let i = _copy_intp '(2) in + assert (_somefunc '(i) as int = 2); + assert (_delete_intp '(i) = C_void); + let i = _copy_intp '(3) in + assert (_otherfunc '(i) as int = 3); + assert (_delete_intp '(i) = C_void); +;; diff --git a/Examples/test-suite/ocaml/wrapmacro_runme.ml b/Examples/test-suite/ocaml/wrapmacro_runme.ml new file mode 100644 index 000000000..f11136360 --- /dev/null +++ b/Examples/test-suite/ocaml/wrapmacro_runme.ml @@ -0,0 +1,10 @@ +open Swig +open Wrapmacro + +let _ = + let args = C_list [ C_int64 2L ; C_int64 1L ] in + assert (_maximum '(args) as int = 2); + let args = C_list [ C_double (2. /. 7.) ; C_double 256. ] in + assert (_maximum '(args) as float = 256.); + assert (_GUINT16_SWAP_LE_BE_CONSTANT '(0x1234) as int = 0x3412); +;; diff --git a/Lib/ocaml/std_common.i b/Lib/ocaml/std_common.i index 6523af0b5..7e64607d9 100644 --- a/Lib/ocaml/std_common.i +++ b/Lib/ocaml/std_common.i @@ -7,6 +7,7 @@ %include <std/std_except.i> %apply size_t { std::size_t }; +%apply const size_t& { const std::size_t& }; %{ #include <string> diff --git a/Lib/ocaml/typecheck.i b/Lib/ocaml/typecheck.i index 2cc8dcbec..288a2f32a 100644 --- a/Lib/ocaml/typecheck.i +++ b/Lib/ocaml/typecheck.i @@ -72,7 +72,8 @@ long, signed long, unsigned long, long long, signed long long, unsigned long long, const long &, const signed long &, const unsigned long &, - const long long &, const signed long long &, const unsigned long long & + const long long &, const signed long long &, const unsigned long long &, + size_t, const size_t & { if( !Is_block($input) ) $1 = 0; else { diff --git a/Lib/ocaml/typemaps.i b/Lib/ocaml/typemaps.i index a6c7ef47c..23e2955fb 100644 --- a/Lib/ocaml/typemaps.i +++ b/Lib/ocaml/typemaps.i @@ -132,11 +132,11 @@ %typemap(varin) C_NAME { $1 = OCAML_TO_C($input); } -%typemap(in) C_NAME & ($*1_ltype temp) { +%typemap(in) const C_NAME & ($*1_ltype temp) { temp = ($*1_ltype) OCAML_TO_C($input); $1 = &temp; } -%typemap(varin) C_NAME & { +%typemap(varin) const C_NAME & { $1 = OCAML_TO_C($input); } %typemap(directorout) C_NAME { @@ -156,13 +156,13 @@ %typemap(varout) C_NAME { $result = C_TO_OCAML($1); } -%typemap(varout) C_NAME & { +%typemap(varout) const 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 & { +%typemap(out) const C_NAME & { $result = C_TO_OCAML(*$1); } %typemap(directorin) C_NAME { |