summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYusuke Endoh <[email protected]>2024-05-23 18:24:48 +0900
committerYusuke Endoh <[email protected]>2024-05-23 19:26:45 +0900
commit1471a160ba1bbdca9d6c4b21260793c1414253f3 (patch)
tree5cf4f94faddcbe1f071d9e8b3185941791cd8d61
parentce20367a0e2f1fcfabebf3b6bea732fc71fa79f7 (diff)
Add RB_GC_GUARD for rb_str_to_parser_string
I think this fixes the following random test failure that could not be fixed for a long time: ``` 1) Failure: TestSymbol#test_inspect_under_gc_compact_stress [/home/chkbuild/chkbuild/tmp/build/20240522T003003Z/ruby/test/ruby/test_symbol.rb:126]: <":testing"> expected but was <":\"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\"">. ``` The value passed to this function is the return value of `rb_id2str`, so it is never collected. However, if auto_compact is enabled, the string may move and `RSTRING_PTR(str)` became invalid. This change prevents the string from being moved by RB_GC_GUARD.
-rw-r--r--parse.y4
1 files changed, 3 insertions, 1 deletions
diff --git a/parse.y b/parse.y
index 9a2535bd2d..2ce1143d20 100644
--- a/parse.y
+++ b/parse.y
@@ -2082,7 +2082,9 @@ rb_parser_string_t *
rb_str_to_parser_string(rb_parser_t *p, VALUE str)
{
/* Type check */
- return rb_parser_encoding_string_new(p, RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
+ rb_parser_string_t *ret = rb_parser_encoding_string_new(p, RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
+ RB_GC_GUARD(str);
+ return ret;
}
#endif