Make PHP directors work more like other languages

A PHP exception now gets translated to a C++ exception to skips over C++
code to get back to PHP, avoiding the need to gate every directorout
typemap on EG(exception).
This commit is contained in:
Olly Betts 2021-04-22 14:40:21 +12:00
commit 50426aae20
8 changed files with 50 additions and 88 deletions

View file

@ -93,18 +93,15 @@
%typemap(directorout) SWIGTYPE ($&1_ltype tmp)
%{
/* If exit was via exception, PHP NULL is returned so skip the conversion. */
if (!EG(exception)) {
if ($needNewFlow) {
tmp = ($&1_ltype) &SWIG_Z_FETCH_OBJ_P($1)->ptr;
SWIG_Z_FETCH_OBJ_P($1)->newobject = 0;
} else {
if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
}
if ($needNewFlow) {
tmp = ($&1_ltype) &SWIG_Z_FETCH_OBJ_P($1)->ptr;
SWIG_Z_FETCH_OBJ_P($1)->newobject = 0;
} else {
if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
}
$result = *tmp;
}
$result = *tmp;
%}
%typemap(in) SWIGTYPE *,

View file

@ -55,6 +55,9 @@ static zend_always_inline void *zend_object_alloc(size_t obj_size, zend_class_en
#define SWIG_fail goto fail
// If there's an active PHP exception, just return so it can propagate.
#define SWIG_FAIL() do { if (!EG(exception)) zend_error_noreturn(SWIG_ErrorCode(), "%s", SWIG_ErrorMsg()); goto thrown; } while (0)
static const char *default_error_msg = "Unknown error occurred";
static int default_error_code = E_ERROR;

View file

@ -33,10 +33,8 @@ namespace std {
%}
%typemap(directorout) string %{
if (!EG(exception)) {
convert_to_string($input);
$result.assign(Z_STRVAL_P($input), Z_STRLEN_P($input));
}
%}
%typemap(out) string %{
@ -74,12 +72,10 @@ namespace std {
%}
%typemap(directorout) string & ($*1_ltype *temp) %{
if (!EG(exception)) {
convert_to_string($input);
temp = new $*1_ltype(Z_STRVAL_P($input), Z_STRLEN_P($input));
swig_acquire_ownership(temp);
$result = temp;
}
%}
%typemap(argout) string & %{

View file

@ -75,19 +75,15 @@
%}
%typemap(directorout) TYPE
%{
if (!EG(exception)) {
CONVERT_IN($result, $1_ltype, *$input);
}
CONVERT_IN($result, $1_ltype, *$input);
%}
%typemap(directorout) const TYPE &
%{
$*1_ltype swig_val;
if (!EG(exception)) {
CONVERT_IN(swig_val, $*1_ltype, *$input);
$1_ltype temp = new $*1_ltype(($*1_ltype)swig_val);
swig_acquire_ownership(temp);
$result = temp;
}
CONVERT_IN(swig_val, $*1_ltype, *$input);
$1_ltype temp = new $*1_ltype(($*1_ltype)swig_val);
swig_acquire_ownership(temp);
$result = temp;
%}
%typemap(directorfree) const TYPE &
%{