From f0efeddd41f96d3afae9af73a3dc594d86614f4b Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Sun, 24 Dec 2023 09:08:01 -0500 Subject: Fix Regexp#inspect for GC compaction rb_reg_desc was not safe for GC compaction because it took in the C string and length but not the backing String object so it get moved during compaction. This commit changes rb_reg_desc to use the string from the Regexp object. The test fails when RGENGC_CHECK_MODE is turned on: TestRegexp#test_inspect_under_gc_compact_stress [test/ruby/test_regexp.rb:474]: <"(?-mix:\\/)|"> expected but was <"/\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00/">. --- test/ruby/test_regexp.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index c51c61b2a3..d4aae16037 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -469,6 +469,12 @@ class TestRegexp < Test::Unit::TestCase assert_equal('/\/\xF1\xF2\xF3/i', /\/#{s}/i.inspect) end + def test_inspect_under_gc_compact_stress + EnvUtil.under_gc_compact_stress do + assert_equal('/(?-mix:\\/)|/', Regexp.union(/\//, "").inspect) + end + end + def test_char_to_option assert_equal("BAR", "FOOBARBAZ"[/b../i]) assert_equal("bar", "foobarbaz"[/ b . . /x]) -- cgit v1.2.3