From 2df27036b71ef1fbb3b6a701450fa3e06a18381b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 9 Jun 2022 17:42:21 +1200 Subject: [PATCH] [php] Skip directorout typemap if PHP exception pending Otherwise can end up with a second PHP exception if the directorout typemap doesn't accept PHP Null. `SWIG_fail` in this case results in us returning to PHP which then propagates the pending exception. This commit fixes a failure in smoketest.php in Xapian's PHP bindings, but I've not managed to come up with a reproducer which works for SWIG's testsuite. --- Source/Modules/php.cxx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index bbdd95249..faf4fe070 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2249,11 +2249,13 @@ public: if (tm) tm = Copy(tm); } - if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { - Replaceall(tm, "$error", "EG(exception)"); - Printv(w->code, Str(tm), "\n", NIL); + if (!tm || Len(tm) == 0 || Equal(tm, "1")) { + // Skip marshalling the return value as there isn't one. + tm = NewString("if ($error) SWIG_fail;"); } - Append(w->code, "}\n"); + + Replaceall(tm, "$error", "EG(exception)"); + Printv(w->code, Str(tm), "\n}\n{\n", NIL); Delete(tm); /* marshal return value from PHP to C/C++ type */ @@ -2301,6 +2303,8 @@ public: } } + Append(w->code, "}\n"); + Delete(cleanup); Delete(outarg); }