8000 Fix crash for special constants in too complex generic ivars · github/ruby@0597cbc · GitHub
[go: up one dir, main page]

Skip to content

Commit 0597cbc

Browse files
committed
Fix crash for special constants in too complex generic ivars
We should skip reference updating for entries in too complex generic ivars that are special constants. This fixes the following crash: MAX_SHAPES = 0x80000 MAX_SHAPES.times do |i| o = [] o.instance_variable_set(:"@foo#{i}", 1) end o = [] o.instance_variable_set(:"@A", 123) GC.compact
1 parent 27ba268 commit 0597cbc

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

gc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,6 +3441,8 @@ vm_weak_table_gen_ivar_foreach_too_complex_i(st_data_t _key, st_data_t value, st
34413441

34423442
GC_ASSERT(!iter_data->weak_only);
34433443

3444+
if (SPECIAL_CONST_P((VALUE)value)) return ST_CONTINUE;
3445+
34443446
return iter_data->callback((VALUE)value, iter_data->data);
34453447
}
34463448

test/ruby/test_gc_compact.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,4 +452,21 @@ def set_a
452452
assert_raise(FrozenError) { a.set_a }
453453
end;
454454
end
455+
456+
def test_moving_too_compex_generic_ivar
457+
omit "not compiled with SHAPE_DEBUG" unless defined?(RubyVM::Shape)
458+
459+
assert_separately([], <<~RUBY)
460+
RubyVM::Shape.exhaust_shapes
461+
462+
obj = []
463+
obj.instance_variable_set(:@fixnum, 123)
464+
obj.instance_variable_set(:@str, "hello")
465+
466+
GC.verify_compaction_references(expand_heap: true, toward: :empty)
467+
468+
assert_equal(123, obj.instance_variable_get(:@fixnum))
469+
assert_equal("hello", obj.instance_variable_get(:@str))
470+
RUBY
471+
end
455472
end

0 commit comments

Comments
 (0)
0