Commit:    bf82f46ea9028faa3830525d2462effe7d08600d
Author:    Nikita Popov <ni...@php.net>         Sun, 3 Jun 2012 02:16:29 +0200
Parents:   7b3bfa5784cf36647f21a72ceb9741e40927a5b6
Branches:  master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=bf82f46ea9028faa3830525d2462effe7d08600d

Log:
Properly handle yield during method calls

Changed paths:
  A  Zend/tests/generators/yield_during_method_call.phpt
  M  Zend/zend_generators.c


Diff:
diff --git a/Zend/tests/generators/yield_during_method_call.phpt 
b/Zend/tests/generators/yield_during_method_call.phpt
new file mode 100644
index 0000000..da987ab
--- /dev/null
+++ b/Zend/tests/generators/yield_during_method_call.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Yield can be used during a method call
+--FILE--
+<?php
+
+class A {
+    public function b($c) {
+        echo $c, "\n";
+    }
+}
+
+function *gen() {
+    $a = new A;
+    $a->b(yield);
+}
+
+$gen = gen();
+$gen->send('foo');
+
+// test resource cleanup
+$gen = gen();
+$gen->rewind();
+$gen->close();
+
+// test cloning
+$g1 = gen();
+$g1->rewind();
+$g2 = clone $g1;
+$g1->close();
+$g2->send('bar');
+
+?>
+--EXPECT--
+foo
+bar
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index df204fa..a3277e6 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -41,6 +41,10 @@ void zend_generator_close(zend_generator *generator, 
zend_bool finished_executio
                        zval_ptr_dtor(&execute_data->current_this);
                }
 
+               if (execute_data->object) {
+                       zval_ptr_dtor(&execute_data->object);
+               }
+
                /* If the generator is closed before it can finish execution 
(reach
                 * a return statement) we have to free loop variables manually, 
as
                 * we don't know whether the SWITCH_FREE / FREE opcodes have 
run */
@@ -228,6 +232,10 @@ static void zend_generator_clone_storage(zend_generator 
*orig, zend_generator **
                        );
                        Z_ADDREF_P(clone->send_target->var.ptr);
                }
+
+               if (execute_data->object) {
+                       Z_ADDREF_P(execute_data->object);
+               }
        }
 
        /* The value and key are known not to be references, so simply add refs 
*/


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to