Skip to content

Commit 16f91ee

Browse files
committed
Check that #require was redefined by RubyGems
* If not, we would end up in infinite recursion, so better fail fast. (cherry picked from commit 36b8a53)
1 parent a78e953 commit 16f91ee

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/truffle/truffle/lazy-rubygems.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
# Otherwise, --disable-gems would degrade startup which is counter-intuitive.
1111
Truffle::Boot.delay do
1212
if Truffle::Boot.get_option 'rubygems'
13+
module Truffle::LazyRubyGems
14+
end
15+
1316
module Kernel
1417
# Take this alias name so RubyGems will reuse this copy
1518
# and skip the method below once RubyGems is loaded.
@@ -20,10 +23,18 @@ module Kernel
2023
gem_original_require(path)
2124
rescue LoadError
2225
gem_original_require 'rubygems'
23-
require path
26+
27+
# Check that #require was redefined by RubyGems, otherwise we would end up in infinite recursion
28+
new_require = ::Kernel.instance_method(:require)
29+
if new_require == Truffle::LazyRubyGems::LAZY_REQUIRE
30+
raise 'RubyGems did not redefine #require as expected, make sure $LOAD_PATH and home are set correctly'
31+
end
32+
new_require.bind(self).call(path)
2433
end
2534
end
2635

36+
Truffle::LazyRubyGems::LAZY_REQUIRE = instance_method(:require)
37+
2738
private def gem(*args)
2839
require 'rubygems'
2940
gem(*args)

0 commit comments

Comments
 (0)