com php-src: Fixed calling generators through magic __call(): Zend/tests/generators/generator_trampol ine.phpt Zend/zend_vm_def.h Zend/zend_vm_execut
e.h
| From: | Dmitry Stogov | Date: | Mon, 28 Nov 2016 09:20:19 +0000 |
| Subject: | com php-src: Fixed calling generators through magic __call(): Zend/tests/generators/generator_trampol ine.phpt Zend/zend_vm_def.h Zend/zend_vm_execut e.h |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-96090@lists.php.net to get a copy of this message | ||
Commit: 970f21be97980a18153f13d653f4132cce676158
Author: Dmitry Stogov <dmitry@zend.com> Mon, 28 Nov 2016 12:20:19 +0300
Parents: fe04f5494a0c1ae393ef55642a797c0a8df8d8f2
Branches: PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=970f21be97980a18153f13d653f4132cce676158
Log:
Fixed calling generators through magic __call()
Changed paths:
A Zend/tests/generators/generator_trampoline.phpt
M Zend/zend_vm_def.h
M Zend/zend_vm_execute.h
Diff:
diff --git a/Zend/tests/generators/generator_trampoline.phpt
b/Zend/tests/generators/generator_trampoline.phpt
new file mode 100644
index 0000000..a98dc9e
--- /dev/null
+++ b/Zend/tests/generators/generator_trampoline.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Calling generator through magic __call()
+--FILE--
+<?php
+class A {
+ public function __call($name, $args) {
+ for ($i = 0; $i < 5; $i++) {
+ yield $i;
+ }
+ }
+}
+
+$a = new A();
+foreach ($a->gen() as $n) {
+ var_dump($n);
+}
+$a->gen();
+?>
+--EXPECT--
+int(0)
+int(1)
+int(2)
+int(3)
+int(4)
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 6693ef3..fdce0f9 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -7928,17 +7928,27 @@ ZEND_VM_HANDLER(158, ZEND_CALL_TRAMPOLINE, ANY, ANY)
if (EXPECTED(fbc->type == ZEND_USER_FUNCTION)) {
- ZEND_ASSERT(!(fbc->common.fn_flags & ZEND_ACC_GENERATOR));
-
- call->symbol_table = NULL;
- i_init_func_execute_data(call, &fbc->op_array,
- ret, (fbc->common.fn_flags & ZEND_ACC_STATIC) == 0);
-
- if (EXPECTED(zend_execute_ex == execute_ex)) {
- ZEND_VM_ENTER();
+ if (UNEXPECTED((fbc->common.fn_flags & ZEND_ACC_GENERATOR) != 0)) {
+ if (ret) {
+ zend_generator_create_zval(call, &fbc->op_array, ret);
+ Z_VAR_FLAGS_P(ret) = 0;
+ } else {
+ if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_CLOSURE)) {
+ OBJ_RELEASE((zend_object*)fbc->op_array.prototype);
+ }
+ zend_vm_stack_free_args(call);
+ }
} else {
- ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
- zend_execute_ex(call);
+ call->symbol_table = NULL;
+ i_init_func_execute_data(call, &fbc->op_array,
+ ret, (fbc->common.fn_flags & ZEND_ACC_STATIC) == 0);
+
+ if (EXPECTED(zend_execute_ex == execute_ex)) {
+ ZEND_VM_ENTER();
+ } else {
+ ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
+ zend_execute_ex(call);
+ }
}
} else {
zval retval;
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index 2c90e00..c97525e 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -1737,17 +1737,27 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL
ZEND_CALL_TRAMPOLINE_SPEC_HANDLER(Z
if (EXPECTED(fbc->type == ZEND_USER_FUNCTION)) {
- ZEND_ASSERT(!(fbc->common.fn_flags & ZEND_ACC_GENERATOR));
-
- call->symbol_table = NULL;
- i_init_func_execute_data(call, &fbc->op_array,
- ret, (fbc->common.fn_flags & ZEND_ACC_STATIC) == 0);
-
- if (EXPECTED(zend_execute_ex == execute_ex)) {
- ZEND_VM_ENTER();
+ if (UNEXPECTED((fbc->common.fn_flags & ZEND_ACC_GENERATOR) != 0)) {
+ if (ret) {
+ zend_generator_create_zval(call, &fbc->op_array, ret);
+ Z_VAR_FLAGS_P(ret) = 0;
+ } else {
+ if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_CLOSURE)) {
+ OBJ_RELEASE((zend_object*)fbc->op_array.prototype);
+ }
+ zend_vm_stack_free_args(call);
+ }
} else {
- ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
- zend_execute_ex(call);
+ call->symbol_table = NULL;
+ i_init_func_execute_data(call, &fbc->op_array,
+ ret, (fbc->common.fn_flags & ZEND_ACC_STATIC) == 0);
+
+ if (EXPECTED(zend_execute_ex == execute_ex)) {
+ ZEND_VM_ENTER();
+ } else {
+ ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
+ zend_execute_ex(call);
+ }
}
} else {
zval retval;