Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rubinius load file twice when first time developer require with .rb

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...
commit 71a2efbd6527be388b368572be974f5d2ebe7674 1 parent 1d8c8a1
@LTe authored
View
22 kernel/common/codeloader.rb
@@ -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
View
24 kernel/common/codeloader18.rb
@@ -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
View
22 kernel/common/codeloader19.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.