Skip to content

Commit e948188

Browse files
committed
Improve error_handing replacement functions
We explicitly skip calls to user_error_handler in EH_THROW mode Closes GH-6050.
1 parent 62dce97 commit e948188

File tree

1 file changed

+4
-41
lines changed

1 file changed

+4
-41
lines changed

Zend/zend_API.c

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4230,62 +4230,25 @@ ZEND_API void zend_save_error_handling(zend_error_handling *current) /* {{{ */
42304230
{
42314231
current->handling = EG(error_handling);
42324232
current->exception = EG(exception_class);
4233-
ZVAL_COPY(&current->user_handler, &EG(user_error_handler));
4233+
ZVAL_UNDEF(&current->user_handler);
42344234
}
42354235
/* }}} */
42364236

42374237
ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current) /* {{{ */
42384238
{
42394239
if (current) {
42404240
zend_save_error_handling(current);
4241-
if (error_handling != EH_NORMAL && Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
4242-
zval_ptr_dtor(&EG(user_error_handler));
4243-
ZVAL_UNDEF(&EG(user_error_handler));
4244-
}
42454241
}
4242+
ZEND_ASSERT(error_handling == EH_THROW || exception_class == NULL);
42464243
EG(error_handling) = error_handling;
4247-
EG(exception_class) = error_handling == EH_THROW ? exception_class : NULL;
4248-
}
4249-
/* }}} */
4250-
4251-
static int same_zval(zval *zv1, zval *zv2) /* {{{ */
4252-
{
4253-
if (Z_TYPE_P(zv1) != Z_TYPE_P(zv2)) {
4254-
return 0;
4255-
}
4256-
switch (Z_TYPE_P(zv1)) {
4257-
case IS_UNDEF:
4258-
case IS_NULL:
4259-
case IS_FALSE:
4260-
case IS_TRUE:
4261-
return 1;
4262-
case IS_LONG:
4263-
return Z_LVAL_P(zv1) == Z_LVAL_P(zv2);
4264-
case IS_DOUBLE:
4265-
return Z_LVAL_P(zv1) == Z_LVAL_P(zv2);
4266-
case IS_STRING:
4267-
case IS_ARRAY:
4268-
case IS_OBJECT:
4269-
case IS_RESOURCE:
4270-
return Z_COUNTED_P(zv1) == Z_COUNTED_P(zv2);
4271-
default:
4272-
return 0;
4273-
}
4244+
EG(exception_class) = exception_class;
42744245
}
42754246
/* }}} */
42764247

42774248
ZEND_API void zend_restore_error_handling(zend_error_handling *saved) /* {{{ */
42784249
{
42794250
EG(error_handling) = saved->handling;
4280-
EG(exception_class) = saved->handling == EH_THROW ? saved->exception : NULL;
4281-
if (Z_TYPE(saved->user_handler) != IS_UNDEF
4282-
&& !same_zval(&saved->user_handler, &EG(user_error_handler))) {
4283-
zval_ptr_dtor(&EG(user_error_handler));
4284-
ZVAL_COPY_VALUE(&EG(user_error_handler), &saved->user_handler);
4285-
} else if (Z_TYPE(saved->user_handler)) {
4286-
zval_ptr_dtor(&saved->user_handler);
4287-
}
4288-
ZVAL_UNDEF(&saved->user_handler);
4251+
EG(exception_class) = saved->exception;
42894252
}
42904253
/* }}} */
42914254

0 commit comments

Comments
 (0)