Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into Ractor-Local-GC-v…
Browse files Browse the repository at this point in the history
…ersion-3
  • Loading branch information
rm155 committed Aug 23, 2024
2 parents ef6ecc9 + 3f6be01 commit d5e1115
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 39 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ The following bundled gems are updated.
* net-ftp 0.3.7
* net-imap 0.4.14
* net-smtp 0.5.0
* rbs 3.5.2
* rbs 3.5.3
* typeprof 0.21.11
* debug 1.9.2
* racc 1.8.1
Expand Down
18 changes: 8 additions & 10 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -3706,21 +3706,19 @@ rb_ary_collect(VALUE ary)

/*
* call-seq:
* array.map! {|element| ... } -> self
* array.map! -> new_enumerator
* collect! {|element| ... } -> new_array
* collect! -> new_enumerator
* map! {|element| ... } -> new_array
* map! -> new_enumerator
*
* Calls the block, if given, with each element;
* replaces the element with the block's return value:
* With a block given, calls the block with each element of +self+
* and replaces the element with the block's return value;
* returns +self+:
*
* a = [:foo, 'bar', 2]
* a.map! { |element| element.class } # => [Symbol, String, Integer]
*
* Returns a new Enumerator if no block given:
*
* a = [:foo, 'bar', 2]
* a1 = a.map!
* a1 # => #<Enumerator: [:foo, "bar", 2]:map!>
*
* With no block given, returns a new Enumerator.
*/

static VALUE
Expand Down
4 changes: 0 additions & 4 deletions ext/fiddle/fiddle.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ Gem::Specification.new do |spec|
"ext/fiddle/memory_view.c",
"ext/fiddle/pinned.c",
"ext/fiddle/pointer.c",
"ext/fiddle/win32/fficonfig.h",
"ext/fiddle/win32/libffi-3.2.1-mswin.patch",
"ext/fiddle/win32/libffi-config.rb",
"ext/fiddle/win32/libffi.mk.tmpl",
"fiddle.gemspec",
"lib/fiddle.rb",
"lib/fiddle/closure.rb",
Expand Down
15 changes: 9 additions & 6 deletions gc/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -1831,14 +1831,17 @@ rb_gc_impl_object_id(void *objspace_ptr, VALUE obj)

