Skip to content

Commit 7002e77

Browse files
committed
Fix Symbol#inspect for GC compaction
The test fails when RGENGC_CHECK_MODE is turned on: 1) Failure: TestSymbol#test_inspect_under_gc_compact_stress [test/ruby/test_symbol.rb:123]: <":testing"> expected but was <":\x00\x00\x00\x00\x00\x00\x00">.
1 parent e233730 commit 7002e77

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

string.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11630,10 +11630,15 @@ sym_inspect(VALUE sym)
1163011630
}
1163111631
else {
1163211632
rb_encoding *enc = STR_ENC_GET(str);
11633-
RSTRING_GETMEM(str, ptr, len);
11633+
11634+
VALUE orig_str = str;
11635+
RSTRING_GETMEM(orig_str, ptr, len);
11636+
1163411637
str = rb_enc_str_new(0, len + 1, enc);
1163511638
dest = RSTRING_PTR(str);
1163611639
memcpy(dest + 1, ptr, len);
11640+
11641+
RB_GC_GUARD(orig_str);
1163711642
}
1163811643
dest[0] = ':';
1163911644
return str;

test/ruby/test_symbol.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ def test_inspect
118118
end
119119
end
120120

121+
def test_inspect_under_gc_compact_stress
122+
EnvUtil.under_gc_compact_stress do
123+
assert_inspect_evaled(':testing')
124+
end
125+
end
126+
121127
def test_name
122128
assert_equal("foo", :foo.name)
123129
assert_same(:foo.name, :foo.name)

0 commit comments

Comments
 (0)