Typedef_mptr test (with runme).

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4871 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Art Yerkes 2003-06-06 16:19:28 +00:00
commit f45fd1a36e
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
#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

View file

@ -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 */