com php-src: Fix dangling send target when using yield from: Zend/tests/generators/dangling_send_target.phpt Zend/ze nd_generators.c
Zend/zend_vm_def.h Zend/zend_vm _execute.h

From: Date: Thu, 11 Feb 2016 15:25:16 +0000
Subject: com php-src: Fix dangling send target when using yield from: Zend/tests/generators/dangling_send_target.phpt Zend/ze nd_generators.c
Zend/zend_vm_def.h Zend/zend_vm _execute.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-90988@lists.php.net to get a copy of this message
Commit: 1322672c0b70cf3a8f3fa64f7d6c4b52338f8b81 Author: Nikita Popov <nikic@php.net> Thu, 11 Feb 2016 16:22:42 +0100 Parents: 95a47ab556a2014b6aad193dd881cc0f35f0e9c8 Branches: PHP-7.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1322672c0b70cf3a8f3fa64f7d6c4b52338f8b81 Log: Fix dangling send target when using yield from Also drop some unnecessary TRY_DELREFs -- leftovers from the days when null was refcounted. Changed paths: A Zend/tests/generators/dangling_send_target.phpt M Zend/zend_generators.c M Zend/zend_vm_def.h M Zend/zend_vm_execute.h Diff: diff --git a/Zend/tests/generators/dangling_send_target.phpt b/Zend/tests/generators/dangling_send_target.phpt new file mode 100644 index 0000000..c62c24a --- /dev/null +++ b/Zend/tests/generators/dangling_send_target.phpt @@ -0,0 +1,22 @@ +--TEST-- +Yield from does not leave a dangling send target +--FILE-- +<?php +function gen1() { + yield from [yield]; +} + +$gen = gen1(); +$gen->send(new stdClass); + +function gen2() { + $x = yield; + yield from [1, 2, 3]; +} +$gen = gen2(); +$gen->send(new stdClass); +$gen->send(new stdClass); +?> +===DONE=== +--EXPECT-- +===DONE=== diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index c572a9c..f8087fc 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -35,11 +35,6 @@ static void zend_generator_cleanup_unfinished_execution(zend_generator *generato { zend_execute_data *execute_data = generator->execute_data; - if (generator->send_target) { - Z_TRY_DELREF_P(generator->send_target); - generator->send_target = NULL; - } - if (execute_data->opline != execute_data->func->op_array.opcodes) { /* -1 required because we want the last run opcode, not the next to-be-run one. */ uint32_t op_num = execute_data->opline - execute_data->func->op_array.opcodes - 1; @@ -882,7 +877,6 @@ ZEND_METHOD(Generator, send) root = zend_generator_get_current(generator); /* Put sent value in the target VAR slot, if it is used */ if (root->send_target) { - Z_TRY_DELREF_P(root->send_target); ZVAL_COPY(root->send_target, value); } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 11cd241..655952b 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -7503,6 +7503,9 @@ ZEND_VM_HANDLER(142, ZEND_YIELD_FROM, CONST|TMP|VAR|CV, ANY) ZVAL_NULL(EX_VAR(opline->result.var)); } + /* This generator has no send target (though the generator we delegate to might have one) */ + generator->send_target = NULL; + /* We increment to the next op, so we are at the correct position when the * generator is resumed. */ ZEND_VM_INC_OPCODE(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 6f44069..cd17b782 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -4183,6 +4183,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_CONST_HANDLER( ZVAL_NULL(EX_VAR(opline->result.var)); } + /* This generator has no send target (though the generator we delegate to might have one) */ + generator->send_target = NULL; + /* We increment to the next op, so we are at the correct position when the * generator is resumed. */ ZEND_VM_INC_OPCODE(); @@ -12517,6 +12520,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_TMP_HANDLER(ZE ZVAL_NULL(EX_VAR(opline->result.var)); } + /* This generator has no send target (though the generator we delegate to might have one) */ + generator->send_target = NULL; + /* We increment to the next op, so we are at the correct position when the * generator is resumed.. */ ZEND_VM_INC_OPCODE(); @@ -16335,6 +16341,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_VAR_HANDLER(ZE ZVAL_NULL(EX_VAR(opline->result.var)); } + /* This generator has no send target (though the generator we delegate to might have one) */ + generator->send_target = NULL; + /* We increment to the next op, so we are at the correct position when the * generator is resumed. */ ZEND_VM_INC_OPCODE(); @@ -29665,6 +29674,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_CV_HANDLER(ZEN ZVAL_NULL(EX_VAR(opline->result.var)); } + /* This generator has no send target (though the generator we delegate to might have one) */ + generator->send_target = NULL; + /* We increment to the next op, so we are at the correct position when the * generator is resumed. */ ZEND_VM_INC_OPCODE();

« previous php.cvs (#90988) next »