com php-src: Fix zend_vm_call_opcode_handler (e.g . Generators throwing exceptions) with IP/FP re gisters: Zend/zend_vm_execute.h Zend/zend_vm_ge
n.php sapi/phpdbg/tests/generator_run.phpt
| From: | Bob Weinand | Date: | Tue, 25 Aug 2015 23:25:25 +0000 |
| Subject: | com php-src: Fix zend_vm_call_opcode_handler (e.g . Generators throwing exceptions) with IP/FP re gisters: Zend/zend_vm_execute.h Zend/zend_vm_ge n.php sapi/phpdbg/tests/generator_run.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-88752@lists.php.net to get a copy of this message | ||
Commit: c1e9bd27fe59b4f860a616a4e04fdb823a1dbff7
Author: Bob Weinand <bobwei9@hotmail.com> Wed, 26 Aug 2015 00:25:25 +0100
Parents: 9d31b297057a46b8c3cbef137b615e2d8d3d3783
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c1e9bd27fe59b4f860a616a4e04fdb823a1dbff7
Log:
Fix zend_vm_call_opcode_handler (e.g. Generators throwing exceptions) with IP/FP registers
Changed paths:
M Zend/zend_vm_execute.h
M Zend/zend_vm_gen.php
A sapi/phpdbg/tests/generator_run.phpt
Diff:
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index fef3e96..f85d6c0 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -49636,11 +49636,16 @@ ZEND_API int zend_vm_call_opcode_handler(zend_execute_data* ex)
LOAD_OPLINE();
#if defined(ZEND_VM_FP_GLOBAL_REG) && defined(ZEND_VM_IP_GLOBAL_REG)
((opcode_handler_t)OPLINE->handler)(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
- ret = opline? ((execute_data != ex)? (int)(execute_data->prev_execute_data != ex) + 1 : 0) :
-1;
+ if (EXPECTED(opline)) {
+ ret = execute_data != ex ? (int)(execute_data->prev_execute_data != ex) + 1 : 0;
+ SAVE_OPLINE();
+ } else {
+ ret = -1;
+ }
#else
ret = ((opcode_handler_t)OPLINE->handler)(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
-#endif
SAVE_OPLINE();
+#endif
#ifdef ZEND_VM_FP_GLOBAL_REG
execute_data = orig_execute_data;
#endif
diff --git a/Zend/zend_vm_gen.php b/Zend/zend_vm_gen.php
index 3a80705..40c9f24 100644
--- a/Zend/zend_vm_gen.php
+++ b/Zend/zend_vm_gen.php
@@ -1618,11 +1618,16 @@ function gen_vm($def, $skel) {
out($f, "\tLOAD_OPLINE();\n");
out($f,"#if defined(ZEND_VM_FP_GLOBAL_REG) &&
defined(ZEND_VM_IP_GLOBAL_REG)\n");
out($f,
"\t((opcode_handler_t)OPLINE->handler)(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);\n");
- out($f, "\tret = opline? ((execute_data != ex)? (int)(execute_data->prev_execute_data !=
ex) + 1 : 0) : -1;\n");
+ out($f, "\tif (EXPECTED(opline)) {\n");
+ out($f, "\t\tret = execute_data != ex ? (int)(execute_data->prev_execute_data != ex) + 1
: 0;\n");
+ out($f, "\t\tSAVE_OPLINE();\n");
+ out($f, "\t} else {\n");
+ out($f, "\t\tret = -1;\n");
+ out($f, "\t}\n");
out($f, "#else\n");
out($f, "\tret =
((opcode_handler_t)OPLINE->handler)(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);\n");
- out($f, "#endif\n");
out($f, "\tSAVE_OPLINE();\n");
+ out($f, "#endif\n");
out($f, "#ifdef ZEND_VM_FP_GLOBAL_REG\n");
out($f, "\texecute_data = orig_execute_data;\n");
out($f, "#endif\n");
diff --git a/sapi/phpdbg/tests/generator_run.phpt b/sapi/phpdbg/tests/generator_run.phpt
new file mode 100644
index 0000000..798d770
--- /dev/null
+++ b/sapi/phpdbg/tests/generator_run.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Ensure proper saving of EX(opline)
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> caught Generator exception
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+function gen() {
+ try {
+ throw new Exception;
+ } catch(Exception $e) {
+ yield "caught Generator exception";
+ }
+}
+
+foreach (gen() as $v) {
+ print $v;
+}