Merge branch 'ZackerySpytz-OCaml-classDirectorMethod-CAMLreturn'

* ZackerySpytz-OCaml-classDirectorMethod-CAMLreturn:
  [OCaml] Fix possible GC issues in generated director code

 Conflicts:
	Examples/test-suite/ocaml/director_unroll_runme.ml
This commit is contained in:
William S Fulton 2019-02-09 22:54:43 +00:00
commit 9ab873f432
2 changed files with 15 additions and 16 deletions

View file

@ -3,17 +3,13 @@ open Director_unroll
let director_unroll_MyFoo ob meth args = let director_unroll_MyFoo ob meth args =
match meth with match meth with
| "ping" -> C_string "director_unroll_MyFoo::ping()" | "ping" -> C_string "MyFoo::ping()"
| _ -> (invoke ob) meth args | _ -> (invoke ob) meth args
let a = let a = new_derived_object
new_derived_object new_Foo (director_unroll_MyFoo) '()
new_Foo (director_unroll_MyFoo) '()
let _ = let b = new_Bar '()
let b = new_Bar '() in let _ = b -> set (a)
let _ = b -> set (a) in let c = b -> get ()
let c = b -> get () in let _ = assert ((a -> "&" () as int) = (c -> "&" () as int))
assert (director_unroll_MyFoo c "ping" '() as string =
"director_unroll_MyFoo::ping()");
;;

View file

@ -1405,8 +1405,7 @@ public:
pure_virtual = true; pure_virtual = true;
} }
} }
Printf(w->locals, "CAMLparam0();\n");
Wrapper_add_local(w, "swig_result", "CAMLparam0();\n" "SWIG_CAMLlocal2(swig_result,args)");
/* determine if the method returns a pointer */ /* determine if the method returns a pointer */
is_pointer = SwigType_ispointer_return(decl); is_pointer = SwigType_ispointer_return(decl);
@ -1480,16 +1479,18 @@ public:
if (ignored_method) { if (ignored_method) {
if (!pure_virtual) { if (!pure_virtual) {
if (!is_void)
Printf(w->code, "return ");
String *super_call = Swig_method_call(super, l); String *super_call = Swig_method_call(super, l);
Printf(w->code, "%s;\n", super_call); if (is_void)
Printf(w->code, "%s;\n", super_call);
else
Printf(w->code, "CAMLreturn_type(%s);\n", super_call);
Delete(super_call); Delete(super_call);
} else { } else {
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname),
SwigType_namestr(name)); SwigType_namestr(name));
} }
} else { } else {
Wrapper_add_local(w, "swig_result", "SWIG_CAMLlocal2(swig_result, args)");
/* attach typemaps to arguments (C/C++ -> Ocaml) */ /* attach typemaps to arguments (C/C++ -> Ocaml) */
String *arglist = NewString(""); String *arglist = NewString("");
@ -1686,6 +1687,8 @@ public:
Printf(w->code, "CAMLreturn_type(*c_result);\n"); Printf(w->code, "CAMLreturn_type(*c_result);\n");
} }
} }
} else {
Printf(w->code, "CAMLreturn0;\n");
} }
Printf(w->code, "}\n"); Printf(w->code, "}\n");