* ruby.c (ruby_init_loadpath_safe): mark initial load paths.

* gem_prelude.rb (push_all_highest_version_gems_on_load_path):
  search insertion position by initial load path mark.

* lib/rubygems.rb (Gem.load_path_insert_index): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-03-12 15:11:10 +00:00
parent 614619031b
commit 04e68d0107
5 changed files with 17 additions and 21 deletions

View File

@ -1,3 +1,12 @@
Sat Mar 13 00:11:05 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (ruby_init_loadpath_safe): mark initial load paths.
* gem_prelude.rb (push_all_highest_version_gems_on_load_path):
search insertion position by initial load path mark.
* lib/rubygems.rb (Gem.load_path_insert_index): ditto.
Fri Mar 12 21:34:00 2010 Kenta Murata <mrkn@mrkn.jp> Fri Mar 12 21:34:00 2010 Kenta Murata <mrkn@mrkn.jp>
* NEWS: emoji encodings. * NEWS: emoji encodings.

View File

@ -267,7 +267,7 @@ if defined?(Gem) then
require_paths.first.instance_variable_set(:@gem_prelude_index, true) require_paths.first.instance_variable_set(:@gem_prelude_index, true)
end end
# gem directories must come after -I and ENV['RUBYLIB'] # gem directories must come after -I and ENV['RUBYLIB']
$:[$:.index(ConfigMap[:sitelibdir]),0] = require_paths $:[$:.index{|e|e.instance_variable_defined?(:@gem_prelude_index)}||-1,0] = require_paths
end end
def const_missing(constant) def const_missing(constant)

View File

@ -254,8 +254,6 @@ module Gem
File.join spec.full_gem_path, path File.join spec.full_gem_path, path
end end
sitelibdir = ConfigMap[:sitelibdir]
# gem directories must come after -I and ENV['RUBYLIB'] # gem directories must come after -I and ENV['RUBYLIB']
insert_index = load_path_insert_index insert_index = load_path_insert_index
@ -570,23 +568,9 @@ module Gem
## ##
# The index to insert activated gem paths into the $LOAD_PATH. # The index to insert activated gem paths into the $LOAD_PATH.
#
# Defaults to the site lib directory unless gem_prelude.rb has loaded paths,
# then it inserts the activated gem's paths before the gem_prelude.rb paths
# so you can override the gem_prelude.rb default $LOAD_PATH paths.
def self.load_path_insert_index def self.load_path_insert_index
index = $LOAD_PATH.index ConfigMap[:sitelibdir] $LOAD_PATH.index {|path| path.instance_variable_defined?(:@gem_prelude_index)}
$LOAD_PATH.each_with_index do |path, i|
if path.instance_variables.include?(:@gem_prelude_index) or
path.instance_variables.include?('@gem_prelude_index') then
index = i
break
end
end
index
end end
## ##

7
ruby.c
View File

@ -339,6 +339,7 @@ void
ruby_init_loadpath_safe(int safe_level) ruby_init_loadpath_safe(int safe_level)
{ {
VALUE load_path; VALUE load_path;
ID id_initial_load_path_mark;
extern const char ruby_initial_load_paths[]; extern const char ruby_initial_load_paths[];
const char *paths = ruby_initial_load_paths; const char *paths = ruby_initial_load_paths;
#if defined LOAD_RELATIVE #if defined LOAD_RELATIVE
@ -432,16 +433,18 @@ ruby_init_loadpath_safe(int safe_level)
#define RUBY_RELATIVE(path, len) rubylib_mangled_path(path, len) #define RUBY_RELATIVE(path, len) rubylib_mangled_path(path, len)
#define PREFIX_PATH() rubylib_mangled_path(RUBY_LIB_PREFIX, sizeof(RUBY_LIB_PREFIX)-1) #define PREFIX_PATH() rubylib_mangled_path(RUBY_LIB_PREFIX, sizeof(RUBY_LIB_PREFIX)-1)
#endif #endif
#define incpush(path) rb_ary_push(load_path, (path))
load_path = GET_VM()->load_path; load_path = GET_VM()->load_path;
if (safe_level == 0) { if (safe_level == 0) {
ruby_push_include(getenv("RUBYLIB"), identical_path); ruby_push_include(getenv("RUBYLIB"), identical_path);
} }
id_initial_load_path_mark = rb_intern_const("@gem_prelude_index");
while (*paths) { while (*paths) {
size_t len = strlen(paths); size_t len = strlen(paths);
incpush(RUBY_RELATIVE(paths, len)); VALUE path = RUBY_RELATIVE(paths, len);
rb_ivar_set(path, id_initial_load_path_mark, path);
rb_ary_push(load_path, path);
paths += len + 1; paths += len + 1;
} }

View File

@ -48,7 +48,7 @@ class Prelude
key = $1 key = $1
unless @mkconf unless @mkconf
require './rbconfig' require './rbconfig'
@mkconf = RbConfig::MAKEFILE_CONFIG.merge('rubylibprefix'=>'#{TMP_RUBY_PREFIX}') @mkconf = RbConfig::MAKEFILE_CONFIG.merge('prefix'=>'#{TMP_RUBY_PREFIX}')
end end
if RbConfig::MAKEFILE_CONFIG.has_key? key if RbConfig::MAKEFILE_CONFIG.has_key? key
val = RbConfig.expand("$(#{key})", @mkconf) val = RbConfig.expand("$(#{key})", @mkconf)