summaryrefslogtreecommitdiff
path: root/Lib/php/php.swg
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2021-05-25 16:37:21 +1200
committerOlly Betts <olly@survex.com>2021-05-25 16:42:12 +1200
commitcdc69f9843a9b153a91109a493702e089f48602f (patch)
treeb14a7557e24b4beae1c4f621e024b2dc38a5790d /Lib/php/php.swg
parent8fb25b6a38e41d8147d5f0767d64ab269f0fdc66 (diff)
downloadswig-cdc69f9843a9b153a91109a493702e089f48602f.tar.gz
php: Throw exceptions instead of using errors
Parameter type errors and some other cases in SWIG-generated wrappers now throw a PHP exception, which is how PHP's native parameter handling deals with similar situations. See #2014, but not closing yet as there may be more cases to convert.
Diffstat (limited to 'Lib/php/php.swg')
-rw-r--r--Lib/php/php.swg35
1 files changed, 23 insertions, 12 deletions
diff --git a/Lib/php/php.swg b/Lib/php/php.swg
index 42985eac7..3b579b9fc 100644
--- a/Lib/php/php.swg
+++ b/Lib/php/php.swg
@@ -86,7 +86,8 @@
%typemap(in) SWIGTYPE ($&1_ltype tmp)
%{
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");
+ zend_type_error("Expected $&1_descriptor for argument $argnum of $symname");
+ return;
}
$1 = *tmp;
%}
@@ -94,7 +95,8 @@
%typemap(directorout) SWIGTYPE ($&1_ltype tmp)
%{
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");
+ zend_type_error("Expected $&1_descriptor for argument $argnum of $symname");
+ goto thrown;
}
$result = *tmp;
%}
@@ -103,7 +105,8 @@
SWIGTYPE []
%{
if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) {
- SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
+ zend_type_error("Expected $1_descriptor for argument $argnum of $symname");
+ return;
}
%}
@@ -111,7 +114,8 @@
SWIGTYPE [] (swig_owntype own)
%{
if (SWIG_ConvertPtrAndOwn($input, (void **)&$result, $1_descriptor, SWIG_POINTER_DISOWN, &own) < 0) {
- SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
+ zend_type_error("Expected $1_descriptor for argument $argnum of $symname");
+ goto thrown;
}
swig_acquire_ownership_obj((void*)$result, own);
%}
@@ -120,7 +124,8 @@
SWIGTYPE &&
%{
if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) {
- SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
+ zend_type_error("Expected $1_descriptor for argument $argnum of $symname");
+ return;
}
%}
@@ -128,7 +133,8 @@
SWIGTYPE && ($1_ltype tmp)
%{
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");
+ zend_type_error("Expected $1_descriptor for argument $argnum of $symname");
+ goto thrown;
}
$result = tmp;
%}
@@ -136,7 +142,8 @@
%typemap(in) SWIGTYPE *const& ($*ltype temp)
%{
if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) {
- SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor");
+ zend_type_error("Expected $*1_descriptor for argument $argnum of $symname");
+ return;
}
$1 = ($1_ltype)&temp;
%}
@@ -144,7 +151,8 @@
%typemap(in) SWIGTYPE *DISOWN
%{
if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN) < 0) {
- SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
+ zend_type_error("Expected $1_descriptor for argument $argnum of $symname");
+ return;
}
%}
@@ -157,10 +165,12 @@
%{
if (SWIG_ConvertPtr(&$input, (void **) &$1, 0, 0) < 0) {
/* Allow NULL from php for void* */
- if (Z_ISNULL($input))
+ if (Z_ISNULL($input)) {
$1=0;
- else
- SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
+ } else {
+ zend_type_error("Expected $1_descriptor for argument $argnum of $symname");
+ return;
+ }
}
%}
@@ -175,7 +185,8 @@
/* So... we didn't get a ref or ptr, but we'll accept NULL by reference */
if (!(Z_ISREF($input) && Z_ISNULL_P(Z_REFVAL($input)))) {
/* wasn't a pre/ref/thing, OR anything like an int thing */
- SWIG_PHP_Error(E_ERROR, "Type error in argument $arg of $symname.");
+ zend_throw_exception(zend_ce_type_error, "Type error in argument $arg of $symname", 0);
+ return;
}
}
force=0;