summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Zend/zend_vm_execute.h9
-rw-r--r--Zend/zend_vm_gen.php9
-rw-r--r--sapi/phpdbg/tests/generator_run.phpt24
3 files changed, 38 insertions, 4 deletions
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index fef3e96bc7..f85d6c0a2c 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 3a80705b6a..40c9f24f53 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 0000000000..798d77051e
--- /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;
+}