ruby-changes:24672
From: nobu <ko1@a...>
Date: Fri, 17 Aug 2012 23:29:15 +0900 (JST)
Subject: [ruby-changes:24672] nobu:r36723 (trunk): object.c: preserve encodings
nobu 2012-08-17 23:29:00 +0900 (Fri, 17 Aug 2012) New Revision: 36723 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36723 Log: object.c: preserve encodings * object.c (rb_any_to_s, rb_obj_inspect): preserve encodings of class name and instance variable names. Modified files: trunk/ChangeLog trunk/object.c trunk/test/ruby/test_object.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 36722) +++ ChangeLog (revision 36723) @@ -1,3 +1,8 @@ +Fri Aug 17 23:28:54 2012 Nobuyoshi Nakada <nobu@r...> + + * object.c (rb_any_to_s, rb_obj_inspect): preserve encodings of class + name and instance variable names. + Fri Aug 17 12:39:33 2012 NAKAMURA Usaku <usa@r...> * ext/dl/lib/dl/func.rb (DL::Function#bind): allow to return/break from Index: object.c =================================================================== --- object.c (revision 36722) +++ object.c (revision 36723) @@ -370,10 +370,10 @@ VALUE rb_any_to_s(VALUE obj) { - const char *cname = rb_obj_classname(obj); VALUE str; + VALUE cname = rb_class_name(CLASS_OF(obj)); - str = rb_sprintf("#<%s:%p>", cname, (void*)obj); + str = rb_sprintf("#<%"PRIsVALUE":%p>", cname, (void*)obj); OBJ_INFECT(str, obj); return str; @@ -484,11 +484,12 @@ { if (rb_ivar_count(obj) > 0) { VALUE str; - const char *c = rb_obj_classname(obj); + VALUE c = rb_class_name(CLASS_OF(obj)); - str = rb_sprintf("-<%s:%p", c, (void*)obj); + str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void*)obj); return rb_exec_recursive(inspect_obj, obj, str); - } else { + } + else { return rb_any_to_s(obj); } } Index: test/ruby/test_object.rb =================================================================== --- test/ruby/test_object.rb (revision 36722) +++ test/ruby/test_object.rb (revision 36723) @@ -688,6 +688,13 @@ s = x.to_s assert_equal(true, s.untrusted?) assert_equal(true, s.tainted?) + + x = eval(<<-EOS) + class ToS\u{3042} + new.to_s + end + EOS + assert_match(/\bToS\u{3042}:/, x) end def test_inspect @@ -713,6 +720,23 @@ "to_s" end assert_match(/\A#<Object:0x\h+>\z/, x.inspect, feature6130) + + x = eval(<<-EOS) + class Inspect\u{3042} + new.inspect + end + EOS + assert_match(/\bInspect\u{3042}:/, x) + + x = eval(<<-EOS) + class Inspect\u{3042} + def initialize + @\u{3044} = 42 + end + new.inspect + end + EOS + assert_match(/\bInspect\u{3042}:.* @\u{3044}=42\b/, x) end def test_exec_recursive -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/