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

ruby-changes:36492

From: nobu <ko1@a...>
Date: Wed, 26 Nov 2014 03:44:37 +0900 (JST)
Subject: [ruby-changes:36492] nobu:r48574 (trunk): object.c: preserve encodings

nobu	2014-11-26 03:44:16 +0900 (Wed, 26 Nov 2014)

  New Revision: 48574

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48574

  Log:
    object.c: preserve encodings
    
    * object.c (inspect_i): preserve encodings in inspected result
      string.

  Modified files:
    trunk/object.c
    trunk/test/ruby/test_object.rb
Index: object.c
===================================================================
--- object.c	(revision 48573)
+++ object.c	(revision 48574)
@@ -489,8 +489,6 @@ inspect_i(st_data_t k, st_data_t v, st_d https://github.com/ruby/ruby/blob/trunk/object.c#L489
     ID id = (ID)k;
     VALUE value = (VALUE)v;
     VALUE str = (VALUE)a;
-    VALUE str2;
-    const char *ivname;
 
     /* need not to show internal data */
     if (CLASS_OF(value) == 0) return ST_CONTINUE;
@@ -502,12 +500,8 @@ inspect_i(st_data_t k, st_data_t v, st_d https://github.com/ruby/ruby/blob/trunk/object.c#L500
     else {
 	rb_str_cat2(str, ", ");
     }
-    ivname = rb_id2name(id);
-    rb_str_cat2(str, ivname);
-    rb_str_cat2(str, "=");
-    str2 = rb_inspect(value);
-    rb_str_append(str, str2);
-    OBJ_INFECT(str, str2);
+    rb_str_catf(str, "%"PRIsVALUE"=%+"PRIsVALUE,
+		rb_id2str(id), value);
 
     return ST_CONTINUE;
 }
Index: test/ruby/test_object.rb
===================================================================
--- test/ruby/test_object.rb	(revision 48573)
+++ test/ruby/test_object.rb	(revision 48574)
@@ -758,10 +758,12 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_object.rb#L758
         def initialize
           @\u{3044} = 42
         end
-        new.inspect
+        new
       end
     EOS
-    assert_match(/\bInspect\u{3042}:.* @\u{3044}=42\b/, x)
+    assert_match(/\bInspect\u{3042}:.* @\u{3044}=42\b/, x.inspect)
+    x.instance_variable_set("@\u{3046}".encode(Encoding::EUC_JP), 6)
+    assert_match(/@\u{3046}=6\b/, x.inspect)
   end
 
   def test_singleton_class

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

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