]> granicus.if.org Git - php/commitdiff
Crude generator GC for value/key/retval
authorNikita Popov <nikic@php.net>
Wed, 10 Feb 2016 18:03:02 +0000 (19:03 +0100)
committerNikita Popov <nikic@php.net>
Wed, 10 Feb 2016 18:03:02 +0000 (19:03 +0100)
These values remain live after the generator has been closed, so
they are particularly susceptible to leaking cycles.

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

diff --git a/Zend/tests/bug69989_1.phpt b/Zend/tests/bug69989_1.phpt
new file mode 100644 (file)
index 0000000..816c554
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Bug #69989: Cycle collection for yielded values
+--FILE--
+<?php
+
+function gen() {
+    yield yield;
+}
+$gen = gen();
+$gen->send($gen);
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
index 4861e459195269642c7c8093c7ba910d09703aa3..c572a9cc353c12761a84bf7e56f4cc9f0c9bd3de 100644 (file)
@@ -193,6 +193,15 @@ static void zend_generator_free_storage(zend_object *object) /* {{{ */
 }
 /* }}} */
 
+static HashTable *zend_generator_get_gc(zval *object, zval **table, int *n) /* {{{ */
+{
+       zend_generator *generator = (zend_generator*) Z_OBJ_P(object);
+       *table = &generator->value;
+       *n = 3;
+       return NULL;
+}
+/* }}} */
+
 static zend_object *zend_generator_create(zend_class_entry *class_type) /* {{{ */
 {
        zend_generator *generator;
@@ -1128,6 +1137,7 @@ void zend_register_generator_ce(void) /* {{{ */
        memcpy(&zend_generator_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        zend_generator_handlers.free_obj = zend_generator_free_storage;
        zend_generator_handlers.dtor_obj = zend_generator_dtor_storage;
+       zend_generator_handlers.get_gc = zend_generator_get_gc;
        zend_generator_handlers.clone_obj = NULL;
        zend_generator_handlers.get_constructor = zend_generator_get_constructor;