com php-src: Make sure that exception is thrown on rewind() after closing too: Zend/tests/generators/generator_rewind.phpt Zend/zen d_generators.c
| From: | Gustavo André dos Santos Lopes | Date: | Wed, 29 Aug 2012 18:31:34 +0000 |
| Subject: | com php-src: Make sure that exception is thrown on rewind() after closing too: Zend/tests/generators/generator_rewind.phpt Zend/zen d_generators.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-70015@lists.php.net to get a copy of this message | ||
Commit: cc07038fa9b2a59893c52fb0c515a1fb03e56d5c
Author: Nikita Popov <nikic@php.net> Wed, 29 Aug 2012 20:31:34 +0200
Parents: d60e3c6ef53986e82178bb657ad907edc16d2c34
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=cc07038fa9b2a59893c52fb0c515a1fb03e56d5c
Log:
Make sure that exception is thrown on rewind() after closing too
Changed paths:
M Zend/tests/generators/generator_rewind.phpt
M Zend/zend_generators.c
Diff:
diff --git a/Zend/tests/generators/generator_rewind.phpt
b/Zend/tests/generators/generator_rewind.phpt
index 3224f6a..af885ef 100644
--- a/Zend/tests/generators/generator_rewind.phpt
+++ b/Zend/tests/generators/generator_rewind.phpt
@@ -21,6 +21,14 @@ try {
echo "\n", $e, "\n\n";
}
+$gen = gen();
+foreach ($gen as $v) { }
+try {
+ foreach ($gen as $v) { }
+} catch (Exception $e) {
+ echo "\n", $e, "\n\n";
+}
+
function gen2() {
echo "in generator\n";
@@ -40,4 +48,12 @@ Stack trace:
#0 %s(%d): Generator->rewind()
#1 {main}
+before yield
+after yield
+
+exception 'Exception' with message 'Cannot rewind a generator that was already
run' in %s:%d
+Stack trace:
+#0 %s(%d): unknown()
+#1 {main}
+
in generator
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index 03294f7..0eb17d0 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -500,7 +500,7 @@ void zend_generator_resume(zend_generator *generator TSRMLS_DC) /* {{{ */
static void zend_generator_ensure_initialized(zend_generator *generator TSRMLS_DC) /* {{{ */
{
- if (!generator->value) {
+ if (generator->execute_data && !generator->value) {
zend_generator_resume(generator TSRMLS_CC);
generator->flags |= ZEND_GENERATOR_AT_FIRST_YIELD;
}