8000 Fix String#sub for GC compaction · github/ruby@50bf437 · GitHub
[go: up one dir, main page]

Skip to content

Commit 50bf437

Browse files
committed
Fix String#sub for GC compaction
The test fails when RGENGC_CHECK_MODE is turned on: TestString#test_sub_gc_compact_stress = 9.42 s 1) Failure: TestString#test_sub_gc_compact_stress [test/ruby/test_string.rb:2089]: <"aaa [amp] yyy"> expected but was <"aaa [] yyy">.
1 parent a2ebf9c commit 50bf437

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

string.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5816,6 +5816,8 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
58165816
TERM_FILL(&RSTRING_PTR(str)[l D4F4 en], TERM_LEN(str));
58175817
ENC_CODERANGE_SET(str, cr);
58185818

5819+
RB_GC_GUARD(match);
5820+
58195821
return str;
58205822
}
58215823
return Qnil;

test/ruby/test_string.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,15 @@ def o.to_s; self; end
20812081
}
20822082
end
20832083

2084+
def test_sub_gc_compact_stress
2085+
EnvUtil.under_gc_compact_stress do
2086+
m = /&(?<foo>.*?);/.match(S("aaa &amp; yyy"))
2087+
assert_equal("amp", m["foo"])
2088+
2089+
assert_equal("aaa [amp] yyy", S("aaa &amp; yyy").sub(/&(?<foo>.*?);/, S('[\k<foo>]')))
2090+
end
2091+
end
2092+
20842093
def test_sub!
20852094
a = S("hello")
20862095
b = a.dup

0 commit comments

Comments
 (0)
0