Move error handling for GC.stat to gc.c

This commit is contained in:
Peter Zhu 2024-10-22 10:49:12 -04:00
parent 9dea0fae25
commit c0b50d05c7
Notes: git 2024-10-23 17:18:28 +00:00
2 changed files with 31 additions and 8 deletions

32
gc.c
View File

@ -3416,18 +3416,40 @@ gc_stat(rb_execution_context_t *ec, VALUE self, VALUE arg) // arg is (nil || has
if (NIL_P(arg)) {
arg = rb_hash_new();
}
else if (!RB_TYPE_P(arg, T_HASH) && !SYMBOL_P(arg)) {
rb_raise(rb_eTypeError, "non-hash or symbol given");
}
return rb_gc_impl_stat(rb_gc_get_objspace(), arg);
VALUE ret = rb_gc_impl_stat(rb_gc_get_objspace(), arg);
if (ret == Qundef) {
GC_ASSERT(SYMBOL_P(arg));
rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(arg));
}
return ret;
}
size_t
rb_gc_stat(VALUE key)
rb_gc_stat(VALUE arg)
{
if (SYMBOL_P(key)) {
return rb_gc_impl_stat(rb_gc_get_objspace(), key);
if (!RB_TYPE_P(arg, T_HASH) && !SYMBOL_P(arg)) {
rb_raise(rb_eTypeError, "non-hash or symbol given");
}
VALUE ret = rb_gc_impl_stat(rb_gc_get_objspace(), arg);
if (ret == Qundef) {
GC_ASSERT(SYMBOL_P(arg));
rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(arg));
}
if (SYMBOL_P(arg)) {
return NUM2SIZET(ret);
}
else {
rb_gc_impl_stat(rb_gc_get_objspace(), key);
return 0;
}
}

View File

@ -7512,7 +7512,7 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
key = hash_or_sym;
}
else {
rb_raise(rb_eTypeError, "non-hash or symbol given");
rb_bug("non-hash or symbol given");
}
#define SET(name, attr) \
@ -7566,8 +7566,9 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
#endif /* RGENGC_PROFILE */
#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;
}
#if defined(RGENGC_PROFILE) && RGENGC_PROFILE >= 2