Typedef_mptr test (with runme).

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4871 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Art Yerkes 2003-06-06 16:19:28 +00:00
commit d2cd68c7cc
3 changed files with 41 additions and 14 deletions

View file

@ -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)

View file

@ -2,7 +2,7 @@
%module typedef_mptr %module typedef_mptr
#ifdef SWIGPYTHON #if defined(SWIGPYTHON) || defined(SWIGOCAML)
%inline %{ %inline %{
@ -28,7 +28,7 @@ Integer do_op(Foo *f, Integer x, Integer y, Integer (FooObj::*op)(Integer, Integ
%} %}
#endif #endif
#ifdef SWIGPYTHON #if defined(SWIGPYTHON) || defined(SWIGOCAML)
%constant int (Foo::*add)(int,int) = &Foo::add; %constant int (Foo::*add)(int,int) = &Foo::add;
%constant Integer (FooObj::*sub)(Integer,Integer) = &FooObj::sub; %constant Integer (FooObj::*sub)(Integer,Integer) = &FooObj::sub;
#endif #endif

View file

@ -242,11 +242,20 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val);
%char_ptr_out(varout); %char_ptr_out(varout);
%char_ptr_out(invv); %char_ptr_out(invv);
%typemap(in) SWIGTYPE * { %define %swigtype_ptr_in(how)
%typemap(how) SWIGTYPE * {
$1 = ($ltype)caml_ptr_val($input,$1_descriptor); $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(out) SWIGTYPE * {
/* %typemap(how) SWIGTYPE *, SWIGTYPE (CLASS::*) */
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr"); CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
if( fromval ) { if( fromval ) {
$result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor)); $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); $result = caml_val_ptr ((void *)$1,$1_descriptor);
} }
} }
%typemap(how) SWIGTYPE (CLASS::*) {
%typemap(varin) SWIGTYPE * { /* %typemap(how) SWIGTYPE *, SWIGTYPE (CLASS::*) */
$1 = ($ltype)caml_ptr_val($input,$1_descriptor); void *v;
memcpy(&v,& $1, sizeof(void *));
$result = caml_val_ptr (v,$1_descriptor);
} }
%enddef
%typemap(varout) SWIGTYPE * { %swigtype_ptr_in(in);
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr"); %swigtype_ptr_in(memberin);
if( fromval ) { %swigtype_ptr_in(varin);
$result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor)); %swigtype_ptr_in(outv);
} else { %swigtype_ptr_out(out);
$result = caml_val_ptr ((void *)$1,$1_descriptor); %swigtype_ptr_out(memberout);
} %swigtype_ptr_out(varout);
} %swigtype_ptr_out(inv);
/* C++ References */ /* C++ References */