Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3181

Show
Ignore:
Timestamp:
11/24/05 05:43:27 (3 years ago)
Author:
bitsweat
Message:

Sever infinite loop for mutual dependencies. Closes #2997.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/dependencies.rb

    r3176 r3181  
    4646      load_file_name = (file_name =~ /\.rb$/ ? file_name : "#{file_name}.rb") 
    4747 
    48       # Enable warnings iff this file has not been loaded before. 
    49       if history.include?(file_name) 
    50         load load_file_name 
    51       else 
    52         enable_warnings { load load_file_name } 
     48      # Record that we've seen this file *before* loading it to avoid an 
     49      # infinite loop with mutual dependencies. 
     50      loaded << file_name 
     51 
     52      begin 
     53        # Enable warnings iff this file has not been loaded before. 
     54        if history.include?(file_name) 
     55          load load_file_name 
     56        else 
     57          enable_warnings { load load_file_name } 
     58        end 
     59      rescue 
     60        loaded.delete file_name 
     61        raise 
    5362      end 
    5463    else 
     
    5665    end 
    5766 
    58     # Record that we've seen this file. 
    59     loaded  << file_name 
     67    # Record history *after* loading so first load gets warnings. 
    6068    history << file_name 
    6169  end 
  • trunk/activesupport/test/dependencies_test.rb

    r3169 r3181  
    8080    Dependencies.mechanism = old_mechanism 
    8181  end 
     82 
     83  def test_mutual_dependencies_dont_infinite_loop 
     84    $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/dependencies" 
     85    old_mechanism, Dependencies.mechanism = Dependencies.mechanism, :load 
     86 
     87    $mutual_dependencies_count = 0 
     88    assert_nothing_raised { require_dependency 'mutual_one' } 
     89    assert_equal 2, $mutual_dependencies_count 
     90 
     91    Dependencies.clear 
     92 
     93    $mutual_dependencies_count = 0 
     94    assert_nothing_raised { require_dependency 'mutual_two' } 
     95    assert_equal 2, $mutual_dependencies_count 
     96  ensure 
     97    $LOAD_PATH.shift 
     98    Dependencies.mechanism = old_mechanism 
     99  end 
    82100end 
  • trunk/activesupport/test/dependencies/raises_exception.rb

    r3169 r3181  
    11$raises_exception_load_count += 1 
    22raise 'Loading me failed, so do not add to loaded or history.' 
     3$raises_exception_load_count += 1