com php-src: Fix bug #68775: Zend/tests/bug68775.phpt Zend/zend_generators.c
| From: | Nikita Popov | Date: | Fri, 09 Jan 2015 16:59:41 +0000 |
| Subject: | com php-src: Fix bug #68775: Zend/tests/bug68775.phpt Zend/zend_generators.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-84048@lists.php.net to get a copy of this message | ||
Commit: 41a249fef602b8cbfdc70fc8179e48cc1387b821
Author: Nikita Popov <nikic@php.net> Fri, 9 Jan 2015 17:58:41 +0100
Parents: 32f761d7f856d13ca17814899f7317614a6c4d9d
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=41a249fef602b8cbfdc70fc8179e48cc1387b821
Log:
Fix bug #68775
Bugs:
https://bugs.php.net/68775
Changed paths:
A Zend/tests/bug68775.phpt
M Zend/zend_generators.c
Diff:
diff --git a/Zend/tests/bug68775.phpt b/Zend/tests/bug68775.phpt
new file mode 100644
index 0000000..ce0eaed
--- /dev/null
+++ b/Zend/tests/bug68775.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Bug #68775: yield in a function argument crashes or loops indefinitely
+--FILE--
+<?php
+
+function a($x) {
+ var_dump($x);
+}
+
+function gen() {
+ a(yield);
+}
+
+$g = gen();
+$g->send(1);
+
+?>
+--EXPECT--
+int(1)
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index 17bd4a3..ae46555 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -303,8 +303,8 @@ ZEND_API void zend_generator_resume(zend_generator *generator) /* {{{ */
zend_execute_data *original_execute_data = EG(current_execute_data);
zend_class_entry *original_scope = EG(scope);
zend_vm_stack original_stack = EG(vm_stack);
-
original_stack->top = EG(vm_stack_top);
+
/* Set executor globals */
EG(current_execute_data) = generator->execute_data;
EG(scope) = generator->execute_data->func->common.scope;
@@ -314,8 +314,7 @@ ZEND_API void zend_generator_resume(zend_generator *generator) /* {{{ */
/* We want the backtrace to look as if the generator function was
* called from whatever method we are current running (e.g. next()).
- * So we have to link generator call frame with caller call frames */
-
+ * So we have to link generator call frame with caller call frame. */
generator->execute_data->prev_execute_data = original_execute_data;
/* Resume execution */
@@ -329,6 +328,7 @@ ZEND_API void zend_generator_resume(zend_generator *generator) /* {{{ */
}
/* Restore executor globals */
+ generator->stack->top = EG(vm_stack_top);
EG(current_execute_data) = original_execute_data;
EG(scope) = original_scope;
EG(vm_stack_top) = original_stack->top;