[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.
This commit is contained in:
Olly Betts 2022-06-09 17:42:21 +12:00
commit 2df27036b7

View file

@ -2249,11 +2249,13 @@ public:
if (tm) if (tm)
tm = Copy(tm); tm = Copy(tm);
} }
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { if (!tm || Len(tm) == 0 || Equal(tm, "1")) {
Replaceall(tm, "$error", "EG(exception)"); // Skip marshalling the return value as there isn't one.
Printv(w->code, Str(tm), "\n", NIL); 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); Delete(tm);
/* marshal return value from PHP to C/C++ type */ /* marshal return value from PHP to C/C++ type */
@ -2301,6 +2303,8 @@ public:
} }
} }
Append(w->code, "}\n");
Delete(cleanup); Delete(cleanup);
Delete(outarg); Delete(outarg);
} }