]> granicus.if.org Git - php/commitdiff
Do not add a ref to EX(object) on generator clone
authorNikita Popov <nikic@php.net>
Thu, 20 Dec 2012 19:33:18 +0000 (20:33 +0100)
committerNikita Popov <nikic@php.net>
Thu, 20 Dec 2012 19:33:18 +0000 (20:33 +0100)
If a ref has to be added it will be already added while walking the call
slots.

Zend/tests/generators/clone_after_object_call.phpt [new file with mode: 0644]
Zend/zend_generators.c

diff --git a/Zend/tests/generators/clone_after_object_call.phpt b/Zend/tests/generators/clone_after_object_call.phpt
new file mode 100644 (file)
index 0000000..0a42426
--- /dev/null
@@ -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
index d4254e090dd8a2dc76960df81c08bfbe44854264..a1917416ef9d92856f84ae3c8640a9b1503dc213 100644 (file)
@@ -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 */