Skip to content

Commit

Permalink
Showing 181 changed files with 482 additions and 775 deletions.
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -702,14 +702,15 @@ private RootNode addGetsLoop(RootNode oldRoot, boolean printing, boolean process

if (processLineEndings) whileBody.add(new CallNode(pos, dollarUnderscore, "chop!", null, null));
if (split) whileBody.add(new GlobalAsgnNode(pos, "$F", new CallNode(pos, dollarUnderscore, "split", null, null)));
if (printing) whileBody.add(new FCallNode(pos, "puts", new ArrayNode(pos, dollarUnderscore), null));

if (oldRoot.getBodyNode() instanceof BlockNode) { // common case n stmts
whileBody.addAll(oldRoot.getBodyNode());
whileBody.addAll(((BlockNode) oldRoot.getBodyNode()));
} else { // single expr script
whileBody.add(oldRoot.getBodyNode());
}

if (printing) whileBody.add(new FCallNode(pos, "puts", new ArrayNode(pos, dollarUnderscore), null));

return new RootNode(pos, oldRoot.getScope(), newBody, oldRoot.getFile());
}

111 changes: 89 additions & 22 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -128,6 +128,10 @@ public static RubyModule createKernelModule(Ruby runtime) {
runtime.setSuperMethodMissing(new MethodMissingMethod(module, PUBLIC, CallType.SUPER));
runtime.setNormalMethodMissing(new MethodMissingMethod(module, PUBLIC, CallType.NORMAL));

if (runtime.getInstanceConfig().isAssumeLoop()) {
module.defineAnnotatedMethods(LoopMethods.class);
}

recacheBuiltinMethods(runtime);

return module;
@@ -1734,28 +1738,6 @@ public static IRubyObject fork19(ThreadContext context, IRubyObject recv, Block
throw runtime.newNotImplementedError("fork is not available on this platform");
}

@JRubyMethod(module = true, visibility = PRIVATE, reads = LASTLINE, writes = LASTLINE)
public static IRubyObject gsub(ThreadContext context, IRubyObject recv, IRubyObject arg0, Block block) {
RubyString str = (RubyString) getLastlineString(context, context.runtime).dup();

if (!str.gsub_bang(context, arg0, block).isNil()) {
context.setLastLine(str);
}

return str;
}

@JRubyMethod(module = true, visibility = PRIVATE, reads = LASTLINE, writes = LASTLINE)
public static IRubyObject gsub(ThreadContext context, IRubyObject recv, IRubyObject arg0, IRubyObject arg1, Block block) {
RubyString str = (RubyString) getLastlineString(context, context.runtime).dup();

if (!str.gsub_bang(context, arg0, arg1, block).isNil()) {
context.setLastLine(str);
}

return str;
}

@JRubyMethod(module = true)
public static IRubyObject tap(ThreadContext context, IRubyObject recv, Block block) {
block.yield(context, recv);
@@ -2061,6 +2043,91 @@ public static RubyArray instance_variables19(ThreadContext context, IRubyObject
}
/* end delegated bindings */

public static IRubyObject gsub(ThreadContext context, IRubyObject recv, IRubyObject arg0, Block block) {
RubyString str = (RubyString) getLastlineString(context, context.runtime).dup();

if (!str.gsub_bang(context, arg0, block).isNil()) {
context.setLastLine(str);
}

return str;
}

public static IRubyObject gsub(ThreadContext context, IRubyObject recv, IRubyObject arg0, IRubyObject arg1, Block block) {
RubyString str = (RubyString) getLastlineString(context, context.runtime).dup();

if (!str.gsub_bang(context, arg0, arg1, block).isNil()) {
context.setLastLine(str);
}

return str;
}

public static class LoopMethods {
@JRubyMethod(module = true, visibility = PRIVATE, reads = LASTLINE, writes = LASTLINE)
public static IRubyObject gsub(ThreadContext context, IRubyObject recv, IRubyObject arg0, Block block) {
RubyString str = getLastlineString(context, context.runtime);

context.setLastLine(str.gsub(context, arg0, block));

return str;
}

@JRubyMethod(module = true, visibility = PRIVATE, reads = LASTLINE, writes = LASTLINE)
public static IRubyObject gsub(ThreadContext context, IRubyObject recv, IRubyObject arg0, IRubyObject arg1, Block block) {
RubyString str = getLastlineString(context, context.runtime);

context.setLastLine(str.gsub(context, arg0, arg1, block));

return str;
}

@JRubyMethod(module = true, visibility = PRIVATE, reads = LASTLINE, writes = LASTLINE)
public static IRubyObject sub(ThreadContext context, IRubyObject recv, IRubyObject arg0, Block block) {
RubyString str = getLastlineString(context, context.runtime);

context.setLastLine(str.sub(context, arg0, block));

return str;
}

@JRubyMethod(module = true, visibility = PRIVATE, reads = LASTLINE, writes = LASTLINE)
public static IRubyObject sub(ThreadContext context, IRubyObject recv, IRubyObject arg0, IRubyObject arg1, Block block) {
RubyString str = getLastlineString(context, context.runtime);

context.setLastLine(str.sub(context, arg0, arg1, block));

return str;
}

@JRubyMethod(module = true, visibility = PRIVATE, reads = LASTLINE, writes = LASTLINE)
public static IRubyObject chop(ThreadContext context, IRubyObject recv) {
RubyString str = getLastlineString(context, context.runtime);

context.setLastLine(str.chop(context));

return str;
}

@JRubyMethod(module = true, visibility = PRIVATE, reads = LASTLINE, writes = LASTLINE)
public static IRubyObject chomp(ThreadContext context, IRubyObject recv) {
RubyString str = getLastlineString(context, context.runtime);

context.setLastLine(str.chomp(context));

return str;
}

@JRubyMethod(module = true, visibility = PRIVATE, reads = LASTLINE, writes = LASTLINE)
public static IRubyObject chomp(ThreadContext context, IRubyObject recv, IRubyObject arg0) {
RubyString str = getLastlineString(context, context.runtime);

context.setLastLine(str.chomp(context, arg0));

return str;
}
}

@Deprecated
public static IRubyObject methodMissing(ThreadContext context, IRubyObject recv, String name, Visibility lastVis, CallType lastCallType, IRubyObject[] args, Block block) {
return methodMissing(context, recv, name, lastVis, lastCallType, args);
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ public IRubyObject invoke(ThreadContext context, IRubyObject caller, IRubyObject

updateInvocationTarget(mh, self, selfClass, method, switchPoint);

return ((RubyHash) self).fastARef(args[0]);
return ((RubyHash) self).op_aref(context, args[0]);
} else {
// slow path follows normal invoke logic with a strDup for the key
SwitchPoint switchPoint = (SwitchPoint) selfClass.getInvalidator().getData();
1 change: 0 additions & 1 deletion lib/ruby/stdlib/gauntlet_rubygems.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems'
require 'gauntlet'

60 changes: 10 additions & 50 deletions lib/ruby/stdlib/rubygems.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
# -*- ruby -*-
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
@@ -10,7 +9,7 @@
require 'thread'

module Gem
VERSION = '2.6.1'
VERSION = '2.5.1'
end

# Must be first since it unloads the prelude from 1.9.2
@@ -174,14 +173,6 @@ module Gem
@pre_reset_hooks ||= []
@post_reset_hooks ||= []

def self.env_requirement(gem_name)
@env_requirements_by_name ||= {}
@env_requirements_by_name[gem_name] ||= begin
req = ENV["GEM_REQUIREMENT_#{gem_name.upcase}"] || '>= 0'.freeze
Gem::Requirement.create(req)
end
end

##
# Try to activate a gem containing +path+. Returns true if
# activation succeeded or wasn't needed because it was already
@@ -200,13 +191,8 @@ def self.try_activate path

begin
spec.activate
rescue Gem::LoadError => e # this could fail due to gem dep collisions, go lax
spec_by_name = Gem::Specification.find_by_name(spec.name)
if spec_by_name.nil?
raise e
else
spec_by_name.activate
end
rescue Gem::LoadError # this could fail due to gem dep collisions, go lax
Gem::Specification.find_by_name(spec.name).activate
end

return true
@@ -252,7 +238,7 @@ def self.bin_path(name, exec_name = nil, *requirements)
specs = dep.matching_specs(true)

raise Gem::GemNotFoundException,
"can't find gem #{dep}" if specs.empty?
"can't find gem #{name} (#{requirements})" if specs.empty?

specs = specs.find_all { |spec|
spec.executables.include? exec_name
@@ -339,38 +325,16 @@ def self.deflate(data)
# lookup files.

def self.paths
@paths ||= Gem::PathSupport.new(ENV)
@paths ||= Gem::PathSupport.new
end

# Initialize the filesystem paths to use from +env+.
# +env+ is a hash-like object (typically ENV) that
# is queried for 'GEM_HOME', 'GEM_PATH', and 'GEM_SPEC_CACHE'
# Keys for the +env+ hash should be Strings, and values of the hash should
# be Strings or +nil+.

def self.paths=(env)
clear_paths
target = {}
env.each_pair do |k,v|
case k
when 'GEM_HOME', 'GEM_PATH', 'GEM_SPEC_CACHE'
case v
when nil, String
target[k] = v
when Array
unless Gem::Deprecate.skip
warn <<-eowarn
Array values in the parameter are deprecated. Please use a String or nil.
An Array was passed in from #{caller[3]}
eowarn
end
target[k] = v.join File::PATH_SEPARATOR
end
else
target[k] = v
end
end
@paths = Gem::PathSupport.new ENV.to_hash.merge(target)
@paths = Gem::PathSupport.new env
Gem::Specification.dirs = @paths.path
end

@@ -465,9 +429,7 @@ def self.find_files(glob, check_load_path=true)

files = find_files_from_load_path glob if check_load_path

gem_specifications = @gemdeps ? Gem.loaded_specs.values : Gem::Specification.stubs

files.concat gem_specifications.map { |spec|
files.concat Gem::Specification.stubs.map { |spec|
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
}.flatten

@@ -976,11 +938,9 @@ def self.ui
# by the unit tests to provide environment isolation.

def self.use_paths(home, *paths)
paths.flatten!
paths.compact!
hash = { "GEM_HOME" => home, "GEM_PATH" => paths.empty? ? home : paths.join(File::PATH_SEPARATOR) }
hash.delete_if { |_, v| v.nil? }
self.paths = hash
paths = nil if paths == [nil]
paths = paths.first if Array === Array(paths).first
self.paths = { "GEM_HOME" => home, "GEM_PATH" => paths }
end

##
1 change: 0 additions & 1 deletion lib/ruby/stdlib/rubygems/available_set.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
class Gem::AvailableSet

include Enumerable
11 changes: 6 additions & 5 deletions lib/ruby/stdlib/rubygems/basic_specification.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
# BasicSpecification is an abstract class which implements some common code
# used by both Specification and StubSpecification.
@@ -95,7 +94,7 @@ def extension_dir
# Returns path to the extensions directory.

def extensions_dir
Gem.default_ext_dir_for(base_dir) ||
@extensions_dir ||= Gem.default_ext_dir_for(base_dir) ||
File.join(base_dir, 'extensions', Gem::Platform.local.to_s,
Gem.extension_api_version)
end
@@ -125,9 +124,9 @@ def full_gem_path

def full_name
if platform == Gem::Platform::RUBY or platform.nil? then
"#{name}-#{version}".dup.untaint
"#{name}-#{version}".untaint
else
"#{name}-#{version}-#{platform}".dup.untaint
"#{name}-#{version}-#{platform}".untaint
end
end

@@ -196,6 +195,7 @@ def gems_dir

def internal_init # :nodoc:
@extension_dir = nil
@extensions_dir = nil
@full_gem_path = nil
@gem_dir = nil
@ignored = nil
@@ -281,7 +281,7 @@ def lib_dirs_glob
self.require_paths.first
end

"#{self.full_gem_path}/#{dirs}".dup.untaint
"#{self.full_gem_path}/#{dirs}".untaint
end

##
@@ -325,3 +325,4 @@ def have_file? file, suffixes
end

end

18 changes: 3 additions & 15 deletions lib/ruby/stdlib/rubygems/command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -154,7 +153,7 @@ def execute

def show_lookup_failure(gem_name, version, errors, domain)
if errors and !errors.empty?
msg = "Could not find a valid gem '#{gem_name}' (#{version}), here is why:\n".dup
msg = "Could not find a valid gem '#{gem_name}' (#{version}), here is why:\n"
errors.each { |x| msg << " #{x.wordy}\n" }
alert_error msg
else
@@ -300,8 +299,6 @@ def invoke_with_build_args(args, build_args)

options[:build_args] = build_args

self.ui = Gem::SilentUI.new if options[:silent]

if options[:help] then
show_help
elsif @when_invoked then
@@ -522,15 +519,10 @@ def wrap(text, width) # :doc:
end
end

add_common_option('-q', '--quiet', 'Silence command progress meter') do |value, options|
add_common_option('-q', '--quiet', 'Silence commands') do |value, options|
Gem.configuration.verbose = false
end

add_common_option("--silent",
"Silence rubygems output") do |value, options|
options[:silent] = true
end

# Backtrace and config-file are added so they show up in the help
# commands. Both options are actually handled before the other
# options get parsed.
@@ -547,11 +539,6 @@ def wrap(text, width) # :doc:
'Turn on Ruby debugging') do
end

add_common_option('--norc',
'Avoid loading any .gemrc file') do
end


# :stopdoc:

HELP = <<-HELP
@@ -592,3 +579,4 @@ def wrap(text, width) # :doc:

module Gem::Commands
end

1 change: 0 additions & 1 deletion lib/ruby/stdlib/rubygems/command_manager.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
Loading

0 comments on commit 28a9f53

Please sign in to comment.