WITH_OBJSPACE_OF_VALUE_ENTER(obj, objspace);
rb_native_mutex_lock(&objspace->obj_id_lock);
st_data_t val;
if (st_lookup(objspace->obj_to_id_tbl, (st_data_t)obj, &val)) {
GC_ASSERT(FL_TEST(obj, FL_SEEN_OBJ_ID));
id = (VALUE)val;
if (FL_TEST(obj, FL_SEEN_OBJ_ID)) {
st_data_t val;
if (st_lookup(objspace->obj_to_id_tbl, (st_data_t)obj, &val)) {
id = (VALUE)val;
}
else {
rb_bug("rb_gc_impl_object_id: FL_SEEN_OBJ_ID flag set but not found in table");
}
}
else {
GC_ASSERT(!FL_TEST(obj, FL_SEEN_OBJ_ID));
id = retrieve_next_obj_id(OBJ_ID_INCREMENT);
GC_ASSERT(!st_lookup(objspace->obj_to_id_tbl, (st_data_t)obj, NULL));

st_insert_no_gc(objspace->obj_to_id_tbl, (st_data_t)obj, (st_data_t)id);
st_insert_no_gc(objspace->id_to_obj_tbl, (st_data_t)id, (st_data_t)obj);
Expand Down
2 changes: 1 addition & 1 deletion gems/bundled_gems
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ net-pop 0.1.2 https://github.com/ruby/net-pop
net-smtp 0.5.0 https://github.com/ruby/net-smtp
matrix 0.4.2 https://github.com/ruby/matrix
prime 0.1.2 https://github.com/ruby/prime
rbs 3.5.2 https://github.com/ruby/rbs
rbs 3.5.3 https://github.com/ruby/rbs
typeprof 0.21.11 https://github.com/ruby/typeprof b19a6416da3a05d57fadd6ffdadb382b6d236ca5
debug 1.9.2 https://github.com/ruby/debug
racc 1.8.1 https://github.com/ruby/racc
Expand Down
7 changes: 4 additions & 3 deletions lib/bundler/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def run

if options[:deployment] || options[:frozen] || Bundler.frozen_bundle?
unless Bundler.default_lockfile.exist?
flag = "--deployment flag" if options[:deployment]
flag ||= "--frozen flag" if options[:frozen]
flag ||= "deployment setting"
flag = "--deployment flag" if options[:deployment]
flag ||= "--frozen flag" if options[:frozen]
flag ||= "deployment setting" if Bundler.settings[:deployment]
flag ||= "frozen setting" if Bundler.settings[:frozen]
raise ProductionError, "The #{flag} requires a lockfile. Please make " \
"sure you have checked your #{SharedHelpers.relative_lockfile_path} into version control " \
"before deploying."
Expand Down
2 changes: 1 addition & 1 deletion lib/tempfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def open(*args, **kw)
# Related: Tempfile.new.
#
def Tempfile.create(basename="", tmpdir=nil, mode: 0, anonymous: false, **options, &block)
if anonymous
if anonymous && RUBY_VERSION >= '3.2'
create_anonymous(basename, tmpdir, mode: mode, **options, &block)
else
create_with_filename(basename, tmpdir, mode: mode, **options, &block)
Expand Down
1 change: 1 addition & 0 deletions spec/bundler/bundler/bundler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
it "should issue a warning and return a temporary user home" do
allow(Bundler.rubygems).to receive(:user_home).and_return(path)
allow(File).to receive(:directory?).with(path).and_return true
allow(File).to receive(:writable?).and_call_original
allow(File).to receive(:writable?).with(path).and_return false
allow(File).to receive(:directory?).with(dotbundle).and_return false
allow(Bundler).to receive(:tmp).and_return(Pathname.new("/tmp/trulyrandom"))
Expand Down
12 changes: 12 additions & 0 deletions spec/bundler/install/deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@
end
end

it "fails without a lockfile and says that deployment requires a lock" do
bundle "config deployment true"
bundle "install", raise_on_error: false
expect(err).to include("The deployment setting requires a lockfile")
end

it "fails without a lockfile and says that frozen requires a lock" do
bundle "config frozen true"
bundle "install", raise_on_error: false
expect(err).to include("The frozen setting requires a lockfile")
end

it "still works if you are not in the app directory and specify --gemfile" do
bundle "install"
simulate_new_machine
Expand Down
16 changes: 14 additions & 2 deletions test/fileutils/test_fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,24 @@ def no_broken_symlink?
@@no_broken_symlink
end

def has_capsh?
!!system('capsh', '--print', out: File::NULL, err: File::NULL)
end

def has_root_file_capabilities?
!!system(
'capsh', '--has-p=CAP_DAC_OVERRIDE', '--has-p=CAP_CHOWN', '--has-p=CAP_FOWNER',
out: File::NULL, err: File::NULL
)
end

def root_in_posix?
if /cygwin/ =~ RUBY_PLATFORM
# FIXME: privilege if groups include root user?
return Process.groups.include?(0)
end
if Process.respond_to?('uid')
elsif has_capsh?
return has_root_file_capabilities?
elsif Process.respond_to?('uid')
return Process.uid == 0
else
return false
Expand Down
8 changes: 4 additions & 4 deletions test/ruby/test_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1716,10 +1716,10 @@ def test_slice_out_of_range
def test_slice_gc_compact_stress
omit "compaction doesn't work well on s390x" if RUBY_PLATFORM =~ /s390x/ # https://github.com/ruby/ruby/pull/5077
EnvUtil.under_gc_compact_stress { assert_equal([1, 2, 3, 4, 5], (0..10).to_a[1, 5]) }
# EnvUtil.under_gc_compact_stress do
# a = [0, 1, 2, 3, 4, 5]
# assert_equal([2, 1, 0], a.slice((2..).step(-1)))
# end
EnvUtil.under_gc_compact_stress do
a = [0, 1, 2, 3, 4, 5]
assert_equal([2, 1, 0], a.slice((2..).step(-1)))
end
end

def test_slice!
Expand Down
19 changes: 17 additions & 2 deletions test/ruby/test_file_exhaustive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def blockdev
@blockdev
end

def root_without_capabilities?
return false unless Process.uid == 0
return false unless system('command', '-v', 'capsh', out: File::NULL)
!system('capsh', '--has-p=CAP_DAC_OVERRIDE', out: File::NULL, err: File::NULL)
end

def test_path
[regular_file, utf8_file].each do |file|
assert_equal(file, File.open(file) {|f| f.path})
Expand Down Expand Up @@ -1538,8 +1544,17 @@ def test_test
assert_equal(stat.size?, File.size?(f), f)
assert_bool_equal(stat.socket?, File.socket?(f), f)
assert_bool_equal(stat.setuid?, File.setuid?(f), f)
assert_bool_equal(stat.writable?, File.writable?(f), f)
assert_bool_equal(stat.writable_real?, File.writable_real?(f), f)
# It's possible in Linux to be uid 0, but not to have the CAP_DAC_OVERRIDE
# capability that allows skipping file permissions checks (e.g. some kinds
# of "rootless" container setups). In these cases, stat.writable? will be
# true (because it always returns true if Process.uid == 0), but
# File.writeable? will be false (because it actually asks the kernel to do
# an access check).
# Skip these two assertions in that case.
unless root_without_capabilities?
assert_bool_equal(stat.writable?, File.writable?(f), f)
assert_bool_equal(stat.writable_real?, File.writable_real?(f), f)
end
assert_bool_equal(stat.executable?, File.executable?(f), f)
assert_bool_equal(stat.executable_real?, File.executable_real?(f), f)
assert_bool_equal(stat.zero?, File.zero?(f), f)
Expand Down
12 changes: 10 additions & 2 deletions test/test_tempfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,15 +488,23 @@ def test_create_anonymous_removes_file
Dir.mktmpdir {|d|
t = Tempfile.create("", d, anonymous: true)
t.close
assert_equal([], Dir.children(d))
if RUBY_VERSION >= '3.2'
assert_equal([], Dir.children(d))
else
refute_equal([], Dir.children(d))
end
}
end

def test_create_anonymous_path
Dir.mktmpdir {|d|
begin
t = Tempfile.create("", d, anonymous: true)
assert_equal(File.join(d, ""), t.path)
if RUBY_VERSION >= '3.2'
assert_equal(File.join(d, ""), t.path)
else
refute_equal(File.join(d, ""), t.path)
end
ensure
t.close if t
end
Expand Down
4 changes: 2 additions & 2 deletions tool/rbinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ def CONFIG.[](name, mandatory = false)
prolog_script = <<EOS
bindir="#{load_relative ? '${0%/*}' : bindir.gsub(/\"/, '\\\\"')}"
EOS
if CONFIG["LIBRUBY_RELATIVE"] != 'yes' and libpathenv = CONFIG["LIBPATHENV"]
if !load_relative and libpathenv = CONFIG["LIBPATHENV"]
pathsep = File::PATH_SEPARATOR
prolog_script << <<EOS
libdir="#{load_relative ? '$\{bindir%/bin\}/lib' : libdir.gsub(/\"/, '\\\\"')}"
libdir="#{libdir.gsub(/\"/, '\\\\"')}"
export #{libpathenv}="$libdir${#{libpathenv}:+#{pathsep}$#{libpathenv}}"
EOS
end
Expand Down
2 changes: 1 addition & 1 deletion weakmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ wkmap_inspect(VALUE self)
* val1 = Object.new
* m[key1] = val1
*
* key2 = "foo"
* key2 = "bar"
* val2 = Object.new
* m[key2] = val2
*
Expand Down

0 comments on commit d5e1115

Please sign in to comment.