87158 Commits

Author SHA1 Message Date
Andy Wong
b51e1c07d8
[DOC] Fix typos in ObjectSpace::WeakMap docs
The value of variable key2 should be "bar". This way, when nil is assigned to val1 and garbage collection occurs, the output of m.keys will then be ["bar"].
2024-08-23 20:44:51 +09:00
KJ Tsanaktsidis
4dae4c6858 [rubygems/rubygems] Don't break if extra calls to File.writable? happen
In https://bugs.ruby-lang.org/issues/20693, I'd like to have Dir.tmpdir
call `File.writable?` instead of `Stat#writable?`. However, that causes
this test to break in bundler because it's using RSpec to stub
`File.writable?`.

We can fix this by allowing the real `File.writable?` to be called for
all files except the directory we're trying to stub.

https://github.com/rubygems/rubygems/commit/0fa6657293
2024-08-23 08:08:26 +00:00
git
73a946c618 Update bundled gems list as of 2024-08-23 2024-08-23 07:00:52 +00:00
David Rodríguez
9f5860407f [rubygems/rubygems] Fix error message when Bundler refuses to install due to frozen being set without a lockfile
https://github.com/rubygems/rubygems/commit/0857d62ca6
2024-08-23 07:00:30 +00:00
Hiroshi SHIBATA
7812732e2c [ruby/tempfile] File.new(fileno, mode: mode, path: path) is provided from Ruby 3.2
https://github.com/ruby/tempfile/commit/67ce897727
2024-08-23 06:07:40 +00:00
David Rodríguez
52082d19e0 load_relative is always falsy here 2024-08-23 12:17:07 +09:00
David Rodríguez
fbadcd277f Reuse load_relative local 2024-08-23 12:17:07 +09:00
Hiroshi SHIBATA
c48e5959de
[ruby/fiddle] Removed libffi patchs for old Ruby
(https://github.com/ruby/fiddle/pull/143)

Pick
92865d8760
from `ruby/ruby` repo.

---------

https://github.com/ruby/fiddle/commit/aad5a3bc79

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2024-08-23 11:44:38 +09:00
Burdette Lamar
784ccd0115
[DOC] Tweaks for Array#collect! (#11434) 2024-08-22 20:59:59 -04:00
Peter Zhu
fdba458e85 Uncomment test accidentally commented in 1656350 2024-08-22 19:47:40 -04:00
KJ Tsanaktsidis
8800127d80 Skip some tests which don't work under permissionless containers
When running as UID 0 but without CAP_DAC_OVERRIDE (for example, in a
docker container running with --uid 0 but --cap-drop=all), these tests
won't work because of hard-coded assumptions about what uid 0 can and
can't do.
2024-08-23 09:34:41 +10:00
Peter Zhu
165635049a Don't use gc_impl.h inside of gc/gc.h
Using gc_impl.h inside of gc/gc.h will cause gc/gc.h to use the functions
in gc/default.c when builing with shared GC support because gc/gc.h is
included into gc.c before the rb_gc_impl functions are overridden by the
preprocessor.
2024-08-22 13:50:17 -04:00
Peter Zhu
b0c92d6c3f Change hash_replace_ref_value to assume value moved
When hash_foreach_replace_value returns ST_REPLACE, it's guaranteed that
the value has moved in hash_replace_ref_value.
2024-08-22 13:50:17 -04:00
Kevin Newton
3f30c4df8c [ruby/prism] Update templates/include/prism/ast.h.erb
https://github.com/ruby/prism/commit/7f7620b6d5
2024-08-22 15:23:33 +00:00
Alexander Momchilov
0ef703b91c [ruby/prism] Render node comments into their ast.h
https://github.com/ruby/prism/commit/b17c3241d3
2024-08-22 15:23:32 +00:00
Kevin Newton
d57486cb10 [ruby/prism] Turn off extended mode when parsing extended group
https://github.com/ruby/prism/commit/098b3f08bc
2024-08-22 14:43:35 +00:00
Peter Zhu
56a34b5af5 Fix use-after-free for WeakKeyMap
[Bug #20688]

We cannot free the key before the ST_DELETE because it could hash the
key which would read the key and would cause a use-after-free. Instead,
we store the key and free it on the next iteration.
2024-08-22 10:01:55 -04:00
Peter Zhu
df9a6aa943 Fix WeakMap use-after-free
[Bug #20688]

We cannot free the weakmap_entry before the ST_DELETE because it could
hash the key which would read the weakmap_entry and would cause a
use-after-free. Instead, we store the entry and free it on the next
iteration.

For example, the following script triggers a use-after-free in Valgrind:

    weakmap = ObjectSpace::WeakMap.new
    10_000.times { weakmap[Object.new] = Object.new }

    ==25795== Invalid read of size 8
    ==25795==    at 0x462297: wmap_cmp (weakmap.c:165)
    ==25795==    by 0x3A2B1C: find_table_bin_ind (st.c:930)
    ==25795==    by 0x3A5EAA: st_general_foreach (st.c:1599)
    ==25795==    by 0x3A5EAA: rb_st_foreach (st.c:1640)
    ==25795==    by 0x25C991: gc_mark_children (default.c:4870)
    ==25795==    by 0x25C991: gc_marks_wb_unprotected_objects_plane (default.c:5565)
    ==25795==    by 0x25C991: rgengc_rememberset_mark_plane (default.c:5557)
    ==25795==    by 0x25C991: rgengc_rememberset_mark (default.c:6233)
    ==25795==    by 0x25C991: gc_marks_start (default.c:6057)
    ==25795==    by 0x25C991: gc_marks (default.c:6077)
    ==25795==    by 0x25C991: gc_start (default.c:6723)
    ==25795==    by 0x260F96: heap_prepare (default.c:2282)
    ==25795==    by 0x260F96: heap_next_free_page (default.c:2489)
    ==25795==    by 0x260F96: newobj_cache_miss (default.c:2598)
    ==25795==    by 0x26197F: newobj_alloc (default.c:2622)
    ==25795==    by 0x26197F: rb_gc_impl_new_obj (default.c:2701)
    ==25795==    by 0x26197F: newobj_of (gc.c:890)
    ==25795==    by 0x26197F: rb_wb_protected_newobj_of (gc.c:917)
    ==25795==    by 0x2DEA88: rb_class_allocate_instance (object.c:131)
    ==25795==    by 0x2E3B18: class_call_alloc_func (object.c:2141)
    ==25795==    by 0x2E3B18: rb_class_alloc (object.c:2113)
    ==25795==    by 0x2E3B18: rb_class_new_instance_pass_kw (object.c:2172)
    ==25795==    by 0x429DDC: vm_call_cfunc_with_frame_ (vm_insnhelper.c:3786)
    ==25795==    by 0x44B08D: vm_sendish (vm_insnhelper.c:5953)
    ==25795==    by 0x44B08D: vm_exec_core (insns.def:898)
    ==25795==    by 0x43A7A4: rb_vm_exec (vm.c:2564)
    ==25795==    by 0x234914: rb_ec_exec_node (eval.c:281)
    ==25795==  Address 0x21603710 is 0 bytes inside a block of size 16 free'd
    ==25795==    at 0x4849B2C: free (vg_replace_malloc.c:989)
    ==25795==    by 0x249651: rb_gc_impl_free (default.c:8527)
    ==25795==    by 0x249651: rb_gc_impl_free (default.c:8508)
    ==25795==    by 0x249651: ruby_sized_xfree.constprop.0 (gc.c:4178)
    ==25795==    by 0x4626EC: ruby_sized_xfree_inlined (gc.h:277)
    ==25795==    by 0x4626EC: wmap_free_entry (weakmap.c:45)
    ==25795==    by 0x4626EC: wmap_mark_weak_table_i (weakmap.c:61)
    ==25795==    by 0x3A5CEF: apply_functor (st.c:1633)
    ==25795==    by 0x3A5CEF: st_general_foreach (st.c:1543)
    ==25795==    by 0x3A5CEF: rb_st_foreach (st.c:1640)
    ==25795==    by 0x25C991: gc_mark_children (default.c:4870)
    ==25795==    by 0x25C991: gc_marks_wb_unprotected_objects_plane (default.c:5565)
    ==25795==    by 0x25C991: rgengc_rememberset_mark_plane (default.c:5557)
    ==25795==    by 0x25C991: rgengc_rememberset_mark (default.c:6233)
    ==25795==    by 0x25C991: gc_marks_start (default.c:6057)
    ==25795==    by 0x25C991: gc_marks (default.c:6077)
    ==25795==    by 0x25C991: gc_start (default.c:6723)
    ==25795==    by 0x260F96: heap_prepare (default.c:2282)
    ==25795==    by 0x260F96: heap_next_free_page (default.c:2489)
    ==25795==    by 0x260F96: newobj_cache_miss (default.c:2598)
    ==25795==    by 0x26197F: newobj_alloc (default.c:2622)
    ==25795==    by 0x26197F: rb_gc_impl_new_obj (default.c:2701)
    ==25795==    by 0x26197F: newobj_of (gc.c:890)
    ==25795==    by 0x26197F: rb_wb_protected_newobj_of (gc.c:917)
    ==25795==    by 0x2DEA88: rb_class_allocate_instance (object.c:131)
    ==25795==    by 0x2E3B18: class_call_alloc_func (object.c:2141)
    ==25795==    by 0x2E3B18: rb_class_alloc (object.c:2113)
    ==25795==    by 0x2E3B18: rb_class_new_instance_pass_kw (object.c:2172)
    ==25795==    by 0x429DDC: vm_call_cfunc_with_frame_ (vm_insnhelper.c:3786)
    ==25795==    by 0x44B08D: vm_sendish (vm_insnhelper.c:5953)
    ==25795==    by 0x44B08D: vm_exec_core (insns.def:898)
    ==25795==    by 0x43A7A4: rb_vm_exec (vm.c:2564)
    ==25795==  Block was alloc'd at
    ==25795==    at 0x484680F: malloc (vg_replace_malloc.c:446)
    ==25795==    by 0x25CE9E: rb_gc_impl_malloc (default.c:8542)
    ==25795==    by 0x462A39: wmap_aset_replace (weakmap.c:423)
    ==25795==    by 0x3A5542: rb_st_update (st.c:1487)
    ==25795==    by 0x462B8E: wmap_aset (weakmap.c:452)
    ==25795==    by 0x429DDC: vm_call_cfunc_with_frame_ (vm_insnhelper.c:3786)
    ==25795==    by 0x44B08D: vm_sendish (vm_insnhelper.c:5953)
    ==25795==    by 0x44B08D: vm_exec_core (insns.def:898)
    ==25795==    by 0x43A7A4: rb_vm_exec (vm.c:2564)
    ==25795==    by 0x234914: rb_ec_exec_node (eval.c:281)
    ==25795==    by 0x2369B8: ruby_run_node (eval.c:319)
    ==25795==    by 0x15D675: rb_main (main.c:43)
    ==25795==    by 0x15D675: main (main.c:62)
2024-08-22 10:01:55 -04:00
Peter Zhu
34bf724a9b Remove wmap_free_entry 2024-08-22 10:01:55 -04:00
Peter Zhu
3dd4679786 Refactor wmap_compact to use wmap_foreach 2024-08-22 10:01:55 -04:00
Peter Zhu
9c372f872d Use wmap_foreach for wmap_mark 2024-08-22 10:01:55 -04:00
Peter Zhu
e375fa078f Refactor wmap_foreach to pass weakmap_entry 2024-08-22 10:01:55 -04:00
Peter Zhu
9a9e74389c Add struct weakmap_entry for WeakMap entries 2024-08-22 10:01:55 -04:00
David Rodríguez
2569413b1c [rubygems/rubygems] Fix --prefer-local flag
The original implementation of this flag was too naive and all it did
was restricting gems to locally installed versions if there are any
local versions installed.

However, it should be much smarter. For example:

* It should fallback to remote versions if locally installed version
  don't satisfy the requirements.
* It should pick locally installed versions even for subdependencies not
  yet discovered.

This commit fixes both issues by using a smarter approach similar to how
we resolve prereleases:

* First resolve optimistically using only locally installed gems.
* If any conflicts are found, scan those conflicts, allow remote
  versions for the specific gems that run into conflicts, and
  re-resolve.

https://github.com/rubygems/rubygems/commit/607a3bf479

Co-authored-by: Gourav Khunger <gouravkhunger18@gmail.com>
2024-08-22 11:48:32 +00:00
David Rodríguez
203051d839 [rubygems/rubygems] Fix bad grammar in log message
https://github.com/rubygems/rubygems/commit/bea4c1ad79
2024-08-22 11:48:31 +00:00
Hiroshi SHIBATA
d731adb755
Strictly checking pull-request author 2024-08-22 16:38:54 +09:00
KJ Tsanaktsidis
86c2724e75 Don't emit ELF notes on non-ELF platforms
These apparently break compilation on old MacOS toolchains, because the
MachO section name is capped to 16 chars (although, on my MacOS, at
least, the section name just gets truncated). Nevertheless, these serve
no purpose on non-ELF platforms (they're part of the LSB Linux ABI).

[Bug #20677]
2024-08-22 17:35:43 +10:00
KJ Tsanaktsidis
6a746e1bc9 Check for both aarch64 and arm64 arch's for pac-ret
Linux calls it aarch64, but MacOS calls it arm64; pac-ret works on both.
2024-08-22 17:35:43 +10:00
KJ Tsanaktsidis
ff0a181852 Fix typo in ELF note generation
This wasn't looking at the right macro name for pac-ret support, so if
Ruby was compiled with pac-ret but NOT BTI, then the ELF note would not
be emitted.
2024-08-22 17:35:43 +10:00
Nobuyoshi Nakada
004c6a6ed1 Use ruby to suppress a warning message by cmd.exe
It is expected that reading from command with offset fails by ESPIPE
and the pipe will be closed immediately.  While this causes the child
process to terminate by SIGPIPE usually, cmd.exe yields the message
bellow.

```
The process tried to write to a nonexistent pipe.
```
2024-08-22 16:32:54 +09:00
git
29500e3034 Update bundled gems list as of 2024-08-22 2024-08-22 07:01:14 +00:00
Nobuyoshi Nakada
e7ce8ca166
Fix commented version of codeql-action/upload-sarif [ci skip]
Dependabot will update matching version comments.
2024-08-22 12:35:57 +09:00
dependabot[bot]
0846bcbdf8 Bump github/codeql-action from 3.26.3 to 3.26.4
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.3 to 3.26.4.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](883d8588e5...f0f3afee80)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-22 12:25:52 +09:00
Hiroshi SHIBATA
64a005df3b make test-tool with Windows is broken. We should use :KILL with that platform.
```
[ 14/191] TestParallel::TestParallel#test_hungup = 11.02 s
  1) Failure:
TestParallel::TestParallel#test_hungup [C:/Users/hsbt/DevDrive/github.com/ruby/ruby/tool/test/testunit/test_parallel.rb:211]:
Expected /^Retrying hung up testcases\.+$/ to match "Run options: \n" +
"  --seed=35582\n" +
"  --ruby\n" +
"  \".\\\\ruby.exe -I../../ruby/lib -I.ext/x64-mswin64_140 -I. ../../ruby/tool/runruby.rb --extout=.ext -- --disable-gems\"\n" +
"  -j\n" +
"  t1\n" +
"  --worker-timeout=1\n" +
"\n" +
"# Running tests:\n" +
"\n" +
"[1/1] 50340=test4test_hungup.\n" +
"C:/Users/hsbt/DevDrive/github.com/ruby/ruby/tool/lib/test/unit.rb:418:in 'Process.kill': Invalid argument (Errno::EINVAL)\n" +
```
2024-08-22 11:29:48 +09:00
Jeremy Evans
a3f5a043fa Handle getlogin failure in PTY.spawn
getlogin is only called if USER environment variable is not set,
but if getlogin returns NULL in that case, then do not call
getpwnam, and assume /bin/sh as shell.

Mentioned in comment to bug 20586.
2024-08-22 11:20:47 +09:00
Jeremy Evans
ae886e0c83 Check getlogin return value before passing to strcasecmp
getlogin can return NULL, and this can avoid a segfault
in that case.

Mentioned as an issue in comment to bug 20586.
2024-08-22 11:20:47 +09:00
Hiroshi SHIBATA
8999fd1ac8 automerge needs windows results 2024-08-22 11:06:20 +09:00
Hiroshi SHIBATA
8558bea27b Suppress warning for fd leak
```
Leaked file descriptor: TestResolvDNS#test_multiple_servers_with_timeout_and_truncated_tcp_fallback: 15 : #<TCPSocket:fd 15, AF_INET, 127.0.0.1, 61633>
```
2024-08-22 10:38:43 +09:00
Kevin Newton
773cf883ac [PRISM] Reset $. when done reading STDIN 2024-08-21 16:59:03 -04:00
Kevin Newton
f60499826f [PRISM] Fix TestTRICK#test_ksk_1
If an array element is a static literal that does not result in a
intermediate array, it still needs to be compiled normally.
2024-08-21 16:32:19 -04:00
Kevin Newton
465cf8d80b [PRISM] Potentially enable coverage on the main script 2024-08-21 16:32:05 -04:00
BurdetteLamar
76ccd1df37 [DOC] Tweaks for Enum#tally 2024-08-21 15:56:59 -04:00
BurdetteLamar
53e3795379 [DOC] Tweaks to Array#bsearch_index 2024-08-21 12:07:28 -04:00
Burdette Lamar
f5579c9278
[DOC] Include keywords.rdoc in doc/syntax/ (#11414) 2024-08-21 12:06:48 -04:00
BurdetteLamar
65b3bcede3 [DOC] Tweaks for Array#collect 2024-08-21 11:59:20 -04:00
BurdetteLamar
ee6c7ab0cf [DOC] Tweaks for Array#clear 2024-08-21 11:56:35 -04:00
BurdetteLamar
124f1754df [DOC] Tweaks for Array#bsearch 2024-08-21 11:42:20 -04:00
eileencodes
7ad74d1686 [PRISM] Implement unused block warning
Related: ruby/prism#2935
2024-08-21 11:37:13 -04:00
Peter Zhu
e15b454bc3 Simplify how finalizers are ran at shutdown
We don't need to build a linked list from the finalizer table and
instead we can just run the finalizers by iterating the ST table.

This also improves the performance at shutdown, for example:

    1_000_000.times.map do
      o = Object.new
      ObjectSpace.define_finalizer(o, proc { })
      o
    end

Before:

    Time (mean ± σ):      1.722 s ±  0.056 s    [User: 1.597 s, System: 0.113 s]
    Range (min … max):    1.676 s …  1.863 s    10 runs

After:

    Time (mean ± σ):      1.538 s ±  0.025 s    [User: 1.437 s, System: 0.093 s]
    Range (min … max):    1.510 s …  1.586 s    10 runs
2024-08-21 11:12:07 -04:00
David Rodríguez
669d1f79d8 [rubygems/rubygems] Restore support for passing relative paths to :git
The `file://` protocol does not really work with relative paths and it's
not necessary anyways. So restore support for that by not using
`file://`.

https://github.com/rubygems/rubygems/commit/16a68998ce
2024-08-21 14:47:57 +00:00