summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2015-11-21 05:16:11 -0800
committerAnatol Belski <ab@php.net>2015-11-21 18:28:04 +0100
commitc2f7fadee2fa176bb020f7833686fbc6cd092bc7 (patch)
tree046742fa1fe71d3cfc4c9174ce313ca32c9d96a3
parent7d2a26b3fd90fb8ef8ab5d1a7134c370f3be0a78 (diff)
downloadphp-git-c2f7fadee2fa176bb020f7833686fbc6cd092bc7.tar.gz
Port the fix of 5.6 to 7.0
-rw-r--r--Zend/tests/bug70944.phpt6
-rw-r--r--Zend/zend_exceptions.c35
2 files changed, 21 insertions, 20 deletions
diff --git a/Zend/tests/bug70944.phpt b/Zend/tests/bug70944.phpt
index 192fd6d501..afb10bc27f 100644
--- a/Zend/tests/bug70944.phpt
+++ b/Zend/tests/bug70944.phpt
@@ -25,13 +25,13 @@ try {
}
?>
--EXPECTF--
-string(%d) "exception 'Exception' with message 'Foo' in %sbug70944.php:%d
+string(%d) "Exception: Foo in %sbug70944.php:%d
Stack trace:
#0 {main}"
-string(%d) "exception 'Exception' with message 'Foo' in %sbug70944.php:%d
+string(%d) "Exception: Foo in %sbug70944.php:%d
Stack trace:
#0 {main}
-Next exception 'Exception' with message 'Dummy' in %sbug70944.php:%d
+Next Exception: Dummy in %sbug70944.php:%d
Stack trace:
#0 {main}"
diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c
index dd137dfb95..147fbe8ad9 100644
--- a/Zend/zend_exceptions.c
+++ b/Zend/zend_exceptions.c
@@ -70,37 +70,38 @@ ZEND_API zend_class_entry *zend_get_exception_base(zval *object)
void zend_exception_set_previous(zend_object *exception, zend_object *add_previous)
{
- zval *previous, *pzv;
- zval tmp, zv, rv;
+ zval *previous, *ancestor, *ex;
+ zval pv, zv, rv;
zend_class_entry *base_ce;
if (exception == add_previous || !add_previous || !exception) {
return;
}
- ZVAL_OBJ(&tmp, add_previous);
- if (!instanceof_function(Z_OBJCE(tmp), zend_ce_throwable)) {
+ ZVAL_OBJ(&pv, add_previous);
+ if (!instanceof_function(Z_OBJCE(pv), zend_ce_throwable)) {
zend_error_noreturn(E_CORE_ERROR, "Previous exception must implement Throwable");
return;
}
- pzv = zend_read_property(i_get_exception_base(&tmp), &tmp, "previous", sizeof("previous")-1, 1, &rv);
- while (Z_TYPE_P(pzv) == IS_OBJECT) {
- if (Z_OBJ_P(pzv) == exception) {
- return;
- }
- pzv = zend_read_property(i_get_exception_base(pzv), pzv, "previous", sizeof("previous")-1, 1, &rv);
- }
ZVAL_OBJ(&zv, exception);
- pzv = &zv;
+ ex = &zv;
do {
- base_ce = i_get_exception_base(pzv);
- previous = zend_read_property(base_ce, pzv, "previous", sizeof("previous")-1, 1, &rv);
+ ancestor = zend_read_property(i_get_exception_base(&pv), &pv, "previous", sizeof("previous")-1, 1, &rv);
+ while (Z_TYPE_P(ancestor) == IS_OBJECT) {
+ if (Z_OBJ_P(ancestor) == Z_OBJ_P(ex)) {
+ OBJ_RELEASE(add_previous);
+ return;
+ }
+ ancestor = zend_read_property(i_get_exception_base(ancestor), ancestor, "previous", sizeof("previous")-1, 1, &rv);
+ }
+ base_ce = i_get_exception_base(ex);
+ previous = zend_read_property(base_ce, ex, "previous", sizeof("previous")-1, 1, &rv);
if (Z_TYPE_P(previous) == IS_NULL) {
- zend_update_property(base_ce, pzv, "previous", sizeof("previous")-1, &tmp);
+ zend_update_property(base_ce, ex, "previous", sizeof("previous")-1, &pv);
GC_REFCOUNT(add_previous)--;
return;
}
- pzv = previous;
- } while (pzv && Z_OBJ_P(pzv) != add_previous);
+ ex = previous;
+ } while (Z_OBJ_P(ex) != add_previous);
}
void zend_exception_save(void) /* {{{ */