From f43dac0df29c137ae966362f7faf26084468a0fb Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Sun, 24 Sep 2023 09:07:52 -0400 Subject: Add rb_hash_free for the GC to use --- gc.c | 7 +------ hash.c | 8 ++++++++ internal/hash.h | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gc.c b/gc.c index c99f94a129..95d4cf8cd1 100644 --- a/gc.c +++ b/gc.c @@ -3539,12 +3539,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj) } #endif - if (RHASH_ST_TABLE_P(obj)) { - st_table *tab = RHASH_ST_TABLE(obj); - - free(tab->bins); - free(tab->entries); - } + rb_hash_free(obj); break; case T_REGEXP: if (RANY(obj)->as.regexp.ptr) { diff --git a/hash.c b/hash.c index 8e0295c38e..8ac8664982 100644 --- a/hash.c +++ b/hash.c @@ -1178,6 +1178,14 @@ hash_st_free_and_clear_table(VALUE hash) RHASH_ST_CLEAR(hash); } +void +rb_hash_free(VALUE hash) +{ + if (RHASH_ST_TABLE_P(hash)) { + hash_st_free(hash); + } +} + typedef int st_foreach_func(st_data_t, st_data_t, st_data_t); struct foreach_safe_arg { diff --git a/internal/hash.h b/internal/hash.h index d1848e5408..fe859cb716 100644 --- a/internal/hash.h +++ b/internal/hash.h @@ -87,6 +87,7 @@ int rb_hash_stlike_delete(VALUE hash, st_data_t *pkey, st_data_t *pval); int rb_hash_stlike_foreach_with_replace(VALUE hash, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg); int rb_hash_stlike_update(VALUE hash, st_data_t key, st_update_callback_func *func, st_data_t arg); VALUE rb_ident_hash_new_with_size(st_index_t size); +void rb_hash_free(VALUE hash); static inline unsigned RHASH_AR_TABLE_SIZE_RAW(VALUE h); static inline VALUE RHASH_IFNONE(VALUE h); -- cgit v1.2.3