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

ruby-changes:31308

From: akr <ko1@a...>
Date: Tue, 22 Oct 2013 18:30:10 +0900 (JST)
Subject: [ruby-changes:31308] akr:r43387 (trunk): * lib/pp.rb (object_address_group): Use Kernel#to_s to obtain the class

akr	2013-10-22 18:29:53 +0900 (Tue, 22 Oct 2013)

  New Revision: 43387

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

  Log:
    * lib/pp.rb (object_address_group): Use Kernel#to_s to obtain the class
      name and object address.
      This fix a problem caused by %p in C generates variable length
      address.
      Reported by ko1 via IRC.

  Modified files:
    trunk/ChangeLog
    trunk/lib/pp.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43386)
+++ ChangeLog	(revision 43387)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Oct 22 18:26:12 2013  Tanaka Akira  <akr@f...>
+
+	* lib/pp.rb (object_address_group): Use Kernel#to_s to obtain the class
+	  name and object address.
+	  This fix a problem caused by %p in C generates variable length
+	  address.
+	  Reported by ko1 via IRC.
+
 Tue Oct 22 16:57:48 2013  Benoit Daloze  <eregontp@g...>
 
 	* file.c (File#expand_path): [DOC] improve documentation of File#expand_path.
Index: lib/pp.rb
===================================================================
--- lib/pp.rb	(revision 43386)
+++ lib/pp.rb	(revision 43387)
@@ -197,22 +197,12 @@ class PP < PrettyPrint https://github.com/ruby/ruby/blob/trunk/lib/pp.rb#L197
       group(1, '#<' + obj.class.name, '>', &block)
     end
 
-    # A mask used in formating object_id's into a hexadecimal id
-    PointerMask = (1 << ([""].pack("p").size * 8)) - 1
-
-    case Object.new.inspect
-    when /\A\#<Object:0x([0-9a-f]+)>\z/
-      # String Formating for hexadecimal id
-      PointerFormat = "%0#{$1.length}x"
-    else
-      PointerFormat = "%x"
-    end
-
     # A convenience method, like object_group, but also reformats the Object's
     # object_id.
     def object_address_group(obj, &block)
-      id = PointerFormat % (obj.object_id * 2 & PointerMask)
-      group(1, "\#<#{obj.class}:0x#{id}", '>', &block)
+      str = Kernel.instance_method(:to_s).bind(obj).call
+      str.chomp!('>')
+      group(1, str, '>', &block)
     end
 
     # A convenience method which is same as follows:

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

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