mirror of
https://github.com/php/php-src.git
synced 2024-11-30 21:35:36 +08:00
Improve error_handing replacement functions
We explicitly skip calls to user_error_handler in EH_THROW mode Closes GH-6050.
This commit is contained in:
parent
62dce97973
commit
e948188832
@ -4230,7 +4230,7 @@ ZEND_API void zend_save_error_handling(zend_error_handling *current) /* {{{ */
|
||||
{
|
||||
current->handling = EG(error_handling);
|
||||
current->exception = EG(exception_class);
|
||||
ZVAL_COPY(¤t->user_handler, &EG(user_error_handler));
|
||||
ZVAL_UNDEF(¤t->user_handler);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -4238,54 +4238,17 @@ ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling,
|
||||
{
|
||||
if (current) {
|
||||
zend_save_error_handling(current);
|
||||
if (error_handling != EH_NORMAL && Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
|
||||
zval_ptr_dtor(&EG(user_error_handler));
|
||||
ZVAL_UNDEF(&EG(user_error_handler));
|
||||
}
|
||||
}
|
||||
ZEND_ASSERT(error_handling == EH_THROW || exception_class == NULL);
|
||||
EG(error_handling) = error_handling;
|
||||
EG(exception_class) = error_handling == EH_THROW ? exception_class : NULL;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static int same_zval(zval *zv1, zval *zv2) /* {{{ */
|
||||
{
|
||||
if (Z_TYPE_P(zv1) != Z_TYPE_P(zv2)) {
|
||||
return 0;
|
||||
}
|
||||
switch (Z_TYPE_P(zv1)) {
|
||||
case IS_UNDEF:
|
||||
case IS_NULL:
|
||||
case IS_FALSE:
|
||||
case IS_TRUE:
|
||||
return 1;
|
||||
case IS_LONG:
|
||||
return Z_LVAL_P(zv1) == Z_LVAL_P(zv2);
|
||||
case IS_DOUBLE:
|
||||
return Z_LVAL_P(zv1) == Z_LVAL_P(zv2);
|
||||
case IS_STRING:
|
||||
case IS_ARRAY:
|
||||
case IS_OBJECT:
|
||||
case IS_RESOURCE:
|
||||
return Z_COUNTED_P(zv1) == Z_COUNTED_P(zv2);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
EG(exception_class) = exception_class;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
ZEND_API void zend_restore_error_handling(zend_error_handling *saved) /* {{{ */
|
||||
{
|
||||
EG(error_handling) = saved->handling;
|
||||
EG(exception_class) = saved->handling == EH_THROW ? saved->exception : NULL;
|
||||
if (Z_TYPE(saved->user_handler) != IS_UNDEF
|
||||
&& !same_zval(&saved->user_handler, &EG(user_error_handler))) {
|
||||
zval_ptr_dtor(&EG(user_error_handler));
|
||||
ZVAL_COPY_VALUE(&EG(user_error_handler), &saved->user_handler);
|
||||
} else if (Z_TYPE(saved->user_handler)) {
|
||||
zval_ptr_dtor(&saved->user_handler);
|
||||
}
|
||||
ZVAL_UNDEF(&saved->user_handler);
|
||||
EG(exception_class) = saved->exception;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user