From 9942e6a5822e1ba8c8f9d642c14fda3cb298baec Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Mon, 4 Feb 2019 11:29:54 -0700 Subject: [PATCH] [OCaml] Fix director_pass_by_value Add a directorin typemap for SWIGTYPE. Add director_frob_runme.ml, director_pass_by_value_runme.ml, and director_unroll_runme.ml. This commit fixes most of the director-related warnings in the OCaml test suite. Of the director tests that are currently included in the OCaml test suite, director_basic and director_property are the only ones which give warnings (due to issues with typecheck typemaps). --- Examples/test-suite/ocaml/Makefile.in | 1 - .../test-suite/ocaml/director_frob_runme.ml | 5 ++++ .../ocaml/director_pass_by_value_runme.ml | 24 +++++++++++++++++++ .../test-suite/ocaml/director_unroll_runme.ml | 19 +++++++++++++++ Lib/ocaml/typemaps.i | 11 +++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/ocaml/director_frob_runme.ml create mode 100644 Examples/test-suite/ocaml/director_pass_by_value_runme.ml create mode 100644 Examples/test-suite/ocaml/director_unroll_runme.ml diff --git a/Examples/test-suite/ocaml/Makefile.in b/Examples/test-suite/ocaml/Makefile.in index 650849815..ccdb9a17b 100644 --- a/Examples/test-suite/ocaml/Makefile.in +++ b/Examples/test-suite/ocaml/Makefile.in @@ -21,7 +21,6 @@ cpp_enum \ default_constructor \ director_binary_string \ director_enum \ -director_pass_by_value \ director_primitives \ director_redefined \ director_string \ diff --git a/Examples/test-suite/ocaml/director_frob_runme.ml b/Examples/test-suite/ocaml/director_frob_runme.ml new file mode 100644 index 000000000..137a88ef3 --- /dev/null +++ b/Examples/test-suite/ocaml/director_frob_runme.ml @@ -0,0 +1,5 @@ +open Swig +open Director_frob + +let foo = new_Bravo '() +assert (foo -> abs_method () as string = "Bravo::abs_method()") diff --git a/Examples/test-suite/ocaml/director_pass_by_value_runme.ml b/Examples/test-suite/ocaml/director_pass_by_value_runme.ml new file mode 100644 index 000000000..af862f189 --- /dev/null +++ b/Examples/test-suite/ocaml/director_pass_by_value_runme.ml @@ -0,0 +1,24 @@ +open Swig +open Director_pass_by_value + +let passByVal = ref [| |] + +let director_pass_by_value_Derived ob meth args = + match meth with + | "virtualMethod" -> passByVal := Array.append !passByVal [|args|]; C_void + | _ -> (invoke ob) meth args + +let d = + new_derived_object + new_DirectorPassByValueAbstractBase + (director_pass_by_value_Derived) + '() + +let _ = + let caller = new_Caller '() in + assert (caller -> call_virtualMethod (d) = C_void); + assert (Array.length !passByVal = 1); + let a = List.hd (fnhelper (!passByVal.(0))) in + assert (a -> getVal () as int = 0x12345678); + assert (a -> "~" () = C_void); +;; diff --git a/Examples/test-suite/ocaml/director_unroll_runme.ml b/Examples/test-suite/ocaml/director_unroll_runme.ml new file mode 100644 index 000000000..ebd7d02c5 --- /dev/null +++ b/Examples/test-suite/ocaml/director_unroll_runme.ml @@ -0,0 +1,19 @@ +open Swig +open Director_unroll + +let director_unroll_MyFoo ob meth args = + match meth with + | "ping" -> C_string "director_unroll_MyFoo::ping()" + | _ -> (invoke ob) meth args + +let a = + new_derived_object + new_Foo (director_unroll_MyFoo) '() + +let _ = + let b = new_Bar '() in + let _ = b -> set (a) in + let c = b -> get () in + assert (director_unroll_MyFoo c "ping" '() as string = + "director_unroll_MyFoo::ping()"); +;; diff --git a/Lib/ocaml/typemaps.i b/Lib/ocaml/typemaps.i index 4acd0b805..4475707d6 100644 --- a/Lib/ocaml/typemaps.i +++ b/Lib/ocaml/typemaps.i @@ -109,6 +109,17 @@ #endif +%typemap(directorin) SWIGTYPE { + $<ype temp = new $ltype((const $ltype &)$1); + swig_result = SWIG_Ocaml_ptr_to_val("create_$ltype_from_ptr", (void *)temp, $&1_descriptor); + args = caml_list_append(args, swig_result); +} + +%typemap(directorin) SWIGTYPE *, SWIGTYPE [], SWIGTYPE &, SWIGTYPE && { + swig_result = SWIG_Ocaml_ptr_to_val("create_$ltype_from_ptr", (void *)&$1, $&1_descriptor); + args = caml_list_append(args, swig_result); +} + /* The SIMPLE_MAP macro below defines the whole set of typemaps needed for simple types. */