Skip to content

Commit e826790

Browse files
committed
merge revision(s) 16082:
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_5@17244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 1033db9 commit e826790

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Sun Jun 15 22:10:14 2008 Akinori MUSHA <knu@iDaemons.org>
2+
3+
* lib/yaml/types.rb: Likewise, pass self to YAML::quick_emit;
4+
merged from 1.9.
5+
6+
* lib/yaml.rb (quick_emit): use combination of object_id and hash to
7+
identify repeated object references, since GC will reuse memory of
8+
objects during output of YAML. [ruby-Bugs-8548] [ruby-Bugs-3698];
9+
merged from 1.9.
10+
111
Sun Jun 15 22:05:45 2008 Akinori MUSHA <knu@iDaemons.org>
212

313
* ext/syck/rubyext.c: Node#value defined twice.

lib/yaml.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ def YAML.quick_emit( oid, opts = {}, &e )
384384
else
385385
emitter.reset( opts )
386386
end
387+
oid =
388+
case oid when Fixnum, NilClass; oid
389+
else oid = "#{oid.object_id}-#{oid.hash}"
390+
end
387391
out.emit( oid, &e )
388392
end
389393

lib/yaml/rubytypes.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Object
1212
def to_yaml_style; end
1313
def to_yaml_properties; instance_variables.sort; end
1414
def to_yaml( opts = {} )
15-
YAML::quick_emit( object_id, opts ) do |out|
15+
YAML::quick_emit( self, opts ) do |out|
1616
out.map( taguri, to_yaml_style ) do |map|
1717
to_yaml_properties.each do |m|
1818
map.add( m[1..-1], instance_variable_get( m ) )
@@ -35,7 +35,7 @@ def yaml_initialize( tag, val )
3535
end
3636
end
3737
def to_yaml( opts = {} )
38-
YAML::quick_emit( object_id, opts ) do |out|
38+
YAML::quick_emit( self, opts ) do |out|
3939
out.map( taguri, to_yaml_style ) do |map|
4040
each do |k, v|
4141
map.add( k, v )
@@ -83,7 +83,7 @@ def self.yaml_new( klass, tag, val )
8383
end
8484
end
8585
def to_yaml( opts = {} )
86-
YAML::quick_emit( object_id, opts ) do |out|
86+
YAML::quick_emit( self, opts ) do |out|
8787
#
8888
# Basic struct is passed as a YAML map
8989
#
@@ -104,7 +104,7 @@ class Array
104104
yaml_as "tag:yaml.org,2002:seq"
105105
def yaml_initialize( tag, val ); concat( val.to_a ); end
106106
def to_yaml( opts = {} )
107-
YAML::quick_emit( object_id, opts ) do |out|
107+
YAML::quick_emit( self, opts ) do |out|
108108
out.seq( taguri, to_yaml_style ) do |seq|
109109
each do |x|
110110
seq.add( x )
@@ -124,7 +124,7 @@ def Exception.yaml_new( klass, tag, val )
124124
o
125125
end
126126
def to_yaml( opts = {} )
127-
YAML::quick_emit( object_id, opts ) do |out|
127+
YAML::quick_emit( self, opts ) do |out|
128128
out.map( taguri, to_yaml_style ) do |map|
129129
map.add( 'message', message )
130130
to_yaml_properties.each do |m|
@@ -161,7 +161,7 @@ def String.yaml_new( klass, tag, val )
161161
end
162162
end
163163
def to_yaml( opts = {} )
164-
YAML::quick_emit( is_complex_yaml? ? object_id : nil, opts ) do |out|
164+
YAML::quick_emit( is_complex_yaml? ? self : nil, opts ) do |out|
165165
if is_binary_data?
166166
out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal )
167167
elsif to_yaml_properties.empty?
@@ -227,7 +227,7 @@ def Range.yaml_new( klass, tag, val )
227227
end
228228
end
229229
def to_yaml( opts = {} )
230-
YAML::quick_emit( object_id, opts ) do |out|
230+
YAML::quick_emit( self, opts ) do |out|
231231
# if self.begin.is_complex_yaml? or self.begin.respond_to? :to_str or
232232
# self.end.is_complex_yaml? or self.end.respond_to? :to_str or
233233
# not to_yaml_properties.empty?
@@ -310,7 +310,7 @@ def Time.yaml_new( klass, tag, val )
310310
end
311311
end
312312
def to_yaml( opts = {} )
313-
YAML::quick_emit( object_id, opts ) do |out|
313+
YAML::quick_emit( self, opts ) do |out|
314314
tz = "Z"
315315
# from the tidy Tobias Peters <t-peters@gmx.de> Thanks!
316316
unless self.utc?
@@ -347,7 +347,7 @@ def to_yaml( opts = {} )
347347
class Date
348348
yaml_as "tag:yaml.org,2002:timestamp#ymd"
349349
def to_yaml( opts = {} )
350-
YAML::quick_emit( object_id, opts ) do |out|
350+
YAML::quick_emit( self, opts ) do |out|
351351
out.scalar( "tag:yaml.org,2002:timestamp", self.to_s, :plain )
352352
end
353353
end

lib/yaml/types.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def to_yaml( opts = {} )
4545
class Object
4646
def self.tag_subclasses?; false; end
4747
def to_yaml( opts = {} )
48-
YAML::quick_emit( object_id, opts ) do |out|
48+
YAML::quick_emit( self, opts ) do |out|
4949
out.map( "tag:ruby.yaml.org,2002:object:#{ @class }", to_yaml_style ) do |map|
5050
@ivars.each do |k,v|
5151
map.add( k, v )
@@ -123,7 +123,7 @@ def is_complex_yaml?
123123
true
124124
end
125125
def to_yaml( opts = {} )
126-
YAML::quick_emit( self.object_id, opts ) do |out|
126+
YAML::quick_emit( self, opts ) do |out|
127127
out.seq( taguri, to_yaml_style ) do |seq|
128128
self.each do |v|
129129
seq.add( Hash[ *v ] )
@@ -173,7 +173,7 @@ def is_complex_yaml?
173173
true
174174
end
175175
def to_yaml( opts = {} )
176-
YAML::quick_emit( self.object_id, opts ) do |out|
176+
YAML::quick_emit( self, opts ) do |out|
177177
out.seq( taguri, to_yaml_style ) do |seq|
178178
self.each do |v|
179179
seq.add( Hash[ *v ] )

test/yaml/test_yaml.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,14 @@ def test_empty_map_key
12721272
assert_equal([{}], o.keys)
12731273
end
12741274

1275+
#
1276+
# contributed by riley lynch [ruby-Bugs-8548]
1277+
#
1278+
def test_object_id_collision
1279+
omap = YAML::Omap.new
1280+
1000.times { |i| omap["key_#{i}"] = { "value" => i } }
1281+
raise "id collision in ordered map" if omap.to_yaml =~ /id\d+/
1282+
end
12751283
end
12761284

12771285
if $0 == __FILE__

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define RUBY_RELEASE_DATE "2008-06-15"
33
#define RUBY_VERSION_CODE 185
44
#define RUBY_RELEASE_CODE 20080615
5-
#define RUBY_PATCHLEVEL 194
5+
#define RUBY_PATCHLEVEL 195
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8

0 commit comments

Comments
 (0)