summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-12-24 19:22:13 -0500
committerPeter Zhu <peter@peterzhu.ca>2023-12-24 21:29:40 -0500
commit7002e776944ddfd362cea253d18d02bc250fe9f7 (patch)
tree1aa1b9479a6dc76251eac1cf2226a3af3f404683 /string.c
parente233730846fd2634208c3c568c49b76bf3b29a0b (diff)
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">.
Diffstat (limited to 'string.c')
-rw-r--r--string.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/string.c b/string.c
index 712c963058..b770daf681 100644
--- a/string.c
+++ b/string.c
@@ -11630,10 +11630,15 @@ sym_inspect(VALUE sym)
}
else {
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);
dest = RSTRING_PTR(str);
memcpy(dest + 1, ptr, len);
+
+ RB_GC_GUARD(orig_str);
}
dest[0] = ':';
return str;