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

ruby-changes:46949

From: nobu <ko1@a...>
Date: Mon, 12 Jun 2017 13:35:58 +0900 (JST)
Subject: [ruby-changes:46949] nobu:r59065 (trunk): iseq.c: preserve encoding

nobu	2017-06-12 13:35:53 +0900 (Mon, 12 Jun 2017)

  New Revision: 59065

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

  Log:
    iseq.c: preserve encoding
    
    * iseq.c (iseqw_inspect): preserve path encoding in the result.

  Modified files:
    trunk/iseq.c
    trunk/test/ruby/test_iseq.rb
Index: test/ruby/test_iseq.rb
===================================================================
--- test/ruby/test_iseq.rb	(revision 59064)
+++ test/ruby/test_iseq.rb	(revision 59065)
@@ -270,4 +270,12 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L270
       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
Index: iseq.c
===================================================================
--- iseq.c	(revision 59064)
+++ iseq.c	(revision 59065)
@@ -983,14 +983,15 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/iseq.c#L983
 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));
     }
 }
 

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

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