From bf7c9e9a423a83fea22afa9480631d295045321c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 18 Feb 2011 06:39:51 +0000 Subject: [PATCH] [PHP] An overloaded method which can return an object or a primitive type no longer causes SWIG to segfault. Reported by Paul Colby in SF#3168531. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12471 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ Examples/test-suite/common.mk | 1 + Examples/test-suite/covariant_return.i | 16 ++++++++++++++++ Source/Modules/php.cxx | 7 ++++++- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/covariant_return.i diff --git a/CHANGES.current b/CHANGES.current index 05a23c2d9..759a7eea6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.2 (in progress) =========================== +2011-02-18: olly + [PHP] An overloaded method which can return an object or a + primitive type no longer causes SWIG to segfault. Reported by Paul + Colby in SF#3168531. + 2011-02-18: olly [PHP] Fix invalid erase during iteration of std::map in generated director code. Reported by Cory Bennett in SF#3175820. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 5f3012091..ce221b4ff 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -140,6 +140,7 @@ CPP_TEST_CASES += \ conversion \ conversion_namespace \ conversion_ns_template \ + covariant_return \ cplusplus_throw \ cpp_basic \ cpp_enum \ diff --git a/Examples/test-suite/covariant_return.i b/Examples/test-suite/covariant_return.i new file mode 100644 index 000000000..20d04841f --- /dev/null +++ b/Examples/test-suite/covariant_return.i @@ -0,0 +1,16 @@ +%module covariant_return + +// Regression test for PHP from SF#3168531i (SWIG <= 2.0.1 segfaults). + +%inline %{ + +#include +using namespace std; +class A { }; +class B { + public: + int foo(int x); + A foo(string y); +}; + +%} diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 554e40bb8..137dff935 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1718,7 +1718,6 @@ public: while (i.item) { SwigType *ret_type = i.item; i = Next(i); - Printf(output, "\t\t"); String *mangled = NewString("_p"); Printf(mangled, "%s", SwigType_manglestr(ret_type)); Node *class_node = Getattr(zend_types, mangled); @@ -1729,7 +1728,13 @@ public: Delete(mangled); mangled = NewString(SwigType_manglestr(ret_type)); class_node = Getattr(zend_types, mangled); + if (!class_node) { + // Return type isn't an object, so will be handled by the + // !is_resource() check before the switch. + continue; + } } + Printf(output, "\t\t"); if (i.item) { Printf(output, "case '%s': ", mangled); } else {