mirror of
https://github.com/ruby/ruby.git
synced 2025-08-26 14:34:39 +02:00
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.
This commit is contained in:
parent
ce20367a0e
commit
1471a160ba
1 changed files with 3 additions and 1 deletions
4
parse.y
4
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue