summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2025-02-18 16:26:07 -0500
committerPeter Zhu <peter@peterzhu.ca>2025-02-18 17:09:28 -0500
commit0597cbcb1d895028e954db9711681e987c56729d (patch)
treed401b1b3106d398cf0524bdd7543b13fac082c51 /test/ruby
parent27ba268b75bbe461460b31426e377b42d4935f70 (diff)
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
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12781
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_gc_compact.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb
index 4c8aa20215..2a72ecfc5f 100644
--- a/test/ruby/test_gc_compact.rb
+++ b/test/ruby/test_gc_compact.rb
@@ -452,4 +452,21 @@ class TestGCCompact < Test::Unit::TestCase
assert_raise(FrozenError) { a.set_a }
end;
end
+
+ def test_moving_too_compex_generic_ivar
+ omit "not compiled with SHAPE_DEBUG" unless defined?(RubyVM::Shape)
+
+ assert_separately([], <<~RUBY)
+ RubyVM::Shape.exhaust_shapes
+
+ obj = []
+ obj.instance_variable_set(:@fixnum, 123)
+ obj.instance_variable_set(:@str, "hello")
+
+ GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ assert_equal(123, obj.instance_variable_get(:@fixnum))
+ assert_equal("hello", obj.instance_variable_get(:@str))
+ RUBY
+ end
end