1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

should not use rb_str_modify(), too

Same as 8247b8edde, should not use rb_str_modify() here.

https://bugs.ruby-lang.org/issues/17343#change-88858
This commit is contained in:
Koichi Sasada 2020-12-01 16:34:59 +09:00
parent d5e16161f6
commit 764de7566f
Notes: git 2020-12-01 18:16:48 +09:00
4 changed files with 23 additions and 3 deletions

View file

@ -1022,13 +1022,21 @@ assert_equal 'can not make a Proc shareable because it accesses outer variables
end
}
# Ractor deep copies frozen objects
# Ractor deep copies frozen objects (ary)
assert_equal '[true, false]', %q{
Ractor.new([[]].freeze) { |ary|
[ary.frozen?, ary.first.frozen? ]
}.take
}
# Ractor deep copies frozen objects (str)
assert_equal '[true, false]', %q{
s = String.new.instance_eval { @x = []; freeze}
Ractor.new(s) { |s|
[s.frozen?, s.instance_variable_get(:@x).frozen?]
}.take
}
###
### Synchronization tests
###

View file

@ -42,6 +42,8 @@ VALUE rb_str_initialize(VALUE str, const char *ptr, long len, rb_encoding *enc);
size_t rb_str_memsize(VALUE);
char *rb_str_to_cstr(VALUE str);
const char *ruby_escaped_char(int c);
void rb_str_make_independent(VALUE str);
static inline bool STR_EMBED_P(VALUE str);
static inline bool STR_SHARED_P(VALUE str);
static inline VALUE QUOTE(VALUE v);

View file

@ -2294,7 +2294,7 @@ obj_traverse_replace_i(VALUE obj, struct obj_traverse_replace_data *data)
case T_MATCH:
break;
case T_STRING:
rb_str_modify(obj);
rb_str_make_independent(obj);
break;
case T_OBJECT:

View file

@ -214,6 +214,16 @@ str_make_independent(VALUE str)
str_make_independent_expand((str), len, 0L, termlen);
}
static inline int str_dependent_p(VALUE str);
void
rb_str_make_independent(VALUE str)
{
if (str_dependent_p(str)) {
str_make_independent(str);
}
}
/* symbols for [up|down|swap]case/capitalize options */
static VALUE sym_ascii, sym_turkic, sym_lithuanian, sym_fold;