From f45fd1a36ea2e44d38512262668aa302279d4ed3 Mon Sep 17 00:00:00 2001 From: Art Yerkes Date: Fri, 6 Jun 2003 16:19:28 +0000 Subject: [PATCH] Typedef_mptr test (with runme). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4871 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/ocaml/typedef_mptr_runme.ml | 15 ++++++++ Examples/test-suite/typedef_mptr.i | 4 +-- Lib/ocaml/typemaps.i | 36 ++++++++++++------- 3 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 Examples/test-suite/ocaml/typedef_mptr_runme.ml diff --git a/Examples/test-suite/ocaml/typedef_mptr_runme.ml b/Examples/test-suite/ocaml/typedef_mptr_runme.ml new file mode 100644 index 000000000..896a2db65 --- /dev/null +++ b/Examples/test-suite/ocaml/typedef_mptr_runme.ml @@ -0,0 +1,15 @@ +open Typedef_mptr + +let soci x = (string_of_int (get_int x)) + +let x = new_Foo C_void +let add_res = _do_op (C_list [ x ; C_int 2 ; C_int 1 ; _add ]) +and sub_res = _do_op (C_list [ x ; C_int 2 ; C_int 1 ; _sub ]) +let _ = + if add_res <> (C_int 3) || sub_res <> (C_int 1) then + raise (Failure ("Bad result:" ^ + " (add " ^ (soci add_res) ^ ") " ^ + " (sub " ^ (soci sub_res) ^ ")")) +let _ = Printf.printf "2 + 1 = %d, 2 - 1 = %d\n" + (get_int add_res) + (get_int sub_res) diff --git a/Examples/test-suite/typedef_mptr.i b/Examples/test-suite/typedef_mptr.i index 5e64c8ac7..de0cde12a 100644 --- a/Examples/test-suite/typedef_mptr.i +++ b/Examples/test-suite/typedef_mptr.i @@ -2,7 +2,7 @@ %module typedef_mptr -#ifdef SWIGPYTHON +#if defined(SWIGPYTHON) || defined(SWIGOCAML) %inline %{ @@ -28,7 +28,7 @@ Integer do_op(Foo *f, Integer x, Integer y, Integer (FooObj::*op)(Integer, Integ %} #endif -#ifdef SWIGPYTHON +#if defined(SWIGPYTHON) || defined(SWIGOCAML) %constant int (Foo::*add)(int,int) = &Foo::add; %constant Integer (FooObj::*sub)(Integer,Integer) = &FooObj::sub; #endif diff --git a/Lib/ocaml/typemaps.i b/Lib/ocaml/typemaps.i index ab06dafa3..4f13a4fa0 100644 --- a/Lib/ocaml/typemaps.i +++ b/Lib/ocaml/typemaps.i @@ -242,11 +242,20 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val); %char_ptr_out(varout); %char_ptr_out(invv); -%typemap(in) SWIGTYPE * { +%define %swigtype_ptr_in(how) +%typemap(how) SWIGTYPE * { $1 = ($ltype)caml_ptr_val($input,$1_descriptor); } +%typemap(how) SWIGTYPE (CLASS::*) { + /* %typemap(how) SWIGTYPE *, SWIGTYPE (CLASS::*) */ + void *v = caml_ptr_val($input,$1_descriptor); + memcpy(& $1, &v, sizeof(v)); +} +%enddef +%define %swigtype_ptr_out(how) %typemap(out) SWIGTYPE * { + /* %typemap(how) SWIGTYPE *, SWIGTYPE (CLASS::*) */ CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr"); if( fromval ) { $result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor)); @@ -254,19 +263,22 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val); $result = caml_val_ptr ((void *)$1,$1_descriptor); } } - -%typemap(varin) SWIGTYPE * { - $1 = ($ltype)caml_ptr_val($input,$1_descriptor); +%typemap(how) SWIGTYPE (CLASS::*) { + /* %typemap(how) SWIGTYPE *, SWIGTYPE (CLASS::*) */ + void *v; + memcpy(&v,& $1, sizeof(void *)); + $result = caml_val_ptr (v,$1_descriptor); } +%enddef -%typemap(varout) SWIGTYPE * { - CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr"); - if( fromval ) { - $result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor)); - } else { - $result = caml_val_ptr ((void *)$1,$1_descriptor); - } -} +%swigtype_ptr_in(in); +%swigtype_ptr_in(memberin); +%swigtype_ptr_in(varin); +%swigtype_ptr_in(outv); +%swigtype_ptr_out(out); +%swigtype_ptr_out(memberout); +%swigtype_ptr_out(varout); +%swigtype_ptr_out(inv); /* C++ References */