ruby-changes:38413
From: tenderlove <ko1@a...>
Date: Fri, 15 May 2015 06:57:52 +0900 (JST)
Subject: [ruby-changes:38413] tenderlove:r50494 (trunk): * variable.c: Change autoload to call `require` through Ruby rather
tenderlove 2015-05-15 06:57:33 +0900 (Fri, 15 May 2015) New Revision: 50494 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50494 Log: * variable.c: Change autoload to call `require` through Ruby rather than directly calling `rb_require_safe`. This allows things like RubyGems to intercept file loading done though `autoload`. [Feature #11140] * test/ruby/test_autoload.rb: Test for change. Modified files: trunk/ChangeLog trunk/test/ruby/test_autoload.rb trunk/variable.c Index: ChangeLog =================================================================== --- ChangeLog (revision 50493) +++ ChangeLog (revision 50494) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri May 15 06:54:19 2015 Aaron Patterson <tenderlove@r...> + + * variable.c: Change autoload to call `require` through Ruby rather + than directly calling `rb_require_safe`. This allows things like + RubyGems to intercept file loading done though `autoload`. + [Feature #11140] + + * test/ruby/test_autoload.rb: Test for change. + Wed Apr 8 19:18:02 2015 Shota Fukumori (sora_h) <her@s...> * enum.c (enum_grep_v, grep_i, grep_iter_i, Init_enum): Index: variable.c =================================================================== --- variable.c (revision 50493) +++ variable.c (revision 50494) @@ -1803,7 +1803,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/variable.c#L1803 autoload_require(VALUE arg) { struct autoload_data_i *ele = (struct autoload_data_i *)arg; - return rb_require_safe(ele->feature, ele->safe_level); + return rb_funcall(rb_vm_top_self(), rb_intern("require"), 1, ele->feature); } static VALUE Index: test/ruby/test_autoload.rb =================================================================== --- test/ruby/test_autoload.rb (revision 50493) +++ test/ruby/test_autoload.rb (revision 50494) @@ -161,6 +161,31 @@ p Foo::Bar https://github.com/ruby/ruby/blob/trunk/test/ruby/test_autoload.rb#L161 } end + def test_require_implemented_in_ruby_is_called + Kernel.module_eval do; alias :old_require :require; end + + called_with = [] + Kernel.send :define_method, :require do |path| + called_with << path + old_require path + end + + Tempfile.create(['autoload', '.rb']) {|file| + file.puts 'class AutoloadTest; end' + file.close + add_autoload(file.path) + begin + assert(Object::AutoloadTest) + ensure + remove_autoload_constant + end + assert_equal [file.path], called_with + } + + ensure + Kernel.module_eval do; alias :require :old_require; undef :old_require; end + end + def add_autoload(path) (@autoload_paths ||= []) << path eval <<-END -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/