Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Properly handle yield during method calls

  • Loading branch information...
commit bf82f46ea9028faa3830525d2462effe7d08600d 1 parent 7b3bfa5
@nikic nikic authored
View
35 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
View
8 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 */
Please sign in to comment.
Something went wrong with that request. Please try again.