Merge branch 'ZackerySpytz-OCaml-director_pass_by_value'
* ZackerySpytz-OCaml-director_pass_by_value: [OCaml] Fix director_pass_by_value [OCaml] Reduce the duplication in typemaps.i
This commit is contained in:
commit
b80b4d5638
6 changed files with 82 additions and 54 deletions
|
|
@ -21,7 +21,6 @@ cpp_enum \
|
|||
default_constructor \
|
||||
director_binary_string \
|
||||
director_enum \
|
||||
director_pass_by_value \
|
||||
director_primitives \
|
||||
director_redefined \
|
||||
director_string \
|
||||
|
|
|
|||
5
Examples/test-suite/ocaml/director_frob_runme.ml
Normal file
5
Examples/test-suite/ocaml/director_frob_runme.ml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
open Swig
|
||||
open Director_frob
|
||||
|
||||
let foo = new_Bravo '()
|
||||
assert (foo -> abs_method () as string = "Bravo::abs_method()")
|
||||
24
Examples/test-suite/ocaml/director_pass_by_value_runme.ml
Normal file
24
Examples/test-suite/ocaml/director_pass_by_value_runme.ml
Normal file
|
|
@ -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);
|
||||
;;
|
||||
19
Examples/test-suite/ocaml/director_unroll_runme.ml
Normal file
19
Examples/test-suite/ocaml/director_unroll_runme.ml
Normal file
|
|
@ -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()");
|
||||
;;
|
||||
|
|
@ -579,6 +579,19 @@ extern "C" {
|
|||
}
|
||||
}
|
||||
|
||||
SWIGINTERN CAML_VALUE SWIG_Ocaml_ptr_to_val(const char *name, void *ptr, swig_type_info *descriptor) {
|
||||
CAMLparam0();
|
||||
SWIG_CAMLlocal1(result);
|
||||
|
||||
CAML_VALUE *fromval = caml_named_value(name);
|
||||
if (fromval) {
|
||||
result = caml_callback(*fromval, caml_val_ptr(ptr, descriptor));
|
||||
} else {
|
||||
result = caml_val_ptr(ptr, descriptor);
|
||||
}
|
||||
CAMLreturn(result);
|
||||
}
|
||||
|
||||
static swig_module_info *SWIG_Ocaml_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
|
||||
CAML_VALUE pointer;
|
||||
|
||||
|
|
|
|||
|
|
@ -52,22 +52,8 @@
|
|||
$1 = *(($ltype) caml_ptr_val($input,$1_descriptor));
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE & {
|
||||
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
|
||||
if( fromval ) {
|
||||
$result = caml_callback(*fromval,caml_val_ptr((void *) &$1,$1_descriptor));
|
||||
} else {
|
||||
$result = caml_val_ptr ((void *) &$1,$1_descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE && {
|
||||
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
|
||||
if( fromval ) {
|
||||
$result = caml_callback(*fromval,caml_val_ptr((void *) &$1,$1_descriptor));
|
||||
} else {
|
||||
$result = caml_val_ptr ((void *) &$1,$1_descriptor);
|
||||
}
|
||||
%typemap(out) SWIGTYPE &, SWIGTYPE && {
|
||||
$result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", (void *)&$1, $1_descriptor);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
|
@ -110,29 +96,30 @@
|
|||
|
||||
%typemap(out) SWIGTYPE {
|
||||
$&1_ltype temp = new $ltype((const $1_ltype &) $1);
|
||||
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
|
||||
if( fromval ) {
|
||||
$result = caml_callback(*fromval,caml_val_ptr((void *)temp,$&1_descriptor));
|
||||
} else {
|
||||
$result = caml_val_ptr ((void *)temp,$&1_descriptor);
|
||||
}
|
||||
$result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", (void *)temp, $&1_descriptor);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
%typemap(out) SWIGTYPE {
|
||||
void *temp = calloc(1,sizeof($ltype));
|
||||
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
|
||||
memmove( temp, &$1, sizeof( $1_type ) );
|
||||
if( fromval ) {
|
||||
$result = caml_callback(*fromval,caml_val_ptr((void *)temp,$&1_descriptor));
|
||||
} else {
|
||||
$result = caml_val_ptr ((void *)temp,$&1_descriptor);
|
||||
}
|
||||
memmove(temp, &$1, sizeof($1_type));
|
||||
$result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", temp, $&1_descriptor);
|
||||
}
|
||||
|
||||
#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. */
|
||||
|
||||
|
|
@ -209,23 +196,8 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val);
|
|||
|
||||
/* Pass through value */
|
||||
|
||||
%typemap (in) value,caml::value,CAML_VALUE "$1=$input;";
|
||||
%typemap (out) value,caml::value,CAML_VALUE "$result=$1;";
|
||||
|
||||
/* Arrays */
|
||||
|
||||
%typemap(in) ArrayCarrier * {
|
||||
$1 = ($ltype)caml_ptr_val($input,$1_descriptor);
|
||||
}
|
||||
|
||||
%typemap(out) ArrayCarrier * {
|
||||
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
|
||||
if( fromval ) {
|
||||
$result = caml_callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor));
|
||||
} else {
|
||||
$result = caml_val_ptr ((void *)$1,$1_descriptor);
|
||||
}
|
||||
}
|
||||
%typemap (in) CAML_VALUE "$1=$input;";
|
||||
%typemap (out) CAML_VALUE "$result=$1;";
|
||||
|
||||
#if 0
|
||||
%include <carray.i>
|
||||
|
|
@ -276,15 +248,11 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val);
|
|||
}
|
||||
%enddef
|
||||
|
||||
%define %swigtype_ptr_out(how)
|
||||
%typemap(out) SWIGTYPE * {
|
||||
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
|
||||
if( fromval ) {
|
||||
$result = caml_callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor));
|
||||
} else {
|
||||
$result = caml_val_ptr ((void *)$1,$1_descriptor);
|
||||
}
|
||||
$result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", (void *)$1, $1_descriptor);
|
||||
}
|
||||
|
||||
%define %swigtype_ptr_out(how)
|
||||
%typemap(how) SWIGTYPE (CLASS::*) {
|
||||
void *v;
|
||||
memcpy(&v,& $1, sizeof(void *));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue