Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bootstraptest/test_ractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1534,10 +1534,10 @@ class C
}

assert_equal '1', %q{
N = 1_000
N = 100
Ractor.new{
a = []
1_000.times.map{|i|
100.times.map{|i|
Thread.new(i){|i|
Thread.pass if i < N
a << Ractor.store_if_absent(:i){ i }
Expand Down
26 changes: 24 additions & 2 deletions gc/default/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -8586,10 +8586,32 @@ gc_enter_count(enum gc_enter_event event)

static bool current_process_time(struct timespec *ts);

/* A gc phase must be timed on the collecting thread's own cpu. A local gc runs
* while the other ractors keep going, and process cpu time counts their work as
* gc: with eight busy ractors the same ten collections were reported as 131ms
* instead of 3ms, more than the wall clock they ran in. The kernel also answers
* this one without walking every thread in the process. */
static bool
current_thread_time(struct timespec *ts)
{
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_THREAD_CPUTIME_ID)
{
static int try_clock_gettime = 1;
if (try_clock_gettime && clock_gettime(CLOCK_THREAD_CPUTIME_ID, ts) == 0) {
return true;
}
else {
try_clock_gettime = 0;
}
}
#endif
return current_process_time(ts);
}

static void
gc_clock_start(struct timespec *ts)
{
if (!current_process_time(ts)) {
if (!current_thread_time(ts)) {
ts->tv_sec = 0;
ts->tv_nsec = 0;
}
Expand All @@ -8601,7 +8623,7 @@ gc_clock_end(struct timespec *ts)
struct timespec end_time;

if ((ts->tv_sec > 0 || ts->tv_nsec > 0) &&
current_process_time(&end_time) &&
current_thread_time(&end_time) &&
end_time.tv_sec >= ts->tv_sec) {
return (unsigned long long)(end_time.tv_sec - ts->tv_sec) * (1000 * 1000 * 1000) +
(end_time.tv_nsec - ts->tv_nsec);
Expand Down
2 changes: 1 addition & 1 deletion internal/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* header, rather than being on a separately allocated buffer) and
* these bits are the length of the Struct.
*/
enum {
enum ruby_rstruct_flags {
RSTRUCT_EMBED_LEN_MASK = RUBY_FL_USER7 | RUBY_FL_USER6 | RUBY_FL_USER5 | RUBY_FL_USER4 |
RUBY_FL_USER3 | RUBY_FL_USER2 | RUBY_FL_USER1,
RSTRUCT_EMBED_LEN_SHIFT = (RUBY_FL_USHIFT+1),
Expand Down
1 change: 1 addition & 0 deletions jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "internal/string.h"
#include "internal/class.h"
#include "internal/imemo.h"
#include "internal/struct.h"
#include "ruby/internal/core/rtypeddata.h"
#include "zjit.h"

Expand Down
3 changes: 3 additions & 0 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def update(*gems)
D
method_option "paths", type: :boolean, banner: "List the paths of all gems that are required by your Gemfile."
method_option "outdated", type: :boolean, banner: "Show verbose output including whether gems are outdated (removed)."
method_option "exact-match", type: :boolean, banner: "Only match gems whose names exactly match the given name"
def show(gem_name = nil)
if ARGV.include?("--outdated")
removed_message = "the `--outdated` flag to `bundle show` has been removed in favor of `bundle show --verbose`"
Expand All @@ -367,6 +368,7 @@ def list
desc "info GEM [OPTIONS]", "Show information for the given gem"
method_option "path", type: :boolean, banner: "Print full path to gem"
method_option "version", type: :boolean, banner: "Print gem version"
method_option "exact-match", type: :boolean, banner: "Only match gems whose names exactly match the given name"
def info(gem_name)
require_relative "cli/info"
Info.new(options, gem_name).run
Expand Down Expand Up @@ -530,6 +532,7 @@ def exec(*args)

desc "open GEM", "Opens the source directory of the given bundled gem"
method_option "path", type: :string, lazy_default: "", banner: "Open relative path of the gem source."
method_option "exact-match", type: :boolean, banner: "Only match gems whose names exactly match the given name"
def open(name)
require_relative "cli/open"
Open.new(options, name).run
Expand Down
4 changes: 4 additions & 0 deletions lib/bundler/cli/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def self.select_spec(name, regex_match = nil)
raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
end

def self.select_spec_with_match_type(name, options)
select_spec(name, options["exact-match"] ? nil : :regex_match)
end

def self.default_gem_spec(name)
gem_spec = Gem::Specification.find_all_by_name(name).last
gem_spec if gem_spec&.default_gem?
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run
private

def spec_for_gem(name)
Bundler::CLI::Common.select_spec(name, :regex_match)
Bundler::CLI::Common.select_spec_with_match_type(name, options)
end

def print_gem_version(spec)
Expand Down
8 changes: 7 additions & 1 deletion lib/bundler/cli/open.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def run
raise InvalidOption, "Cannot specify `--path` option without a value" if !@path.nil? && @path.empty?
editor = [ENV["BUNDLER_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find {|e| !e.nil? && !e.empty? }
return Bundler.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR") unless editor
return unless spec = Bundler::CLI::Common.select_spec(name, :regex_match)
return unless spec = spec_for_gem(name)
if spec.default_gem?
Bundler.ui.info "Unable to open #{name} because it's a default gem, so the directory it would normally be installed to does not exist."
else
Expand All @@ -35,5 +35,11 @@ def editor_command(editor)
require "shellwords"
Shellwords.split(editor)
end

private

def spec_for_gem(name)
Bundler::CLI::Common.select_spec_with_match_type(name, options)
end
end
end
6 changes: 5 additions & 1 deletion lib/bundler/cli/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run
if gem_name == "bundler"
path = File.expand_path("../../..", __dir__)
else
spec = Bundler::CLI::Common.select_spec(gem_name, :regex_match)
spec = spec_for_gem(gem_name)
return unless spec
path = spec.full_gem_path
unless File.directory?(path)
Expand Down Expand Up @@ -55,6 +55,10 @@ def run

private

def spec_for_gem(name)
Bundler::CLI::Common.select_spec_with_match_type(name, options)
end

def fetch_latest_specs
definition = Bundler.definition(true)
Bundler.ui.info "Fetching remote specs for outdated check...\n\n"
Expand Down
5 changes: 4 additions & 1 deletion lib/bundler/man/bundle-info.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.SH "NAME"
\fBbundle\-info\fR \- Show information for the given gem in your bundle
.SH "SYNOPSIS"
\fBbundle info\fR [GEM_NAME] [\-\-path] [\-\-version]
\fBbundle info\fR [GEM_NAME] [\-\-path] [\-\-version] [\-\-exact\-match]
.SH "DESCRIPTION"
Given a gem name present in your bundle, print the basic information about it such as homepage, version, path and summary\.
.SH "OPTIONS"
Expand All @@ -14,4 +14,7 @@ Print the path of the given gem
.TP
\fB\-\-version\fR
Print gem version
.TP
\fB\-\-exact\-match\fR
Only match gems whose names exactly match the given name\.

4 changes: 4 additions & 0 deletions lib/bundler/man/bundle-info.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ bundle-info(1) -- Show information for the given gem in your bundle
`bundle info` [GEM_NAME]
[--path]
[--version]
[--exact-match]

## DESCRIPTION

Expand All @@ -19,3 +20,6 @@ Given a gem name present in your bundle, print the basic information about it

* `--version`:
Print gem version

* `--exact-match`:
Only match gems whose names exactly match the given name.
5 changes: 4 additions & 1 deletion lib/bundler/man/bundle-open.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.SH "NAME"
\fBbundle\-open\fR \- Opens the source directory for a gem in your bundle
.SH "SYNOPSIS"
\fBbundle open\fR [GEM] [\-\-path=PATH]
\fBbundle open\fR [GEM] [\-\-path=PATH] [\-\-exact\-match]
.SH "DESCRIPTION"
Opens the source directory of the provided GEM in your editor\.
.P
Expand All @@ -29,4 +29,7 @@ Will open the README\.md file of the 'rack' gem source in your bundle\.
.TP
\fB\-\-path[=PATH]\fR
Specify GEM source relative path to open\.
.TP
\fB\-\-exact\-match\fR
Only match gems whose names exactly match the given name\.

5 changes: 4 additions & 1 deletion lib/bundler/man/bundle-open.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bundle-open(1) -- Opens the source directory for a gem in your bundle

## SYNOPSIS

`bundle open` [GEM] [--path=PATH]
`bundle open` [GEM] [--path=PATH] [--exact-match]

## DESCRIPTION

Expand All @@ -26,3 +26,6 @@ Will open the README.md file of the 'rack' gem source in your bundle.

* `--path[=PATH]`:
Specify GEM source relative path to open.

* `--exact-match`:
Only match gems whose names exactly match the given name.
5 changes: 4 additions & 1 deletion lib/bundler/man/bundle-show.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.SH "NAME"
\fBbundle\-show\fR \- Shows all the gems in your bundle, or the path to a gem
.SH "SYNOPSIS"
\fBbundle show\fR [GEM] [\-\-paths]
\fBbundle show\fR [GEM] [\-\-paths] [\-\-exact\-match]
.SH "DESCRIPTION"
Without the [GEM] option, \fBshow\fR will print a list of the names and versions of all gems that are required by your [\fBGemfile(5)\fR][Gemfile(5)], sorted by name\.
.P
Expand All @@ -13,4 +13,7 @@ Calling show with [GEM] will list the exact location of that gem on your machine
.TP
\fB\-\-paths\fR
List the paths of all gems that are required by your [\fBGemfile(5)\fR][Gemfile(5)], sorted by gem name\.
.TP
\fB\-\-exact\-match\fR
Only match gems whose names exactly match the given name\.

4 changes: 4 additions & 0 deletions lib/bundler/man/bundle-show.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ bundle-show(1) -- Shows all the gems in your bundle, or the path to a gem

`bundle show` [GEM]
[--paths]
[--exact-match]

## DESCRIPTION

Expand All @@ -19,3 +20,6 @@ machine.
* `--paths`:
List the paths of all gems that are required by your [`Gemfile(5)`][Gemfile(5)],
sorted by gem name.

* `--exact-match`:
Only match gems whose names exactly match the given name.
30 changes: 28 additions & 2 deletions spec/bundler/commands/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,41 @@
end

context "with a valid regexp for gem name" do
it "presents alternatives", :readline do
it "returns the exact match without prompting when requested" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "info myrack --exact-match"
expect(out).to include("* myrack (1.0.0)")
expect(out).not_to include("0 : - exit -")
end

it "does not fall back to regexp matching when exact matching is requested" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "info rac --exact-match", raise_on_error: false
expect(err).to include("Could not find gem 'rac'.")
expect(out).not_to include("0 : - exit -")
end

it "presents alternatives without the exact match flag", :readline do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "info rac"
expect(out).to match(/\A1 : myrack\n2 : myrack-obama\n0 : - exit -(\n>|\z)/)
expect(out).to include("1 : myrack")
expect(out).to include("2 : myrack-obama")
expect(out).to include("0 : - exit -")
end
end

Expand Down
29 changes: 29 additions & 0 deletions spec/bundler/commands/open_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,33 @@
expect(out).to include("Unable to open json because it's a default gem, so the directory it would normally be installed to does not exist.")
end
end

context "with a valid regexp for gem name" do
before do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G
end

it "returns the exact match without prompting when requested" do
bundle "open myrack --exact-match", env: { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }
expect(out).to include("editor #{default_bundle_path("gems", "myrack-1.0.0")}")
expect(out).not_to include("0 : - exit -")
end

it "does not fall back to regexp matching when exact matching is requested" do
bundle "open rac --exact-match", env: { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }, raise_on_error: false
expect(err).to include("Could not find gem 'rac'.")
expect(out).not_to include("0 : - exit -")
end

it "presents alternatives without the exact match flag", :readline do
bundle "open rac", env: { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }
expect(out).to include("1 : myrack")
expect(out).to include("2 : myrack-obama")
expect(out).to include("0 : - exit -")
end
end
end
29 changes: 27 additions & 2 deletions spec/bundler/commands/show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,40 @@
end

context "with a valid regexp for gem name" do
it "presents alternatives", :readline do
it "returns the exact match without prompting when requested" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "show myrack --exact-match"
expect(out).to include(default_bundle_path("gems", "myrack-1.0.0").to_s)
end

it "does not fall back to regexp matching when exact matching is requested" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "show rac --exact-match", raise_on_error: false
expect(err).to include("Could not find gem 'rac'.")
expect(out).not_to include("0 : - exit -")
end

it "presents alternatives without the exact match flag", :readline do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "show rac"
expect(out).to match(/\A1 : myrack\n2 : myrack-obama\n0 : - exit -(\n>|\z)/)
expect(out).to include("1 : myrack")
expect(out).to include("2 : myrack-obama")
expect(out).to include("0 : - exit -")
end
end

Expand Down
14 changes: 14 additions & 0 deletions vm_insnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -6783,6 +6783,20 @@ rb_vm_opt_getconstant_path(rb_execution_context_t *ec, rb_control_frame_t *const
return val;
}

// Return true if the once value is already computed and set *result to the value.
// Otherwise, return false.
// Used for ZJIT. Keep in sync with `vm_once_dispatch` below.
bool
rb_vm_once_done_value(ISE is, VALUE *result)
{
rb_thread_t *running_th = rbimpl_atomic_ptr_load((void**)&is->once.running_thread, RBIMPL_ATOMIC_ACQUIRE);
if (running_th == RUNNING_THREAD_ONCE_DONE) {
*result = is->once.value;
return true;
}
return false;
}

static VALUE
vm_once_dispatch(rb_execution_context_t *ec, ISEQ iseq, ISE is)
{
Expand Down
Loading