[前][次][番号順一覧][スレッド一覧]

ruby-changes:60019

From: Nobuyoshi <ko1@a...>
Date: Wed, 12 Feb 2020 19:58:41 +0900 (JST)
Subject: [ruby-changes:60019] bdf3032e35 (master): Make temporary lock string encoding free

https://git.ruby-lang.org/ruby.git/commit/?id=bdf3032e35

From bdf3032e3542b318c6f52dbe20d1c97cca3d7067 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 12 Feb 2020 19:29:18 +0900
Subject: Make temporary lock string encoding free

As a temporary lock string is hidden, it can not have instance
variables, including non-inlined encoding index.

diff --git a/sprintf.c b/sprintf.c
index 64cfdee..ff1800e 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -257,7 +257,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/sprintf.c#L257
     blen = 0;
     bsiz = 120;
     result = rb_str_buf_new(bsiz);
-    rb_enc_copy(result, fmt);
+    rb_enc_associate(result, enc);
     buf = RSTRING_PTR(result);
     memset(buf, 0, bsiz);
     ENC_CODERANGE_SET(result, coderange);
diff --git a/string.c b/string.c
index 12f5d01..83c4780 100644
--- a/string.c
+++ b/string.c
@@ -199,6 +199,7 @@ VALUE rb_cSymbol; https://github.com/ruby/ruby/blob/trunk/string.c#L199
 static VALUE str_replace_shared_without_enc(VALUE str2, 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_buffer(VALUE klass, VALUE orig, int copy_encoding);
 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 inline void str_modifiable(VALUE str);
@@ -1225,7 +1226,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L1226
 rb_str_tmp_frozen_acquire(VALUE orig)
 {
     if (OBJ_FROZEN_RAW(orig)) return orig;
-    return str_new_frozen(0, orig);
+    return str_new_frozen_buffer(0, orig, FALSE);
 }
 
 void
@@ -1257,6 +1258,12 @@ rb_str_tmp_frozen_release(VALUE orig, VALUE tmp) https://github.com/ruby/ruby/blob/trunk/string.c#L1258
 static VALUE
 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;
 
     if (STR_EMBED_P(orig)) {
@@ -1304,7 +1311,7 @@ str_new_frozen(VALUE klass, VALUE orig) https://github.com/ruby/ruby/blob/trunk/string.c#L1311
 	}
     }
 
-    rb_enc_cr_str_exact_copy(str, orig);
+    if (copy_encoding) rb_enc_cr_str_exact_copy(str, orig);
     OBJ_FREEZE(str);
     return str;
 }
diff --git a/test/ruby/test_encoding.rb b/test/ruby/test_encoding.rb
index 6d0665a..d571dd2 100644
--- a/test/ruby/test_encoding.rb
+++ b/test/ruby/test_encoding.rb
@@ -73,7 +73,7 @@ class TestEncoding < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_encoding.rb#L73
       }
       e = Encoding.list.last
       format = "%d".force_encoding(e)
-      assert_raise(TypeError) {format % 0}
+      assert_equal("0", format % 0)
     end;
   end
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]