Replace remaining PHP errors with PHP exceptions
`SWIG_ErrorCode()`, `SWIG_ErrorMsg()`, `SWIG_FAIL()` and `goto thrown;` are no longer supported (these are really all internal implementation details and none are documented aside from brief mentions in CHANGES for the first three). I wasn't able to find any uses at least in FOSS code via code search tools. If you are using these: Use `SWIG_PHP_Error(code,msg);` instead of `SWIG_ErrorCode(code); SWIG_ErrorMsg(msg);` (which will throw a PHP exception in SWIG >= 4.1 and do the same as the individual calls in older SWIG). `SWIG_FAIL();` and `goto thrown;` can typically be replaced with `SWIG_fail;`. This will probably also work with older SWIG, but please test with your wrappers if this is important to you. Fixes #2014
This commit is contained in:
parent
cdc69f9843
commit
17a294cec4
7 changed files with 41 additions and 68 deletions
|
|
@ -25,7 +25,7 @@
|
|||
code == SWIG_DivisionByZero ? zend_ce_division_by_zero_error : \
|
||||
code == SWIG_SyntaxError ? zend_ce_parse_error : \
|
||||
code == SWIG_OverflowError ? zend_ce_arithmetic_error : \
|
||||
NULL, msg, code); goto thrown; } while (0)
|
||||
NULL, msg, code); SWIG_fail; } while (0)
|
||||
%}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -137,8 +137,8 @@ namespace Swig {
|
|||
swig_msg += " ";
|
||||
swig_msg += msg;
|
||||
}
|
||||
SWIG_ErrorCode() = code;
|
||||
SWIG_ErrorMsg() = swig_msg.c_str();
|
||||
// Don't replace an already active PHP exception.
|
||||
if (!EG(exception)) zend_throw_exception(NULL, swig_msg.c_str(), code);
|
||||
}
|
||||
|
||||
virtual ~DirectorException() throw() {
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@
|
|||
%{
|
||||
if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) {
|
||||
zend_type_error("Expected $&1_descriptor for argument $argnum of $symname");
|
||||
goto thrown;
|
||||
SWIG_fail;
|
||||
}
|
||||
$result = *tmp;
|
||||
%}
|
||||
|
|
@ -115,7 +115,7 @@
|
|||
%{
|
||||
if (SWIG_ConvertPtrAndOwn($input, (void **)&$result, $1_descriptor, SWIG_POINTER_DISOWN, &own) < 0) {
|
||||
zend_type_error("Expected $1_descriptor for argument $argnum of $symname");
|
||||
goto thrown;
|
||||
SWIG_fail;
|
||||
}
|
||||
swig_acquire_ownership_obj((void*)$result, own);
|
||||
%}
|
||||
|
|
@ -134,7 +134,7 @@
|
|||
%{
|
||||
if (SWIG_ConvertPtr($input, (void **) &tmp, $1_descriptor, 0) < 0 || tmp == NULL) {
|
||||
zend_type_error("Expected $1_descriptor for argument $argnum of $symname");
|
||||
goto thrown;
|
||||
SWIG_fail;
|
||||
}
|
||||
$result = tmp;
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -58,15 +58,12 @@ 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;
|
||||
|
||||
#define SWIG_PHP_Arg_Error_Msg(argnum,extramsg) "Error in argument " #argnum " "#extramsg
|
||||
|
||||
#define SWIG_PHP_Error(code,msg) do { SWIG_ErrorCode() = code; SWIG_ErrorMsg() = msg; SWIG_fail; } while (0)
|
||||
#define SWIG_PHP_Error(code,msg) do { zend_throw_exception(NULL, msg, code); SWIG_fail; } while (0)
|
||||
|
||||
#define SWIG_contract_assert(expr,msg) \
|
||||
do { if (!(expr)) zend_printf("Contract Assert Failed %s\n", msg); } while (0)
|
||||
|
|
@ -102,7 +99,7 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) {
|
|||
}
|
||||
|
||||
if (!type->clientdata) {
|
||||
zend_error(E_ERROR, "Type: %s not registered with zend", type->name);
|
||||
zend_type_error("Type: %s not registered with zend", type->name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ INT_TYPEMAP(unsigned long long);
|
|||
if (!(Z_ISREF($input) && Z_ISNULL_P(Z_REFVAL($input)))) {
|
||||
/* wasn't a pre/ref/thing, OR anything like an int thing */
|
||||
zend_type_error("Expected reference or NULL for argument $arg of $symname");
|
||||
SWIG_FAIL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
force=0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue