Freeze $/ and make it ractor safe

[Feature #21109]

By always freezing when setting the global rb_rs variable, we can ensure
it is not modified and can be accessed from a ractor.

We're also making sure it's an instance of String and does not have any
instance variables.

Of course, if $/ is changed at runtime, it may cause surprising behavior
but doing so is deprecated already anyway.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
This commit is contained in:
Étienne Barrié 2025-03-24 12:17:58 +01:00 committed by Jean Boussier
parent 49d49d5985
commit 6ecfe643b5
Notes: git 2025-03-27 16:55:12 +00:00
6 changed files with 110 additions and 12 deletions

4
ruby.c
View file

@ -1325,11 +1325,11 @@ proc_0_option(ruby_cmdline_options_t *opt, const char *s)
if (v > 0377)
rb_rs = Qnil;
else if (v == 0 && numlen >= 2) {
rb_rs = rb_str_new2("");
rb_rs = rb_fstring_lit("");
}
else {
c = v & 0xff;
rb_rs = rb_str_new(&c, 1);
rb_rs = rb_str_freeze(rb_str_new(&c, 1));
}
return s;
}