com php-src: Do not add a ref to EX(object) on generator clone: Zend/tests/generators/clone_after_object_call.phpt Ze nd/zend_generators.c
| From: | Nikita Popov | Date: | Thu, 20 Dec 2012 19:33:18 +0000 |
| Subject: | com php-src: Do not add a ref to EX(object) on generator clone: Zend/tests/generators/clone_after_object_call.phpt Ze nd/zend_generators.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-70780@lists.php.net to get a copy of this message | ||
Commit: 3e78c6ad25fdf07259bfaaa3e2e33fb0914e5e61
Author: Nikita Popov <nikic@php.net> Thu, 20 Dec 2012 20:33:18 +0100
Parents: d5fe89670ee76baeb50664f5460991892ee77d8c
Branches: PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3e78c6ad25fdf07259bfaaa3e2e33fb0914e5e61
Log:
Do not add a ref to EX(object) on generator clone
If a ref has to be added it will be already added while walking the call
slots.
Changed paths:
A Zend/tests/generators/clone_after_object_call.phpt
M Zend/zend_generators.c
Diff:
diff --git a/Zend/tests/generators/clone_after_object_call.phpt
b/Zend/tests/generators/clone_after_object_call.phpt
new file mode 100644
index 0000000..0a42426
--- /dev/null
+++ b/Zend/tests/generators/clone_after_object_call.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Cloning a generator after an object method was called
+--FILE--
+<?php
+
+class A { public function b() { } }
+
+function gen() {
+ $a = new A;
+ $a->b();
+ yield;
+}
+
+$g1 = gen();
+$g1->rewind();
+$g2 = clone $g1;
+
+echo "Done";
+--EXPECT--
+Done
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index d4254e0..a191741 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -223,6 +223,7 @@ static void zend_generator_clone_storage(zend_generator *orig, zend_generator **
/* copy */
clone->execute_data->opline = execute_data->opline;
clone->execute_data->function_state = execute_data->function_state;
+ clone->execute_data->object = execute_data->object;
clone->execute_data->current_scope = execute_data->current_scope;
clone->execute_data->current_called_scope = execute_data->current_called_scope;
clone->execute_data->fast_ret = execute_data->fast_ret;
@@ -326,11 +327,6 @@ static void zend_generator_clone_storage(zend_generator *orig, zend_generator
**
clone->execute_data->current_this = execute_data->current_this;
Z_ADDREF_P(execute_data->current_this);
}
-
- if (execute_data->object) {
- clone->execute_data->object = execute_data->object;
- Z_ADDREF_P(execute_data->object);
- }
}
/* The value and key are known not to be references, so simply add refs */