object.c: preserve encodings
* object.c (rb_any_to_s, rb_obj_inspect): preserve encodings of class name and instance variable names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f7c2791c60
commit
b421bd0e12
@ -1,3 +1,8 @@
|
|||||||
|
Fri Aug 17 23:28:54 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Fri Aug 17 12:39:33 2012 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* ext/dl/lib/dl/func.rb (DL::Function#bind): allow to return/break from
|
* ext/dl/lib/dl/func.rb (DL::Function#bind): allow to return/break from
|
||||||
|
11
object.c
11
object.c
@ -370,10 +370,10 @@ rb_obj_init_dup_clone(VALUE obj, VALUE orig)
|
|||||||
VALUE
|
VALUE
|
||||||
rb_any_to_s(VALUE obj)
|
rb_any_to_s(VALUE obj)
|
||||||
{
|
{
|
||||||
const char *cname = rb_obj_classname(obj);
|
|
||||||
VALUE str;
|
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);
|
OBJ_INFECT(str, obj);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
@ -484,11 +484,12 @@ rb_obj_inspect(VALUE obj)
|
|||||||
{
|
{
|
||||||
if (rb_ivar_count(obj) > 0) {
|
if (rb_ivar_count(obj) > 0) {
|
||||||
VALUE str;
|
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);
|
return rb_exec_recursive(inspect_obj, obj, str);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return rb_any_to_s(obj);
|
return rb_any_to_s(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -688,6 +688,13 @@ class TestObject < Test::Unit::TestCase
|
|||||||
s = x.to_s
|
s = x.to_s
|
||||||
assert_equal(true, s.untrusted?)
|
assert_equal(true, s.untrusted?)
|
||||||
assert_equal(true, s.tainted?)
|
assert_equal(true, s.tainted?)
|
||||||
|
|
||||||
|
x = eval(<<-EOS)
|
||||||
|
class ToS\u{3042}
|
||||||
|
new.to_s
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
assert_match(/\bToS\u{3042}:/, x)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inspect
|
def test_inspect
|
||||||
@ -713,6 +720,23 @@ class TestObject < Test::Unit::TestCase
|
|||||||
"to_s"
|
"to_s"
|
||||||
end
|
end
|
||||||
assert_match(/\A#<Object:0x\h+>\z/, x.inspect, feature6130)
|
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
|
end
|
||||||
|
|
||||||
def test_exec_recursive
|
def test_exec_recursive
|
||||||
|
Loading…
x
Reference in New Issue
Block a user