Move error handling for GC.latest_gc_info to gc.c

This commit is contained in:
Peter Zhu 2024-10-22 10:43:28 -04:00
parent 8e509380a2
commit c2af84b244
Notes: git 2024-10-23 17:18:29 +00:00
2 changed files with 15 additions and 4 deletions

12
gc.c
View File

@ -3397,7 +3397,17 @@ gc_count(rb_execution_context_t *ec, VALUE self)
VALUE
rb_gc_latest_gc_info(VALUE key)
{
return rb_gc_impl_latest_gc_info(rb_gc_get_objspace(), key);
if (!SYMBOL_P(key) && !RB_TYPE_P(key, T_HASH)) {
rb_raise(rb_eTypeError, "non-hash or symbol given");
}
VALUE val = rb_gc_impl_latest_gc_info(rb_gc_get_objspace(), key);
if (val == Qundef) {
rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key));
}
return val;
}
static VALUE

View File

@ -7291,7 +7291,7 @@ gc_info_decode(rb_objspace_t *objspace, const VALUE hash_or_key, const unsigned
hash = hash_or_key;
}
else {
rb_raise(rb_eTypeError, "non-hash or symbol given");
rb_bug("gc_info_decode: non-hash or symbol given");
}
if (NIL_P(sym_major_by)) {
@ -7377,8 +7377,9 @@ gc_info_decode(rb_objspace_t *objspace, const VALUE hash_or_key, const unsigned
SET(retained_weak_references_count, LONG2FIX(objspace->profile.retained_weak_references_count));
#undef SET
if (!NIL_P(key)) {/* matched key should return above */
rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key));
if (!NIL_P(key)) {
// Matched key should return above
return Qundef;
}
return hash;