Don't perform recursive get_gc call

On further consideration, we should be making use of the fact
that zend_object_iterator is also a zend_object here, and let
GC handle the get_gc call on it. Calling get_gc recursively like
this is generally not safe, because there is only one gc_buffer.

This also happens to be much simpler...
This commit is contained in:
Nikita Popov 2021-06-09 11:13:15 +02:00
parent 029d06992e
commit 0643301c75
3 changed files with 2 additions and 25 deletions

View File

@ -1637,12 +1637,6 @@ ZEND_API void zend_get_gc_buffer_grow(zend_get_gc_buffer *gc_buffer) {
gc_buffer->cur = gc_buffer->start + old_capacity;
}
ZEND_API void zend_get_gc_buffer_add_zvals(zend_get_gc_buffer *gc_buffer, zval *zvs, size_t n) {
for (size_t i = 0; i < n; i++) {
zend_get_gc_buffer_add_zval(gc_buffer, &zvs[i]);
}
}
static void zend_get_gc_buffer_release() {
zend_get_gc_buffer *gc_buffer = &EG(get_gc_buffer);
efree(gc_buffer->start);

View File

@ -93,7 +93,6 @@ typedef struct {
ZEND_API zend_get_gc_buffer *zend_get_gc_buffer_create(void);
ZEND_API void zend_get_gc_buffer_grow(zend_get_gc_buffer *gc_buffer);
ZEND_API void zend_get_gc_buffer_add_zvals(zend_get_gc_buffer *gc_buffer, zval *zvs, size_t n);
static zend_always_inline void zend_get_gc_buffer_add_zval(
zend_get_gc_buffer *gc_buffer, zval *zv) {
@ -115,15 +114,6 @@ static zend_always_inline void zend_get_gc_buffer_add_obj(
gc_buffer->cur++;
}
static zend_always_inline void zend_get_gc_buffer_add_ht(
zend_get_gc_buffer *gc_buffer, HashTable *ht) {
if (UNEXPECTED(gc_buffer->cur == gc_buffer->end)) {
zend_get_gc_buffer_grow(gc_buffer);
}
ZVAL_ARR(gc_buffer->cur, ht);
gc_buffer->cur++;
}
static zend_always_inline void zend_get_gc_buffer_use(
zend_get_gc_buffer *gc_buffer, zval **table, int *n) {
*table = gc_buffer->start;

View File

@ -2103,15 +2103,8 @@ static HashTable *spl_dual_it_get_gc(zend_object *obj, zval **table, int *n)
spl_dual_it_object *object = spl_dual_it_from_obj(obj);
zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();
if (object->inner.iterator && object->inner.iterator->funcs->get_gc) {
zval *inner_table;
int inner_n;
HashTable *inner_ht = object->inner.iterator->funcs->get_gc(
object->inner.iterator, &inner_table, &inner_n);
zend_get_gc_buffer_add_zvals(gc_buffer, inner_table, inner_n);
if (inner_ht) {
zend_get_gc_buffer_add_ht(gc_buffer, inner_ht);
}
if (object->inner.iterator) {
zend_get_gc_buffer_add_obj(gc_buffer, &object->inner.iterator->std);
}
zend_get_gc_buffer_add_zval(gc_buffer, &object->current.data);