com php-src: Fixed bug #71013 (Incorrect exception handler with yield from): NEWS Zend/tests/generators/bug71013.phpt Zend/zend_gen erators.c
| From: | Bob Weinand | Date: | Sun, 06 Dec 2015 01:45:19 +0000 |
| Subject: | com php-src: Fixed bug #71013 (Incorrect exception handler with yield from): NEWS Zend/tests/generators/bug71013.phpt Zend/zend_gen erators.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-90099@lists.php.net to get a copy of this message | ||
Commit: 559ede17e109adec5dadff3290090e7141ad40ae
Author: Bob Weinand <bobwei9@hotmail.com> Sun, 6 Dec 2015 02:45:19 +0100
Parents: 1d5744027e1cb5bd5241c1901b281b4d520bbb81
Branches: PHP-7.0
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=559ede17e109adec5dadff3290090e7141ad40ae
Log:
Fixed bug #71013 (Incorrect exception handler with yield from)
Bugs:
https://bugs.php.net/71013
Changed paths:
M NEWS
A Zend/tests/generators/bug71013.phpt
M Zend/zend_generators.c
Diff:
diff --git a/NEWS b/NEWS
index 61fddca..788aa0f 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,7 @@ PHP NEWS
from an array. (Bob)
. Fixed bug #70987 (static::class within Closure::call() causes segfault).
(Andrea)
+ . Fixed bug #71013 (Incorrect exception handler with yield from). (Bob)
- CLI server:
. Fixed bug #71005 (Segfault in php_cli_server_dispatch_router()). (Adam)
diff --git a/Zend/tests/generators/bug71013.phpt b/Zend/tests/generators/bug71013.phpt
new file mode 100644
index 0000000..6ede86e
--- /dev/null
+++ b/Zend/tests/generators/bug71013.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Bug #71013 (Incorrect exception handler with yield from)
+--FILE--
+<?php
+
+class FooBar implements Iterator {
+ function __construct() { echo "Constructing new FooBar\n"; }
+ function __destruct() { echo "Destructing FooBar\n"; }
+ function current () { throw new Exception; }
+ function key () { return 0; }
+ function next () {}
+ function rewind () {}
+ function valid () { return true; }
+}
+
+function foo() {
+ try {
+ $f = new FooBar;
+ yield from $f;
+ } catch (Exception $e) {
+ echo "[foo()] Caught Exception\n";
+ }
+}
+
+function bar() {
+ echo "Starting bar()\n";
+ $x = foo();
+ try {
+ var_dump($x->current());
+ } catch (Exception $e) {
+ echo "[bar()] Caught Exception\n";
+ }
+ echo "Unsetting \$x\n";
+ unset($x);
+ echo "Finishing bar()\n";
+}
+
+bar();
+
+?>
+--EXPECT--
+Starting bar()
+Constructing new FooBar
+[foo()] Caught Exception
+Destructing FooBar
+NULL
+Unsetting $x
+Finishing bar()
+
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index eb7d40e..777adb5 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -573,7 +573,7 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /*
if (iter->index++ > 0) {
iter->funcs->move_forward(iter);
if (UNEXPECTED(EG(exception) != NULL)) {
- goto failure;
+ goto exception;
}
}
@@ -583,7 +583,9 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /*
}
value = iter->funcs->get_current_data(iter);
- if (UNEXPECTED(EG(exception) != NULL || !value)) {
+ if (UNEXPECTED(EG(exception) != NULL)) {
+ goto exception;
+ } else if (UNEXPECTED(!value)) {
goto failure;
}
@@ -595,7 +597,7 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /*
iter->funcs->get_current_key(iter, &generator->key);
if (UNEXPECTED(EG(exception) != NULL)) {
ZVAL_UNDEF(&generator->key);
- goto failure;
+ goto exception;
}
} else {
ZVAL_LONG(&generator->key, iter->index);
@@ -603,6 +605,13 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator)
/*
}
return SUCCESS;
+exception: {
+ zend_execute_data *ex = EG(current_execute_data);
+ EG(current_execute_data) = generator->execute_data;
+ zend_throw_exception_internal(NULL);
+ EG(current_execute_data) = ex;
+ }
+
failure:
zval_ptr_dtor(&generator->values);
ZVAL_UNDEF(&generator->values);