com php-src: Fix bug #69740: NEWS Zend/tests/bug69740.phpt Zend/zend_generators.c
| From: | Nikita Popov | Date: | Thu, 11 Jun 2015 15:40:10 +0000 |
| Subject: | com php-src: Fix bug #69740: NEWS Zend/tests/bug69740.phpt Zend/zend_generators.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-87215@lists.php.net to get a copy of this message | ||
Commit: 8405265578d2df8d76be223910b3e44aff4bdfef
Author: Nikita Popov <nikic@php.net> Thu, 11 Jun 2015 17:40:10 +0200
Parents: 702e349df4ef3cc91927efc0fc5caf0b59cd96e8
Branches: PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8405265578d2df8d76be223910b3e44aff4bdfef
Log:
Fix bug #69740
Bugs:
https://bugs.php.net/69740
Changed paths:
M NEWS
A Zend/tests/bug69740.phpt
M Zend/zend_generators.c
Diff:
diff --git a/NEWS b/NEWS
index 1cec854..90e051c 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ PHP NEWS
fault). (Christoph M. Becker)
. Fixed bug #69781 (phpinfo() reports Professional Editions of Windows
7/8/8.1/10 as "Business"). (Christian Wenz)
+ . Fixed bug #69740 (finally in generator (yield) swallows exception in
+ iteration). (Nikita)
- PDO_pgsql:
. Fixed bug #69752 (PDOStatement::execute() leaks memory with DML
diff --git a/Zend/tests/bug69740.phpt b/Zend/tests/bug69740.phpt
new file mode 100644
index 0000000..30a2a49
--- /dev/null
+++ b/Zend/tests/bug69740.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Bug #69740: finally in generator (yield) swallows exception in iteration
+--FILE--
+<?php
+
+function generate() {
+ try {
+ yield 1;
+ yield 2;
+ } finally {
+ echo "finally\n";
+ }
+}
+
+foreach (generate() as $i) {
+ echo $i, "\n";
+ throw new Exception();
+}
+
+?>
+--EXPECTF--
+1
+finally
+
+Fatal error: Uncaught exception 'Exception' in %s:%d
+Stack trace:
+#0 {main}
+ thrown in %s on line %d
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index 4b18f42..1cf9566 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -198,6 +198,9 @@ static void zend_generator_dtor_storage(zend_generator *generator, zend_object_h
if (finally_op_num) {
ex->opline = &ex->op_array->opcodes[finally_op_num];
ex->fast_ret = NULL;
+ ex->delayed_exception = EG(exception);
+ EG(exception) = NULL;
+
generator->flags |= ZEND_GENERATOR_FORCED_CLOSE;
zend_generator_resume(generator TSRMLS_CC);
}