Skip to content

Commit

Permalink
Fix infinite loop caused by re-encountering superclass
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed May 14, 2011
1 parent ee4be25 commit 1d3f389
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
5 changes: 5 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
=== 3.6.1

* Bug fixes
* Fix infinite loop created when re-encountering BasicObject.

=== 3.6 / 2011-05-13

* Major Enhancements
Expand Down
6 changes: 6 additions & 0 deletions lib/rdoc/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ def add_class class_type, given_name, superclass = '::Object'
end
end

# fix up superclass
superclass = nil if full_name == 'BasicObject'
superclass = nil if full_name == 'Object' and defined?(::BasicObject)
superclass = '::BasicObject' if
defined?(::BasicObject) and full_name == 'Object'

# find the superclass full name
if superclass then
if superclass =~ /^:+/ then
Expand Down
32 changes: 32 additions & 0 deletions test/test_rdoc_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,38 @@ def test_add_class
assert_includes RDoc::TopLevel.classes.map { |k| k.full_name }, 'C1::Klass'
end

def test_add_class_basic_object
skip 'BasicObject is 1.9 only' unless defined?(BasicObject)

@xref_data.add_class RDoc::NormalClass, 'BasicObject'

basic = @xref_data.find_module_named 'BasicObject'

assert_nil basic.superclass

@c1.add_class RDoc::NormalClass, 'BasicObject'

basic = @c1.find_module_named 'BasicObject'

assert_equal 'Object', basic.superclass
end

def test_add_class_object
root_class = defined?(BasicObject) ? 'BasicObject' : nil

@xref_data.add_class RDoc::NormalClass, 'Object'

object = @xref_data.find_module_named 'Object'

assert_equal root_class, object.superclass

@c1.add_class RDoc::NormalClass, 'Object'

object = @c1.find_module_named 'Object'

assert_equal 'Object', object.superclass.full_name
end

def test_add_class_superclass
@c1.add_class RDoc::NormalClass, 'Klass', 'Object'
@c1.add_class RDoc::NormalClass, 'Klass', 'Other'
Expand Down
10 changes: 8 additions & 2 deletions test/test_rdoc_ri_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ def test_save_cache
},
}

expected[:ancestors]['Object'] = %w[BasicObject] if defined?(::BasicObject)

open File.join(@tmpdir, 'cache.ri'), 'rb' do |io|
cache = Marshal.load io.read

Expand Down Expand Up @@ -250,8 +252,10 @@ def test_save_class
assert_directory File.join(@tmpdir, 'Object')
assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri')

object_ancestors = defined?(::BasicObject) ? %w[BasicObject] : []

assert_cache({}, {}, { 'Object' => ['attr_accessor attr'] }, %w[Object],
'Object' => %w[])
'Object' => object_ancestors)

assert_equal @klass, @s.load_class('Object')
end
Expand Down Expand Up @@ -303,8 +307,10 @@ def test_save_class_methods
assert_directory File.join(@tmpdir, 'Object')
assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri')

object_ancestors = defined?(::BasicObject) ? %w[BasicObject] : []

assert_cache({}, {}, { 'Object' => ['attr_accessor attr'] }, %w[Object],
'Object' => %w[])
'Object' => object_ancestors)

assert_equal @klass, @s.load_class('Object')
end
Expand Down

0 comments on commit 1d3f389

Please sign in to comment.