diff --git a/CHANGES.current b/CHANGES.current index f9d3f82a8..8483273d1 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,12 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.11 (in progress) ============================ +2016-09-24: olly + [PHP] Fix code generated for feature("director:except") - + previously the return value of call_user_function() was ignored and + we checked an uninitialised value instead. Fixes #627. Based on + patch from Sergey Seroshtan. + 2016-09-17: wsfulton [Python] Fix iterators for containers of NULL pointers (or Python None) when using -builtin. Previously iteration would stop at the first element that was NULL. diff --git a/Examples/test-suite/director_exception.i b/Examples/test-suite/director_exception.i index 2559ae566..abe23b381 100644 --- a/Examples/test-suite/director_exception.i +++ b/Examples/test-suite/director_exception.i @@ -28,6 +28,21 @@ class DirectorMethodException: public Swig::DirectorException {}; %include "std_string.i" +#ifdef SWIGPHP + +%feature("director:except") { + if ($error == FAILURE) { + throw Swig::DirectorMethodException(); + } +} + +%exception { + try { $action } + catch (Swig::DirectorException &) { SWIG_fail; } +} + +#endif + #ifdef SWIGPYTHON %feature("director:except") { diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index d50246e36..ee78c6d0a 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2625,6 +2625,7 @@ done: } /* exception handling */ + bool error_used_in_typemap = false; tm = Swig_typemap_lookup("director:except", n, Swig_cresult_name(), 0); if (!tm) { tm = Getattr(n, "feature:director:except"); @@ -2634,6 +2635,7 @@ done: if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { if (Replaceall(tm, "$error", "error")) { /* Only declare error if it is used by the typemap. */ + error_used_in_typemap = true; Append(w->code, "int error;\n"); } } else { @@ -2657,6 +2659,9 @@ done: /* wrap complex arguments to zvals */ Printv(w->code, wrap_args, NIL); + if (error_used_in_typemap) { + Append(w->code, "error = "); + } Append(w->code, "call_user_function(EG(function_table), (zval**)&swig_self, &funcname,"); Printf(w->code, " %s, %d, args TSRMLS_CC);\n", Swig_cresult_name(), idx);