Project

General

Profile

Feature #11140

Allow rubygems' `require` to handle `autoload` calls

Added by tenderlovemaking (Aaron Patterson) almost 4 years ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:69132]

Description

Right now, rubygems can't handle calls to autoload because autoload will directly call rb_require_safe rather than sending to Kernel::require.

For example:

class A
  autoload :B, 'a/b' # this is in a different Gem
end
A::B

The above code won't work because 'a/b' is in a different gem. I'd like to give rubygems the opportunity to handle requires made through autoload.

I've attached a patch that makes the change.


Files

call_send_on_autoload.diff (1.31 KB) call_send_on_autoload.diff tenderlovemaking (Aaron Patterson), 05/12/2015 12:24 AM

Associated revisions

Revision cd465d55
Added by tenderlove almost 4 years ago

  • 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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 50494
Added by tenderlovemaking (Aaron Patterson) almost 4 years ago

  • 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.

Revision 50494
Added by tenderlove almost 4 years ago

  • 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.

Revision 50494
Added by tenderlove almost 4 years ago

  • 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.

Revision 50494
Added by tenderlove almost 4 years ago

  • 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.

Revision 50494
Added by tenderlove almost 4 years ago

  • 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.

History

Updated by jeremyevans0 (Jeremy Evans) almost 4 years ago

Considering #5653, should we be making any changes to autoload to make it easier to use, if the intention is to remove it in ruby 3.0? I think before any improvements to autoload should be considered, we first need a firm decision from Matz on autoload's future in ruby.

If Matz decides that autoload will stay in ruby, I'm definitely in favor of autoload calling Kernel::require. But if autoload will be removed in ruby 3.0, I don't think we should make changes like this that would make autoload easier to use. That encourages people to use autoload, which will make updating to ruby 3.0 more painful when the time comes.

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Description updated (diff)

It sounds reasonable as -r option also calls Kernel#require method now.

Updated by matz (Yukihiro Matsumoto) almost 4 years ago

Accepted. Could you apply the patch, Aaron?

Matz.

#4

Updated by Anonymous almost 4 years ago

  • Status changed from Open to Closed

Applied in changeset r50494.


  • 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.

Updated by usa (Usaku NAKAMURA) almost 4 years ago

  • Status changed from Closed to Assigned
  • Assignee set to tenderlovemaking (Aaron Patterson)

Aaron, this commit breaks some tests on ruby/test_require.rb.
Check RubyCI.

#6

Updated by tenderlovemaking (Aaron Patterson) almost 4 years ago

Usaku NAKAMURA wrote:

Aaron, this commit breaks some tests on ruby/test_require.rb.
Check RubyCI.

usa (Usaku NAKAMURA) I'm looking in to it. It seems to be a bug with looking up activated features during autoload. :(

#7

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

Removed that garbage.

#8

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

Since this commit TestAutoload#test_threaded_accessing_constant continuously fails on some Linux distributions.
e.g.: http://rubyci.blob.core.windows.net/ubuntu1404/ruby-trunk/log/20150514T220002Z.fail.html.gz

Updated by tenderlovemaking (Aaron Patterson) 3 months ago

Is this still failing? I don't see it on RubyCI.org

Updated by hsbt (Hiroshi SHIBATA) about 1 month ago

  • Status changed from Assigned to Closed

This patch was already applied.

Also available in: Atom PDF