diff --git a/gc.c b/gc.c index e67d1c0b8e..c10694d3f6 100644 --- a/gc.c +++ b/gc.c @@ -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 diff --git a/gc/default.c b/gc/default.c index 50ad291081..2bb3d0512b 100644 --- a/gc/default.c +++ b/gc/default.c @@ -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;