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

ruby-changes:4588

From: ko1@a...
Date: Sat, 19 Apr 2008 20:21:41 +0900 (JST)
Subject: [ruby-changes:4588] knu - Ruby:r16082 (ruby_1_8): * lib/yaml/types.rb: Likewise, pass self to YAML::quick_emit;

knu	2008-04-19 20:21:23 +0900 (Sat, 19 Apr 2008)

  New Revision: 16082

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/lib/yaml/rubytypes.rb
    branches/ruby_1_8/lib/yaml/types.rb
    branches/ruby_1_8/lib/yaml.rb
    branches/ruby_1_8/test/yaml/test_yaml.rb

  Log:
    * lib/yaml/types.rb: Likewise, pass self to YAML::quick_emit;
      merged from 1.9.
    
    * lib/yaml.rb (quick_emit): use combination of object_id and hash to
      identify repeated object references, since GC will reuse memory of
      objects during output of YAML. [ruby-Bugs-8548] [ruby-Bugs-3698];
      merged from 1.9.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/yaml/test_yaml.rb?r1=16082&r2=16081&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/yaml/rubytypes.rb?r1=16082&r2=16081&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/yaml/types.rb?r1=16082&r2=16081&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16082&r2=16081&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/yaml.rb?r1=16082&r2=16081&diff_format=u

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 16081)
+++ ruby_1_8/ChangeLog	(revision 16082)
@@ -1,3 +1,13 @@
+Sat Apr 19 20:16:52 2008  Akinori MUSHA  <knu@i...>
+
+	* lib/yaml/types.rb: Likewise, pass self to YAML::quick_emit;
+	  merged from 1.9.
+
+	* lib/yaml.rb (quick_emit): use combination of object_id and hash to
+	  identify repeated object references, since GC will reuse memory of
+	  objects during output of YAML. [ruby-Bugs-8548] [ruby-Bugs-3698];
+	  merged from 1.9.
+
 Sat Apr 19 20:05:39 2008  Akinori MUSHA  <knu@i...>
 
 	* array.c (rb_ary_equal, rb_ary_eql, rb_ary_hash, rb_ary_cmp):
Index: ruby_1_8/lib/yaml.rb
===================================================================
--- ruby_1_8/lib/yaml.rb	(revision 16081)
+++ ruby_1_8/lib/yaml.rb	(revision 16082)
@@ -384,6 +384,10 @@
             else
                 emitter.reset( opts )
             end
+        oid =
+            case oid when Fixnum, NilClass; oid
+            else oid = "#{oid.object_id}-#{oid.hash}"
+            end
         out.emit( oid, &e )
 	end
 	
Index: ruby_1_8/lib/yaml/types.rb
===================================================================
--- ruby_1_8/lib/yaml/types.rb	(revision 16081)
+++ ruby_1_8/lib/yaml/types.rb	(revision 16082)
@@ -45,7 +45,7 @@
     class Object
         def self.tag_subclasses?; false; end
         def to_yaml( opts = {} )
-            YAML::quick_emit( object_id, opts ) do |out|
+            YAML::quick_emit( self, opts ) do |out|
                 out.map( "tag:ruby.yaml.org,2002:object:#{ @class }", to_yaml_style ) do |map|
                     @ivars.each do |k,v|
                         map.add( k, v )
@@ -123,7 +123,7 @@
             true
         end
         def to_yaml( opts = {} )
-            YAML::quick_emit( self.object_id, opts ) do |out|
+            YAML::quick_emit( self, opts ) do |out|
                 out.seq( taguri, to_yaml_style ) do |seq|
                     self.each do |v|
                         seq.add( Hash[ *v ] )
@@ -173,7 +173,7 @@
             true
         end
         def to_yaml( opts = {} )
-            YAML::quick_emit( self.object_id, opts ) do |out|
+            YAML::quick_emit( self, opts ) do |out|
                 out.seq( taguri, to_yaml_style ) do |seq|
                     self.each do |v|
                         seq.add( Hash[ *v ] )
