From 7116b0a7f1398f18346ad6f9ba805e3877d45944 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 8 May 2025 17:38:39 +0200 Subject: [PATCH] Extract `rb_shape_free_all` --- shape.c | 15 +++++++++++++++ shape.h | 1 + vm.c | 11 +---------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/shape.c b/shape.c index 16eb5b50f4..ab32533a9d 100644 --- a/shape.c +++ b/shape.c @@ -1431,6 +1431,21 @@ Init_default_shapes(void) get_next_shape_internal(shape, id_frozen, SHAPE_FROZEN, &dont_care, true); } +void +rb_shape_free_all(void) +{ + rb_shape_t *cursor = rb_shape_get_root_shape(); + rb_shape_t *end = rb_shape_get_shape_by_id(GET_SHAPE_TREE()->next_shape_id); + while (cursor < end) { + if (cursor->edges && !SINGLE_CHILD_P(cursor->edges)) { + rb_id_table_free(cursor->edges); + } + cursor++; + } + + xfree(GET_SHAPE_TREE()); +} + void Init_shape(void) { diff --git a/shape.h b/shape.h index 182e5b198f..dd52e20543 100644 --- a/shape.h +++ b/shape.h @@ -175,6 +175,7 @@ rb_shape_t *rb_shape_get_next_no_warnings(rb_shape_t *shape, VALUE obj, ID id); rb_shape_t *rb_shape_object_id_shape(VALUE obj); bool rb_shape_has_object_id(rb_shape_t *shape); attr_index_t rb_shape_object_id_index(rb_shape_t *shape); +void rb_shape_free_all(void); rb_shape_t *rb_shape_rebuild_shape(rb_shape_t *initial_shape, rb_shape_t *dest_shape); diff --git a/vm.c b/vm.c index 7425cc6b8b..a01e2c7060 100644 --- a/vm.c +++ b/vm.c @@ -3115,16 +3115,7 @@ ruby_vm_destruct(rb_vm_t *vm) rb_id_table_free(RCLASS(rb_mRubyVMFrozenCore)->m_tbl); - rb_shape_t *cursor = rb_shape_get_root_shape(); - rb_shape_t *end = rb_shape_get_shape_by_id(GET_SHAPE_TREE()->next_shape_id); - while (cursor < end) { - // 0x1 == SINGLE_CHILD_P - if (cursor->edges && !(((uintptr_t)cursor->edges) & 0x1)) - rb_id_table_free(cursor->edges); - cursor += 1; - } - - xfree(GET_SHAPE_TREE()); + rb_shape_free_all(); st_free_table(vm->static_ext_inits);