]> granicus.if.org Git - php/commitdiff
Support GC for AppendIterator
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 1 Oct 2020 14:18:23 +0000 (16:18 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 1 Oct 2020 14:18:23 +0000 (16:18 +0200)
This also requires adding GC support for ArrayIterator internal
iterators.

ext/spl/spl_array.c
ext/spl/spl_iterators.c
ext/spl/tests/bug65387.phpt

index fb23939ca24c88f4960027793db36b5a483dd8eb..75668e2f0fc9ab9723c61c76d6f8f92df4ef6943 100644 (file)
@@ -1079,6 +1079,13 @@ static void spl_array_it_rewind(zend_object_iterator *iter) /* {{{ */
 }
 /* }}} */
 
+static HashTable *spl_array_it_get_gc(zend_object_iterator *iter, zval **table, int *n)
+{
+       *n = 1;
+       *table = &iter->data;
+       return NULL;
+}
+
 /* {{{ spl_array_set_array */
 static void spl_array_set_array(zval *object, spl_array_object *intern, zval *array, zend_long ar_flags, int just_array) {
        if (Z_TYPE_P(array) != IS_OBJECT && Z_TYPE_P(array) != IS_ARRAY) {
@@ -1135,7 +1142,7 @@ static const zend_object_iterator_funcs spl_array_it_funcs = {
        spl_array_it_move_forward,
        spl_array_it_rewind,
        NULL,
-       NULL, /* get_gc */
+       spl_array_it_get_gc,
 };
 
 zend_object_iterator *spl_array_get_iterator(zend_class_entry *ce, zval *object, int by_ref) /* {{{ */
index c73134e9ae06e0da0930ed96e844df02e38bb8d3..40538cda8eec954b4cc8c3576320035122413e44 100644 (file)
@@ -2140,11 +2140,10 @@ static HashTable *spl_dual_it_get_gc(zend_object *obj, zval **table, int *n)
                        /* Nothing to do */
                        break;
                case DIT_AppendIterator:
-                       // TODO
-                       /*zend_get_gc_buffer_add_obj(gc_buffer, &object->u.append.iterator->std);
+                       zend_get_gc_buffer_add_obj(gc_buffer, &object->u.append.iterator->std);
                        if (Z_TYPE(object->u.append.zarrayit) != IS_UNDEF) {
                                zend_get_gc_buffer_add_zval(gc_buffer, &object->u.append.zarrayit);
-                       }*/
+                       }
                        break;
                case DIT_CachingIterator:
                case DIT_RecursiveCachingIterator:
index 75678254bdfa194f15fc471f4b4ae141d34a123b..a5b028954ccea4f747c9ea767627817bb55af766 100644 (file)
@@ -41,12 +41,10 @@ $it2[] = $it2;
 $it2->next();
 
 // Append
-/* TODO
 $it = new ArrayIterator();
 $it2 = new AppendIterator();
 $it[] = $it2;
 $it2->append($it);
- */
 
 ?>
 ===DONE===