Index: ruby_1_8/lib/yaml/rubytypes.rb
===================================================================
--- ruby_1_8/lib/yaml/rubytypes.rb	(revision 16081)
+++ ruby_1_8/lib/yaml/rubytypes.rb	(revision 16082)
@@ -12,7 +12,7 @@
     def to_yaml_style; end
     def to_yaml_properties; instance_variables.sort; end
 	def to_yaml( opts = {} )
-		YAML::quick_emit( object_id, opts ) do |out|
+		YAML::quick_emit( self, opts ) do |out|
             out.map( taguri, to_yaml_style ) do |map|
 				to_yaml_properties.each do |m|
                     map.add( m[1..-1], instance_variable_get( m ) )
@@ -35,7 +35,7 @@
         end
     end
 	def to_yaml( opts = {} )
-		YAML::quick_emit( object_id, opts ) do |out|
+		YAML::quick_emit( self, opts ) do |out|
             out.map( taguri, to_yaml_style ) do |map|
                 each do |k, v|
                     map.add( k, v )
@@ -83,7 +83,7 @@
         end
     end
 	def to_yaml( opts = {} )
-		YAML::quick_emit( object_id, opts ) do |out|
+		YAML::quick_emit( self, opts ) do |out|
 			#
 			# Basic struct is passed as a YAML map
 			#
@@ -104,7 +104,7 @@
     yaml_as "tag:yaml.org,2002:seq"
     def yaml_initialize( tag, val ); concat( val.to_a ); end
 	def to_yaml( opts = {} )
-		YAML::quick_emit( object_id, opts ) do |out|
+		YAML::quick_emit( self, opts ) do |out|
             out.seq( taguri, to_yaml_style ) do |seq|
                 each do |x|
                     seq.add( x )
@@ -124,7 +124,7 @@
         o
     end
 	def to_yaml( opts = {} )
-		YAML::quick_emit( object_id, opts ) do |out|
+		YAML::quick_emit( self, opts ) do |out|
             out.map( taguri, to_yaml_style ) do |map|
                 map.add( 'message', message )
 				to_yaml_properties.each do |m|
@@ -161,7 +161,7 @@
         end
     end
 	def to_yaml( opts = {} )
-		YAML::quick_emit( is_complex_yaml? ? object_id : nil, opts ) do |out|
+		YAML::quick_emit( is_complex_yaml? ? self : nil, opts ) do |out|
             if is_binary_data?
                 out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal )
             elsif to_yaml_properties.empty?
@@ -227,7 +227,7 @@
         end
     end
 	def to_yaml( opts = {} )
-		YAML::quick_emit( object_id, opts ) do |out|
+		YAML::quick_emit( self, opts ) do |out|
             # if self.begin.is_complex_yaml? or self.begin.respond_to? :to_str or
             #   self.end.is_complex_yaml? or self.end.respond_to? :to_str or
             #   not to_yaml_properties.empty?
@@ -310,7 +310,7 @@
         end
     end
 	def to_yaml( opts = {} )
-		YAML::quick_emit( object_id, opts ) do |out|
+		YAML::quick_emit( self, opts ) do |out|
             tz = "Z"
             # from the tidy Tobias Peters <t-peters@g...> Thanks!
             unless self.utc?
@@ -347,7 +347,7 @@
 class Date
     yaml_as "tag:yaml.org,2002:timestamp#ymd"
 	def to_yaml( opts = {} )
-		YAML::quick_emit( object_id, opts ) do |out|
+		YAML::quick_emit( self, opts ) do |out|
             out.scalar( "tag:yaml.org,2002:timestamp", self.to_s, :plain )
         end
 	end
Index: ruby_1_8/test/yaml/test_yaml.rb
===================================================================
--- ruby_1_8/test/yaml/test_yaml.rb	(revision 16081)
+++ ruby_1_8/test/yaml/test_yaml.rb	(revision 16082)
@@ -1272,6 +1272,14 @@
       assert_equal([{}], o.keys)
     end
 
+    #
+    # contributed by riley lynch [ruby-Bugs-8548]
+    #
+    def test_object_id_collision
+      omap = YAML::Omap.new
+      1000.times { |i| omap["key_#{i}"] = { "value" => i } }
+      raise "id collision in ordered map" if omap.to_yaml =~ /id\d+/
+    end
 end
 
 if $0 == __FILE__

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

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