From a57d295e36980fe7667f5557c4741339d7684fdc Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 12 Jun 2017 04:35:53 +0000 Subject: [PATCH] iseq.c: preserve encoding * iseq.c (iseqw_inspect): preserve path encoding in the result. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- iseq.c | 9 +++++---- test/ruby/test_iseq.rb | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/iseq.c b/iseq.c index 0d66f5a603..a4e86677c9 100644 --- a/iseq.c +++ b/iseq.c @@ -983,14 +983,15 @@ static VALUE iseqw_inspect(VALUE self) { const rb_iseq_t *iseq = iseqw_check(self); + VALUE klass = rb_class_name(rb_obj_class(self)); if (!iseq->body->location.label) { - return rb_sprintf("#<%s: uninitialized>", rb_obj_classname(self)); + return rb_sprintf("#<%"PRIsVALUE": uninitialized>", klass); } else { - return rb_sprintf("<%s:%s@%s>", - rb_obj_classname(self), - RSTRING_PTR(iseq->body->location.label), RSTRING_PTR(rb_iseq_path(iseq))); + return rb_sprintf("<%"PRIsVALUE":%"PRIsVALUE"@%"PRIsVALUE">", + klass, + iseq->body->location.label, rb_iseq_path(iseq)); } } diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index df71e1821e..54256816cf 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -270,4 +270,12 @@ class TestISeq < Test::Unit::TestCase assert_equal(0, eval("0")) end; end + + def test_inspect + %W[foo \u{30d1 30b9}].each do |name| + assert_match /@#{name}/, ISeq.compile("", name).inspect, name + m = ISeq.compile("class TestISeq::Inspect; def #{name}; end; instance_method(:#{name}); end").eval + assert_match /:#{name}@/, ISeq.of(m).inspect, name + end + end end