diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2024-10-22 10:43:28 -0400 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2024-10-23 13:18:09 -0400 |
| commit | c2af84b244e3ddee4ec8f69bc5a2be5efd179901 (patch) | |
| tree | f81e38204dd2af52268f52b6748bfe938d744087 | |
| parent | 8e509380a25bea9b485e071e161b54da05b19cac (diff) | |
Move error handling for GC.latest_gc_info to gc.c
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11932
| -rw-r--r-- | gc.c | 12 | ||||
| -rw-r--r-- | gc/default.c | 7 |
2 files changed, 15 insertions, 4 deletions
@@ -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; |
