Fix removing non-existent ivar for too complex

This commit is contained in:
Peter Zhu 2023-11-01 08:25:09 -04:00
parent a1e24ab484
commit 9c6dd25093
2 changed files with 15 additions and 2 deletions

View File

@ -265,8 +265,13 @@ class TestShapes < Test::Unit::TestCase
c = Class.new
c.instance_variable_set(:@a, 1)
assert_equal(1, c.instance_variable_get(:@a))
c.remove_instance_variable(:@a)
assert_nil(c.instance_variable_get(:@a))
assert_raise(NameError) do
c.remove_instance_variable(:@a)
end
end;
end
@ -290,6 +295,10 @@ class TestShapes < Test::Unit::TestCase
tc.remove_instance_variable(:@a)
assert_nil(tc.instance_variable_get(:@a))
assert_raise(NameError) do
tc.remove_instance_variable(:@a)
end
end;
end

View File

@ -2199,7 +2199,9 @@ rb_obj_remove_instance_variable(VALUE obj, VALUE name)
case T_MODULE:
IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(id);
if (rb_shape_obj_too_complex(obj)) {
st_delete(RCLASS_IV_HASH(obj), (st_data_t *)&id, (st_data_t *)&val);
if (!st_delete(RCLASS_IV_HASH(obj), (st_data_t *)&id, (st_data_t *)&val)) {
val = Qundef;
}
}
else {
rb_shape_transition_shape_remove_ivar(obj, id, shape, &val);
@ -2220,7 +2222,9 @@ rb_obj_remove_instance_variable(VALUE obj, VALUE name)
if (rb_shape_obj_too_complex(obj)) {
struct gen_ivtbl *ivtbl;
if (rb_gen_ivtbl_get(obj, 0, &ivtbl)) {
st_delete(ivtbl->as.complex.table, (st_data_t *)&id, (st_data_t *)&val);
if (!st_delete(ivtbl->as.complex.table, (st_data_t *)&id, (st_data_t *)&val)) {
val = Qundef;
}
}
}
else {