diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index bcae168f0..1512834f9 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -5058,7 +5058,19 @@ private: Printv(w->def, " {\n", NULL); if (SwigType_type(result) != T_VOID) { - Wrapper_add_local(w, "c_result", SwigType_lstr(result, "c_result")); + if (!SwigType_isclass(result)) { + if (!(SwigType_ispointer(result) || SwigType_isreference(result))) { + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(result, 0)); + Wrapper_add_localv(w, "c_result", SwigType_lstr(result, "c_result"), construct_result, NIL); + Delete(construct_result); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(result, "c_result"), "= 0", NIL); + } + } else { + String *cres = SwigType_lstr(result, "c_result"); + Printf(w->code, "%s;\n", cres); + Delete(cres); + } } if (!is_ignored) { diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 73dd14f96..15a13f5ec 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -1429,9 +1429,19 @@ public: * if the return value is a reference or const reference, a specialized typemap must * handle it, including declaration of c_result ($result). */ - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + if (!is_void && (!ignored_method || pure_virtual)) { + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); + Delete(construct_result); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); + } + } else { + String *cres = SwigType_lstr(returntype, "c_result"); + Printf(w->code, "%s;\n", cres); + Delete(cres); } } diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 0130cedd8..e64a0779f 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -1359,11 +1359,19 @@ public: // declare method return value // if the return value is a reference or const reference, a specialized typemap must // handle it, including declaration of c_result ($result). - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - String *cres = SwigType_lstr(returntype, "c_result"); - Printf(w->code, "%s;\n", cres); - Delete(cres); + if (!is_void && (!ignored_method || pure_virtual)) { + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); + Delete(construct_result); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); + } + } else { + String *cres = SwigType_lstr(returntype, "c_result"); + Printf(w->code, "%s;\n", cres); + Delete(cres); } } diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index a7c7fa9ff..e46761028 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -2130,10 +2130,20 @@ public: * handle it, including declaration of c_result ($result). */ if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - String *cres = SwigType_lstr(returntype, "c_result"); - Printf(w->code, "%s;\n", cres); - Delete(cres); + if (!ignored_method || pure_virtual) { + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); + Delete(construct_result); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); + } + } else { + String *cres = SwigType_lstr(returntype, "c_result"); + Printf(w->code, "%s;\n", cres); + Delete(cres); + } } if (!ignored_method) { String *pres = NewStringf("SV *%s", Swig_cresult_name()); diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index f0e3ae2df..e6fbf47d7 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2569,8 +2569,16 @@ done: * if the return value is a reference or const reference, a specialized typemap must * handle it, including declaration of c_result ($result). */ - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { + if (!is_void && (!ignored_method || pure_virtual)) { + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); + Delete(construct_result); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); + } + } else { String *cres = SwigType_lstr(returntype, "c_result"); Printf(w->code, "%s;\n", cres); Delete(cres); diff --git a/Source/Modules/php5.cxx b/Source/Modules/php5.cxx index 188f287d5..59d928c21 100644 --- a/Source/Modules/php5.cxx +++ b/Source/Modules/php5.cxx @@ -2566,8 +2566,16 @@ done: * if the return value is a reference or const reference, a specialized typemap must * handle it, including declaration of c_result ($result). */ - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { + if (!is_void && (!ignored_method || pure_virtual)) { + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); + Delete(construct_result); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); + } + } else { String *cres = SwigType_lstr(returntype, "c_result"); Printf(w->code, "%s;\n", cres); Delete(cres); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 8dcabb578..2248ba920 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -5404,8 +5404,16 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { * if the return value is a reference or const reference, a specialized typemap must * handle it, including declaration of c_result ($result). */ - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { + if (!is_void && (!ignored_method || pure_virtual)) { + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); + Delete(construct_result); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); + } + } else { String *cres = SwigType_lstr(returntype, "c_result"); Printf(w->code, "%s;\n", cres); Delete(cres); diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 07c5797f8..25988d6fb 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -3154,9 +3154,19 @@ public: * if the return value is a reference or const reference, a specialized typemap must * handle it, including declaration of c_result ($result). */ - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + if (!is_void && (!ignored_method || pure_virtual)) { + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); + Delete(construct_result); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); + } + } else { + String *cres = SwigType_lstr(returntype, "c_result"); + Printf(w->code, "%s;\n", cres); + Delete(cres); } }