com php-src: Fix leak when yielding array as key: Zend/tests/ge nerators/yield_array_key.phpt Zend/zend_vm_def.h Zend/zend_vm_execute.h
| From: | Nikita Popov | Date: | Sat, 01 Sep 2012 18:31:40 +0000 |
| Subject: | com php-src: Fix leak when yielding array as key: Zend/tests/ge nerators/yield_array_key.phpt Zend/zend_vm_def.h Zend/zend_vm_execute.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-70092@lists.php.net to get a copy of this message | ||
Commit: dffffdeb3df0b05e79213e52667f3061dc9d635e
Author: Nikita Popov <nikic@php.net> Sat, 1 Sep 2012 20:31:40 +0200
Parents: 1b5b839312b2ec1f6d38f826a592edf83188fc1e
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dffffdeb3df0b05e79213e52667f3061dc9d635e
Log:
Fix leak when yielding array as key
The code was copy-pasted and I forgot to change OP1 to OP2 in that one
place.
Changed paths:
A Zend/tests/generators/yield_array_key.phpt
M Zend/zend_vm_def.h
M Zend/zend_vm_execute.h
Diff:
diff --git a/Zend/tests/generators/yield_array_key.phpt b/Zend/tests/generators/yield_array_key.phpt
new file mode 100644
index 0000000..5afba00
--- /dev/null
+++ b/Zend/tests/generators/yield_array_key.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Array keys can be yielded from generators
+--FILE--
+<?php
+
+function gen() {
+ yield [] => 1;
+}
+
+$gen = gen();
+var_dump($gen->key());
+var_dump($gen->current());
+
+?>
+--EXPECT--
+array(0) {
+}
+int(1)
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index ffd81b0..f683ff2 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -5511,7 +5511,7 @@ ZEND_VM_HANDLER(160, ZEND_YIELD, CONST|TMP|VAR|CV|UNUSED,
CONST|TMP|VAR|CV|UNUSE
INIT_PZVAL_COPY(copy, key);
/* Temporary variables don't need ctor copying */
- if (!IS_OP1_TMP_FREE()) {
+ if (!IS_OP2_TMP_FREE()) {
zval_copy_ctor(copy);
}
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index b0e05b1..f8a8905 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -5005,7 +5005,7 @@ static int ZEND_FASTCALL
ZEND_YIELD_SPEC_CONST_TMP_HANDLER(ZEND_OPCODE_HANDLER_
INIT_PZVAL_COPY(copy, key);
/* Temporary variables don't need ctor copying */
- if (!0) {
+ if (!1) {
zval_copy_ctor(copy);
}
@@ -9553,7 +9553,7 @@ static int ZEND_FASTCALL
ZEND_YIELD_SPEC_TMP_CONST_HANDLER(ZEND_OPCODE_HANDLER_
INIT_PZVAL_COPY(copy, key);
/* Temporary variables don't need ctor copying */
- if (!1) {
+ if (!0) {
zval_copy_ctor(copy);
}
@@ -11266,7 +11266,7 @@ static int ZEND_FASTCALL
ZEND_YIELD_SPEC_TMP_VAR_HANDLER(ZEND_OPCODE_HANDLER_AR
INIT_PZVAL_COPY(copy, key);
/* Temporary variables don't need ctor copying */
- if (!1) {
+ if (!0) {
zval_copy_ctor(copy);
}
@@ -11846,7 +11846,7 @@ static int ZEND_FASTCALL
ZEND_YIELD_SPEC_TMP_UNUSED_HANDLER(ZEND_OPCODE_HANDLER
INIT_PZVAL_COPY(copy, key);
/* Temporary variables don't need ctor copying */
- if (!1) {
+ if (!0) {
zval_copy_ctor(copy);
}
@@ -12537,7 +12537,7 @@ static int ZEND_FASTCALL
ZEND_YIELD_SPEC_TMP_CV_HANDLER(ZEND_OPCODE_HANDLER_ARG
INIT_PZVAL_COPY(copy, key);
/* Temporary variables don't need ctor copying */
- if (!1) {
+ if (!0) {
zval_copy_ctor(copy);
}
@@ -18543,7 +18543,7 @@ static int ZEND_FASTCALL
ZEND_YIELD_SPEC_VAR_TMP_HANDLER(ZEND_OPCODE_HANDLER_AR
INIT_PZVAL_COPY(copy, key);
/* Temporary variables don't need ctor copying */
- if (!0) {
+ if (!1) {
zval_copy_ctor(copy);
}
@@ -27081,7 +27081,7 @@ static int ZEND_FASTCALL
ZEND_YIELD_SPEC_UNUSED_TMP_HANDLER(ZEND_OPCODE_HANDLER
INIT_PZVAL_COPY(copy, key);
/* Temporary variables don't need ctor copying */
- if (!0) {
+ if (!1) {
zval_copy_ctor(copy);
}
@@ -35600,7 +35600,7 @@ static int ZEND_FASTCALL
ZEND_YIELD_SPEC_CV_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG
INIT_PZVAL_COPY(copy, key);
/* Temporary variables don't need ctor copying */
- if (!0) {
+ if (!1) {
zval_copy_ctor(copy);
}