summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2017-07-22 11:14:54 +0200
committerBob Weinand <bobwei9@hotmail.com>2017-07-22 11:14:54 +0200
commit134e713be2e93fd4a6c7504992448667d4e668d0 (patch)
tree0354600bbbc685e4ca075f33b9abc6a29fc72e78 /Zend
parent4cb1151fff357273d82357492ceaa1033de9608e (diff)
parentbad5d0d6c56e078502b21ebdbf829b7a1c9b3bd3 (diff)
downloadphp-git-134e713be2e93fd4a6c7504992448667d4e668d0.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
Diffstat (limited to 'Zend')
-rw-r--r--Zend/tests/generators/bug74954.phpt45
-rw-r--r--Zend/zend_generators.c6
2 files changed, 47 insertions, 4 deletions
diff --git a/Zend/tests/generators/bug74954.phpt b/Zend/tests/generators/bug74954.phpt
new file mode 100644
index 0000000000..58a61af573
--- /dev/null
+++ b/Zend/tests/generators/bug74954.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Bug #74954 (crash after update of generator yielding from finished generator)
+--FILE--
+<?php
+
+function from() {
+ yield 1;
+ throw new Exception();
+}
+
+function gen($gen) {
+ try {
+ var_dump(yield from $gen);
+ } catch (Exception $e) { print "Caught exception!\n$e\n"; }
+}
+
+$gen = from();
+$gens[] = gen($gen);
+$gens[] = gen($gen);
+
+foreach ($gens as $g) {
+ $g->current();
+}
+
+do {
+ foreach ($gens as $i => $g) {
+ $g->next();
+ }
+} while($gens[0]->valid());
+
+?>
+--EXPECTF--
+Caught exception!
+Exception in %s:%d
+Stack trace:
+#0 %s(%d): from()
+#1 [internal function]: gen(Object(Generator))
+#2 %s(%d): Generator->next()
+#3 {main}
+Caught exception!
+ClosedGeneratorException: Generator yielded from aborted, no return value available in %s:%d
+Stack trace:
+#0 [internal function]: gen(Object(Generator))
+#1 %s(%d): Generator->next()
+#2 {main}
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index 99145ada71..20cb996bb8 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -757,15 +757,13 @@ failure:
ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */
{
- zend_generator *generator;
+ zend_generator *generator = zend_generator_get_current(orig_generator);
/* The generator is already closed, thus can't resume */
- if (UNEXPECTED(!orig_generator->execute_data)) {
+ if (UNEXPECTED(!generator->execute_data)) {
return;
}
- generator = zend_generator_get_current(orig_generator);
-
try_again:
if (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING) {
zend_throw_error(NULL, "Cannot resume an already running generator");