summaryrefslogtreecommitdiff
path: root/lib/rubygems/core_ext
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/core_ext')
-rw-r--r--lib/rubygems/core_ext/kernel_require.rb78
-rw-r--r--lib/rubygems/core_ext/kernel_warn.rb17
-rw-r--r--lib/rubygems/core_ext/tcpsocket_init.rb4
3 files changed, 41 insertions, 58 deletions
diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb
index d92b3429e4..3a9bdbdc9d 100644
--- a/lib/rubygems/core_ext/kernel_require.rb
+++ b/lib/rubygems/core_ext/kernel_require.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -35,53 +36,48 @@ module Kernel
def require(path) # :doc:
return gem_original_require(path) unless Gem.discover_gems_on_require
- begin
- RUBYGEMS_ACTIVATION_MONITOR.enter
+ RUBYGEMS_ACTIVATION_MONITOR.synchronize do
+ path = File.path(path)
+
+ # If +path+ belongs to a default gem, we activate it and then go straight
+ # to normal require
+
+ if spec = Gem.find_default_spec(path)
+ name = spec.name
- path = path.to_path if path.respond_to? :to_path
+ next if Gem.loaded_specs[name]
- if spec = Gem.find_unresolved_default_spec(path)
# Ensure -I beats a default gem
resolved_path = begin
rp = nil
load_path_check_index = Gem.load_path_insert_index - Gem.activated_gem_paths
- Gem.suffixes.each do |s|
- $LOAD_PATH[0...load_path_check_index].each do |lp|
- safe_lp = lp.dup.tap(&Gem::UNTAINT)
- begin
- if File.symlink? safe_lp # for backward compatibility
- next
- end
- rescue SecurityError
- RUBYGEMS_ACTIVATION_MONITOR.exit
- raise
+ Gem.suffixes.find do |s|
+ $LOAD_PATH[0...load_path_check_index].find do |lp|
+ if File.symlink? lp # for backward compatibility
+ next
end
- full_path = File.expand_path(File.join(safe_lp, "#{path}#{s}"))
- if File.file?(full_path)
- rp = full_path
- break
- end
+ full_path = File.expand_path(File.join(lp, "#{path}#{s}"))
+ rp = full_path if File.file?(full_path)
end
- break if rp
end
rp
end
- begin
- Kernel.send(:gem, spec.name, Gem::Requirement.default_prerelease)
- rescue Exception
- RUBYGEMS_ACTIVATION_MONITOR.exit
- raise
- end unless resolved_path
+ next if resolved_path
+
+ Kernel.send(:gem, name, Gem::Requirement.default_prerelease)
+
+ Gem.load_bundler_extensions(Gem.loaded_specs[name].version) if name == "bundler"
+
+ next
end
# If there are no unresolved deps, then we can use just try
# normal require handle loading a gem from the rescue below.
if Gem::Specification.unresolved_deps.empty?
- RUBYGEMS_ACTIVATION_MONITOR.exit
- return gem_original_require(path)
+ next
end
# If +path+ is for a gem that has already been loaded, don't
@@ -91,8 +87,7 @@ module Kernel
# TODO request access to the C implementation of this to speed up RubyGems
if Gem::Specification.find_active_stub_by_path(path)
- RUBYGEMS_ACTIVATION_MONITOR.exit
- return gem_original_require(path)
+ next
end
# Attempt to find +path+ in any unresolved gems...
@@ -112,9 +107,7 @@ module Kernel
if found_specs.empty?
found_specs = Gem::Specification.find_in_unresolved_tree path
- found_specs.each do |found_spec|
- found_spec.activate
- end
+ found_specs.each(&:activate)
# We found +path+ directly in an unresolved gem. Now we figure out, of
# the possible found specs, which one we should activate.
@@ -125,7 +118,6 @@ module Kernel
names = found_specs.map(&:name).uniq
if names.size > 1
- RUBYGEMS_ACTIVATION_MONITOR.exit
raise Gem::LoadError, "#{path} found in multiple gems: #{names.join ", "}"
end
@@ -136,26 +128,20 @@ module Kernel
unless valid
le = Gem::LoadError.new "unable to find a version of '#{names.first}' to activate"
le.name = names.first
- RUBYGEMS_ACTIVATION_MONITOR.exit
raise le
end
valid.activate
end
+ end
- RUBYGEMS_ACTIVATION_MONITOR.exit
- return gem_original_require(path)
+ begin
+ gem_original_require(path)
rescue LoadError => load_error
- if load_error.path == path
- RUBYGEMS_ACTIVATION_MONITOR.enter
-
- begin
- require_again = Gem.try_activate(path)
- ensure
- RUBYGEMS_ACTIVATION_MONITOR.exit
- end
+ if load_error.path == path &&
+ RUBYGEMS_ACTIVATION_MONITOR.synchronize { Gem.try_activate(path) }
- return gem_original_require(path) if require_again
+ return gem_original_require(path)
end
raise load_error
diff --git a/lib/rubygems/core_ext/kernel_warn.rb b/lib/rubygems/core_ext/kernel_warn.rb
index 2dadf1fcd8..f806b77fab 100644
--- a/lib/rubygems/core_ext/kernel_warn.rb
+++ b/lib/rubygems/core_ext/kernel_warn.rb
@@ -13,11 +13,7 @@ module Kernel
module_function define_method(:warn) {|*messages, **kw|
unless uplevel = kw[:uplevel]
- if Gem.java_platform? && RUBY_VERSION < "3.1"
- return original_warn.bind(self).call(*messages)
- else
- return original_warn.bind(self).call(*messages, **kw)
- end
+ return original_warn.bind_call(self, *messages, **kw)
end
# Ensure `uplevel` fits a `long`
@@ -35,16 +31,15 @@ module Kernel
start += 1
- if path = loc.path
- unless path.start_with?(rubygems_path, "<internal:")
- # Non-rubygems frames
- uplevel -= 1
- end
+ next unless path = loc.path
+ unless path.start_with?(rubygems_path, "<internal:")
+ # Non-rubygems frames
+ uplevel -= 1
end
end
kw[:uplevel] = start
end
- original_warn.bind(self).call(*messages, **kw)
+ original_warn.bind_call(self, *messages, **kw)
}
end
diff --git a/lib/rubygems/core_ext/tcpsocket_init.rb b/lib/rubygems/core_ext/tcpsocket_init.rb
index c9e0a92953..018c49dbeb 100644
--- a/lib/rubygems/core_ext/tcpsocket_init.rb
+++ b/lib/rubygems/core_ext/tcpsocket_init.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "socket"
module CoreExtensions
@@ -17,7 +19,7 @@ module CoreExtensions
cond_var = Thread::ConditionVariable.new
Addrinfo.foreach(host, serv, nil, :STREAM) do |addr|
- Thread.report_on_exception = false if defined? Thread.report_on_exception = ()
+ Thread.report_on_exception = false
threads << Thread.new(addr) do
# give head start to ipv6 addresses