From fa72ba72f8c64fd0fa87c8f68cbc31f2e7b94b00 Mon Sep 17 00:00:00 2001 From: nagachika Date: Sat, 22 Jul 2023 13:24:55 +0900 Subject: merge revision(s) 54dbd8bea8a79bfcdefa471c1717c6cd28022f33: [Backport #19535] Use an st table for "too complex" objects st tables will maintain insertion order so we can marshal dump / load objects with instance variables in the same order they were set on that particular instance [ruby-core:112926] [Bug #19535] Co-Authored-By: Jemma Issroff --- gc.c | 10 ++++------ include/ruby/st.h | 2 ++ object.c | 2 +- ractor.c | 43 ++++++++++++++++++++++--------------------- shape.h | 6 +++--- st.c | 6 ++++++ test/ruby/test_shapes.rb | 21 +++++++++++++++++++++ variable.c | 28 ++++++++++++++-------------- vm_insnhelper.c | 2 +- 9 files changed, 74 insertions(+), 46 deletions(-) --- test/ruby/test_shapes.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb index b2cd79ab12..47ade7e70b 100644 --- a/test/ruby/test_shapes.rb +++ b/test/ruby/test_shapes.rb @@ -3,6 +3,17 @@ require 'test/unit' # These test the functionality of object shapes class TestShapes < Test::Unit::TestCase + class IVOrder + def expected_ivs + %w{ @a @b @c @d @e @f @g @h @i @j @k } + end + + def set_ivs + expected_ivs.each { instance_variable_set(_1, 1) } + self + end + end + class ShapeOrder def initialize @b = :b # 5 => 6 @@ -80,6 +91,16 @@ class TestShapes < Test::Unit::TestCase refute_equal(shape1.id, shape2.id) end + def test_iv_order_correct_on_complex_objects + (RubyVM::Shape::SHAPE_MAX_VARIATIONS + 1).times { + IVOrder.new.instance_variable_set("@a#{_1}", 1) + } + + obj = IVOrder.new + iv_list = obj.set_ivs.instance_variables + assert_equal obj.expected_ivs, iv_list.map(&:to_s) + end + def test_too_complex ensure_complex -- cgit v1.2.3