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

Make temporary lock string encoding free

As a temporary lock string is hidden, it can not have instance
variables, including non-inlined encoding index.
This commit is contained in:
Nobuyoshi Nakada 2020-02-12 19:29:18 +09:00
parent 1b219f1fb2
commit bdf3032e35
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
3 changed files with 11 additions and 4 deletions

View file

@ -257,7 +257,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
blen = 0; blen = 0;
bsiz = 120; bsiz = 120;
result = rb_str_buf_new(bsiz); result = rb_str_buf_new(bsiz);
rb_enc_copy(result, fmt); rb_enc_associate(result, enc);
buf = RSTRING_PTR(result); buf = RSTRING_PTR(result);
memset(buf, 0, bsiz); memset(buf, 0, bsiz);
ENC_CODERANGE_SET(result, coderange); ENC_CODERANGE_SET(result, coderange);

View file

@ -199,6 +199,7 @@ VALUE rb_cSymbol;
static VALUE str_replace_shared_without_enc(VALUE str2, VALUE str); static VALUE str_replace_shared_without_enc(VALUE str2, VALUE str);
static VALUE str_new_shared(VALUE klass, VALUE str); static VALUE str_new_shared(VALUE klass, VALUE str);
static VALUE str_new_frozen(VALUE klass, VALUE orig); static VALUE str_new_frozen(VALUE klass, VALUE orig);
static VALUE str_new_frozen_buffer(VALUE klass, VALUE orig, int copy_encoding);
static VALUE str_new_static(VALUE klass, const char *ptr, long len, int encindex); static VALUE str_new_static(VALUE klass, const char *ptr, long len, int encindex);
static void str_make_independent_expand(VALUE str, long len, long expand, const int termlen); static void str_make_independent_expand(VALUE str, long len, long expand, const int termlen);
static inline void str_modifiable(VALUE str); static inline void str_modifiable(VALUE str);
@ -1225,7 +1226,7 @@ VALUE
rb_str_tmp_frozen_acquire(VALUE orig) rb_str_tmp_frozen_acquire(VALUE orig)
{ {
if (OBJ_FROZEN_RAW(orig)) return orig; if (OBJ_FROZEN_RAW(orig)) return orig;
return str_new_frozen(0, orig); return str_new_frozen_buffer(0, orig, FALSE);
} }
void void
@ -1256,6 +1257,12 @@ rb_str_tmp_frozen_release(VALUE orig, VALUE tmp)
static VALUE static VALUE
str_new_frozen(VALUE klass, VALUE orig) str_new_frozen(VALUE klass, VALUE orig)
{
return str_new_frozen_buffer(klass, orig, TRUE);
}
static VALUE
str_new_frozen_buffer(VALUE klass, VALUE orig, int copy_encoding)
{ {
VALUE str; VALUE str;
@ -1304,7 +1311,7 @@ str_new_frozen(VALUE klass, VALUE orig)
} }
} }
rb_enc_cr_str_exact_copy(str, orig); if (copy_encoding) rb_enc_cr_str_exact_copy(str, orig);
OBJ_FREEZE(str); OBJ_FREEZE(str);
return str; return str;
} }

View file

@ -73,7 +73,7 @@ class TestEncoding < Test::Unit::TestCase
} }
e = Encoding.list.last e = Encoding.list.last
format = "%d".force_encoding(e) format = "%d".force_encoding(e)
assert_raise(TypeError) {format % 0} assert_equal("0", format % 0)
end; end;
end end