summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2024-10-22 10:46:46 -0400
committerPeter Zhu <peter@peterzhu.ca>2024-10-23 13:18:09 -0400
commit9dea0fae25426cc95de50ab50bf9572e603d7100 (patch)
treebd7b602c6706ad1cb835c7316f7c8da552a4a1a8
parentc2af84b244e3ddee4ec8f69bc5a2be5efd179901 (diff)
Make rb_gc_impl_stat return a VALUE instead of size_t
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11932
-rw-r--r--gc.c11
-rw-r--r--gc/default.c6
-rw-r--r--gc/gc_impl.h2
3 files changed, 6 insertions, 13 deletions
diff --git a/gc.c b/gc.c
index c10694d3f6..e2b9598ff0 100644
--- a/gc.c
+++ b/gc.c
@@ -634,7 +634,7 @@ typedef struct gc_function_map {
unsigned long long (*get_total_time)(void *objspace_ptr);
size_t (*gc_count)(void *objspace_ptr);
VALUE (*latest_gc_info)(void *objspace_ptr, VALUE key);
- size_t (*stat)(void *objspace_ptr, VALUE hash_or_sym);
+ VALUE (*stat)(void *objspace_ptr, VALUE hash_or_sym);
size_t (*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);
@@ -3417,14 +3417,7 @@ gc_stat(rb_execution_context_t *ec, VALUE self, VALUE arg) // arg is (nil || has
arg = rb_hash_new();
}
- size_t val = rb_gc_impl_stat(rb_gc_get_objspace(), arg);
-
- if (SYMBOL_P(arg)) {
- return SIZET2NUM(val);
- }
- else {
- return arg;
- }
+ return rb_gc_impl_stat(rb_gc_get_objspace(), arg);
}
size_t
diff --git a/gc/default.c b/gc/default.c
index 2bb3d0512b..9847052d28 100644
--- a/gc/default.c
+++ b/gc/default.c
@@ -7497,7 +7497,7 @@ ns_to_ms(uint64_t ns)
return ns / (1000 * 1000);
}
-size_t
+VALUE
rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
{
rb_objspace_t *objspace = objspace_ptr;
@@ -7517,7 +7517,7 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
#define SET(name, attr) \
if (key == gc_stat_symbols[gc_stat_sym_##name]) \
- return attr; \
+ return SIZET2NUM(attr); \
else if (hash != Qnil) \
rb_hash_aset(hash, gc_stat_symbols[gc_stat_sym_##name], SIZET2NUM(attr));
@@ -7581,7 +7581,7 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
}
#endif
- return 0;
+ return hash;
}
enum gc_stat_heap_sym {
diff --git a/gc/gc_impl.h b/gc/gc_impl.h
index 78b42bb325..66fdea5bab 100644
--- a/gc/gc_impl.h
+++ b/gc/gc_impl.h
@@ -89,7 +89,7 @@ GC_IMPL_FN bool rb_gc_impl_get_measure_total_time(void *objspace_ptr);
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 size_t rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym);
+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);
// Miscellaneous
GC_IMPL_FN size_t rb_gc_impl_obj_flags(void *objspace_ptr, VALUE obj, ID* flags, size_t max);