From 6f5e378057a02dadbb0173072f69c8a3f30f5649 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 30 Oct 2023 09:50:56 -0700 Subject: Fix "too complex" iv sets on generic ivar objects We weren't taking in to account that objects with generic IV tables could go "too complex" in the IV set code. This commit takes that in to account and also ensures FL_EXIVAR is set when a geniv object transitions to "too complex" Co-Authored-By: Jean Boussier --- test/ruby/test_shapes.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb index b9ac1cafe1..a098edf409 100644 --- a/test/ruby/test_shapes.rb +++ b/test/ruby/test_shapes.rb @@ -184,6 +184,32 @@ class TestShapes < Test::Unit::TestCase assert_empty obj.instance_variables end + def test_too_complex_geniv + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + class TooComplex < Hash + attr_reader :very_unique + end + + obj = Object.new + i = 0 + while RubyVM::Shape.shapes_available > 0 + obj.instance_variable_set(:"@a#{i}", 1) + i += 1 + end + + (RubyVM::Shape::SHAPE_MAX_VARIATIONS * 2).times do + TooComplex.new.instance_variable_set(:"@unique_#{_1}", 1) + end + + tc = TooComplex.new + tc.instance_variable_set(:@very_unique, 3) + tc.instance_variable_set(:@very_unique2, 4) + assert_equal 3, tc.instance_variable_get(:@very_unique) + assert_equal 4, tc.instance_variable_get(:@very_unique2) + end; + end + def test_use_all_shapes_then_freeze assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") begin; -- cgit v1.2.3