Skip to content

Commit

Permalink
Rubinius load file twice when first time developer require with .rb
Browse files Browse the repository at this point in the history
Before patch when user require file with .rb suffix Rubinius recognize
file as :ruby type and execute method :verify_load_path from
Rubinius::CodeLoader. In this method interpreter interate via $LOAD_PATH
and search for proper file. After that Rubinius add to $LOADED_FEATURES
relative path. But when developer require witout .rb suffix Rubinius
execute another method (because interpreter need guess extension).
Method without .rb suffix add to $LOADED_FEATURES only short file path.

Example

require 'ruby.rb'
$LOADED_FEATURES # => ["./ruby.rb"]

require 'ruby'
$LOAD_FEATURES # => ["ruby.rb"]

In this way, the interpreter can load file twice.

After patch:

require 'ruby.rb'
$LOADED_FEATURES # => ["ruby.rb"]

require 'ruby'
$LOAD_FEATURES # => ["ruby.rb"]

* Fixes #1788
* Fixes #1571
  • Loading branch information
LTe committed Jul 27, 2012
1 parent 1d8c8a1 commit 71a2efb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
22 changes: 0 additions & 22 deletions kernel/common/codeloader.rb
Expand Up @@ -249,28 +249,6 @@ def qualified_path?(path)
path[0] == ?/ or path.prefix?("./") or path.prefix?("../")
end

# Main logic for converting a name to an actual file to load. Used by
# #load and by #require when the file extension is provided.
#
# Expands any #home_path? to an absolute path. Then either checks whether
# an absolute path is #loadable? or searches for a loadable file matching
# name in $LOAD_PATH.
#
# Returns true if a loadable file is found, otherwise returns false.
def verify_load_path(path, loading=false)
path = File.expand_path path if home_path? path

if qualified_path? path
return false unless loadable? path
else
return false unless path = search_load_path(path, loading)
end

update_paths(path, path)

return true
end

# Called directly by #load. Either resolves the path passed to Kernel#load
# to a specific file or raises a LoadError.
def resolve_load_path
Expand Down
24 changes: 24 additions & 0 deletions kernel/common/codeloader18.rb
Expand Up @@ -25,5 +25,29 @@ def update_paths(file, path)
@file_path = path
@load_path = File.expand_path path
end

# Main logic for converting a name to an actual file to load. Used by
# #load and by #require when the file extension is provided.
#
# Expands any #home_path? to an absolute path. Then either checks whether
# an absolute path is #loadable? or searches for a loadable file matching
# name in $LOAD_PATH.
#
# Returns true if a loadable file is found, otherwise returns false.
def verify_load_path(path, loading=false)
path = File.expand_path path if home_path? path

if qualified_path? path
return false unless loadable? path
else
return false unless full_path = search_load_path(path, loading)
update_paths(path, full_path)
return true
end

update_paths(path, path)

return true
end
end
end
22 changes: 22 additions & 0 deletions kernel/common/codeloader19.rb
Expand Up @@ -40,5 +40,27 @@ def update_paths(file, path)
@file_path = path
@load_path = path
end

# Main logic for converting a name to an actual file to load. Used by
# #load and by #require when the file extension is provided.
#
# Expands any #home_path? to an absolute path. Then either checks whether
# an absolute path is #loadable? or searches for a loadable file matching
# name in $LOAD_PATH.
#
# Returns true if a loadable file is found, otherwise returns false.
def verify_load_path(path, loading=false)
path = File.expand_path path if home_path? path

if qualified_path? path
return false unless loadable? path
else
return false unless path = search_load_path(path, loading)
end

update_paths(path, path)

return true
end
end
end

0 comments on commit 71a2efb

Please sign in to comment.