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">.
This commit is contained in:
parent
e233730846
commit
7002e77694
7
string.c
7
string.c
@ -11630,10 +11630,15 @@ sym_inspect(VALUE sym)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_encoding *enc = STR_ENC_GET(str);
|
rb_encoding *enc = STR_ENC_GET(str);
|
||||||
RSTRING_GETMEM(str, ptr, len);
|
|
||||||
|
VALUE orig_str = str;
|
||||||
|
RSTRING_GETMEM(orig_str, ptr, len);
|
||||||
|
|
||||||
str = rb_enc_str_new(0, len + 1, enc);
|
str = rb_enc_str_new(0, len + 1, enc);
|
||||||
dest = RSTRING_PTR(str);
|
dest = RSTRING_PTR(str);
|
||||||
memcpy(dest + 1, ptr, len);
|
memcpy(dest + 1, ptr, len);
|
||||||
|
|
||||||
|
RB_GC_GUARD(orig_str);
|
||||||
}
|
}
|
||||||
dest[0] = ':';
|
dest[0] = ':';
|
||||||
return str;
|
return str;
|
||||||
|
@ -118,6 +118,12 @@ class TestSymbol < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_inspect_under_gc_compact_stress
|
||||||
|
EnvUtil.under_gc_compact_stress do
|
||||||
|
assert_inspect_evaled(':testing')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_name
|
def test_name
|
||||||
assert_equal("foo", :foo.name)
|
assert_equal("foo", :foo.name)
|
||||||
assert_same(:foo.name, :foo.name)
|
assert_same(:foo.name, :foo.name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user