From d3aaca97850a1398920f629f8339b56e41b972ed Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 22 Oct 2024 10:56:52 -0400 Subject: [PATCH] Make rb_gc_impl_stat_heap return a VALUE instead of size_t --- gc.c | 11 ++--------- gc/default.c | 10 +++++----- gc/gc_impl.h | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/gc.c b/gc.c index 29b61a0698..435e4d1bf4 100644 --- a/gc.c +++ b/gc.c @@ -635,7 +635,7 @@ typedef struct gc_function_map { size_t (*gc_count)(void *objspace_ptr); VALUE (*latest_gc_info)(void *objspace_ptr, VALUE key); VALUE (*stat)(void *objspace_ptr, VALUE hash_or_sym); - size_t (*stat_heap)(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym); + VALUE (*stat_heap)(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym); // Miscellaneous size_t (*obj_flags)(void *objspace_ptr, VALUE obj, ID* flags, size_t max); bool (*pointer_to_heap_p)(void *objspace_ptr, const void *ptr); @@ -3461,14 +3461,7 @@ gc_stat_heap(rb_execution_context_t *ec, VALUE self, VALUE heap_name, VALUE arg) arg = rb_hash_new(); } - size_t val = rb_gc_impl_stat_heap(rb_gc_get_objspace(), heap_name, arg); - - if (SYMBOL_P(arg)) { - return SIZET2NUM(val); - } - else { - return arg; - } + return rb_gc_impl_stat_heap(rb_gc_get_objspace(), heap_name, arg); } static VALUE diff --git a/gc/default.c b/gc/default.c index aa1e3dd105..6b555fbf08 100644 --- a/gc/default.c +++ b/gc/default.c @@ -7616,12 +7616,12 @@ setup_gc_stat_heap_symbols(void) } } -static size_t +static VALUE stat_one_heap(rb_heap_t *heap, VALUE hash, VALUE key) { #define SET(name, attr) \ if (key == gc_stat_heap_symbols[gc_stat_heap_sym_##name]) \ - return attr; \ + return SIZET2NUM(attr); \ else if (hash != Qnil) \ rb_hash_aset(hash, gc_stat_heap_symbols[gc_stat_heap_sym_##name], SIZET2NUM(attr)); @@ -7639,10 +7639,10 @@ stat_one_heap(rb_heap_t *heap, VALUE hash, VALUE key) rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key)); } - return 0; + return hash; } -size_t +VALUE rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym) { rb_objspace_t *objspace = objspace_ptr; @@ -7685,7 +7685,7 @@ rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym) rb_raise(rb_eTypeError, "heap_name must be nil or an Integer"); } - return 0; + return hash_or_sym; } /* I could include internal.h for this, but doing so undefines some Array macros diff --git a/gc/gc_impl.h b/gc/gc_impl.h index 66fdea5bab..d7ad82d5e0 100644 --- a/gc/gc_impl.h +++ b/gc/gc_impl.h @@ -90,7 +90,7 @@ GC_IMPL_FN unsigned long long rb_gc_impl_get_total_time(void *objspace_ptr); GC_IMPL_FN size_t rb_gc_impl_gc_count(void *objspace_ptr); GC_IMPL_FN VALUE rb_gc_impl_latest_gc_info(void *objspace_ptr, VALUE key); GC_IMPL_FN VALUE rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym); -GC_IMPL_FN size_t rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym); +GC_IMPL_FN VALUE rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym); // Miscellaneous GC_IMPL_FN size_t rb_gc_impl_obj_flags(void *objspace_ptr, VALUE obj, ID* flags, size_t max); GC_IMPL_FN bool rb_gc_impl_pointer_to_heap_p(void *objspace_ptr, const void *ptr);