Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c677b61b9f59
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d5ed6a5c9e03
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Feb 28, 2016

  1. Check if feature is already loaded when require returns false in Auto…

    …load#resolve
    
    This solves the issue mentioned in 01a7c2f.
    ahmadsherif committed Feb 28, 2016
    Copy the full SHA
    abac6a4 View commit details
  2. Add a spec for autoloading a constant that was already loaded by anot…

    …her thread
    
    An explanation of the issue can be found in 01a7c2f.
    ahmadsherif committed Feb 28, 2016
    Copy the full SHA
    d5ed6a5 View commit details
2 changes: 1 addition & 1 deletion core/autoload.rb
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ def resolve
unless @loaded && @thread == Thread.current
@loaded = true
@thread = Thread.current
Rubinius::CodeLoader.require @path
Rubinius::CodeLoader.require @path or Rubinius::CodeLoader.feature_provided? @path
end
end
end
4 changes: 4 additions & 0 deletions spec/ruby/core/module/autoload_spec.rb
Original file line number Diff line number Diff line change
@@ -440,6 +440,10 @@ class ModuleSpecs::Autoload::Z < ModuleSpecs::Autoload::ZZ
ScratchPad.recorded.get.should == mod_count
end
end

it "loads the registered constant even if the constant was already loaded by another thread" do
Thread.new { ModuleSpecs::Autoload::FromThread::D.foo }.value.should == :foo
end
end

describe "Module#autoload" do
11 changes: 11 additions & 0 deletions spec/ruby/core/module/fixtures/autoload_abc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module ModuleSpecs::Autoload::FromThread
module A
class B
class C
def self.foo
:foo
end
end
end
end
end
1 change: 1 addition & 0 deletions spec/ruby/core/module/fixtures/autoload_empty.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file is left empty on purpose
16 changes: 16 additions & 0 deletions spec/ruby/core/module/fixtures/classes.rb
Original file line number Diff line number Diff line change
@@ -365,6 +365,22 @@ def self.use_ex1
return :good
end
end

module FromThread
module A
autoload :B, fixture(__FILE__, "autoload_empty.rb")

class B
autoload :C, fixture(__FILE__, "autoload_abc.rb")

def self.foo
C.foo
end
end
end

class D < A::B; end
end
end

# This class isn't inherited from or included in anywhere. It exists to test