When sleeping with `sleep`, currently the main thread can get woken up from sigchld
from any thread (subprocess exited). The timer thread wakes up the main thread when this
happens, as it checks for signals. The main thread then executes the ruby sigchld handler
if one is registered and is supposed to go back to sleep immediately. This is not ideal but
it's the way it's worked for a while. In commit 8d8159e7d8 I added writes to `th->status`
before and after `wait_running_turn` in `thread_sched_to_waiting_until_wakeup`, which is
called from `sleep`. This is usually the right way to set the thread's status, but `sleep`
is an exception because the writes to `th->status` are done in `sleep_forever`. There's a
loop that checks `th->status` in `sleep_forever`. When the main thread got woken up from
sigchld it saw the changed `th->status` and continued to run the main thread instead of
going back to sleep.
The following script shows the error. It was returning instead of sleeping forever.
```ruby
t = Thread.new do
sleep 0.3
`echo hello` # Spawns subprocess
puts "Subprocess exited"
end
puts "Main thread sleeping..."
result = sleep # Should block forever
puts "sleep returned: #{result.inspect}"
```
Fixes [Bug #21812]
"Code" (when used to refer to what we create in Ruby or any other programming language) is an abstract non-count noun, so it cannot be pluralized. ("Codes" would be used when referring to specific countable things like PIN codes, which is a different use of the word "code".)
This is somewhat confusing because English allows converting count nouns into non-count nouns, and converting non-count nouns into count nouns, and because many words have both forms.
For an example of converting a non-count noun to a count noun, "water" is normally a non-count noun:
> The world is covered with water.
but people who work in restaurants often use the word as a count noun, as a shorthand for "cup of water":
> I need 7 waters on the big table by the window.
For an example of the opposite conversion, "worm" is normally a count noun:
> There are lots of worms in the puddle.
but someone might use it as a non-count noun when talking about non-distinct remains of worms:
> You have worm all over the bottom of your shoe!
So although a given noun can be flexible enough to be used in either way—even when it is unconventional—there is a definite change of meaning when using a word as a count noun or a non-count noun.
* https://github.com/ruby/ruby/actions/runs/20694508956/job/59407571754
1)
UNIXSocket.pair emulates unnamed sockets with a temporary file with a path FAILED
Expected "C:\\a\\_temp\\102424668889-2384.($)".match? /\\AppData\\Local\\Temp\\\d+-\d+\.\(\$\)\z/
to be truthy but was false
This commit adds a field handle_weak_references to rb_data_type_struct for
the callback when handling weak references. This avoids TypedData objects
from needing to expose their rb_data_type_struct and weak references function.
Before, passing the wrong number of arguments (e.g., 2) to
OpenSSL::PKey::EC::Group.new raised a generic "wrong number of
arguments"
error.
This change updates it to show the actual argument count and the
expected
options (1 or 4), making debugging easier for the user.
Example:
ArgumentError: wrong number of arguments (given 2, expected 1 or 4)
I hope it helps!
https://github.com/ruby/openssl/commit/783c99e6c7
Although the example code comments indicate that it returns `false`,
a non-matching result for `=~` is actually `nil`.
```ruby
Foo.foo.blank? #=> false
"foo".blank? #=> false
```
https://github.com/ruby/ruby/blob/v4.0.0-preview3/doc/language/box.md?plain=1#L115-L122
This PR replaces `=~` with `match?` so that it returns the expected `false`.
Since this makes the result a boolean, it also aligns with the expected behavior of
a predicate method name like `blank?`.
Based on the example, it appears that `foo.rb` and `main.rb` are expected to be in the same directory.
Since Ruby 1.9, the current directory is not included in `$LOAD_PATH` by default.
As a result, running `box.require('foo')` as shown in the sample code raises a `LoadError`:
```console
main.rb:2:in `Ruby::Box#require': cannot load such file -- foo (LoadError)
from main.rb:2:in `<main>'
```
To avoid this, it seems simplest to show either `box.require('./foo')` or `box.require_relative('foo')`.
In this PR, `box.require('foo')` is replaced with `box.require_relative('foo')` to make the intention of
using a relative path explicit.
This should reduce the chance that users trying Ruby Box will run into an unexpected error.
Anonymous memberless Structs and Data were returning `#<struct >` and
`#<data >` with a trailing space. Now they return `#<struct>` and
`#<data>` to match attrless class behavior and look a bit more compact.
Thread::Queue spends a significant amount of time in array functions,
checking for invariants we know aren't a problem, and whether the backing
array need to reordered.
By using a ring buffer we can remove a lot of overhead (~23% faster).
```
$ hyperfine './miniruby --yjit /tmp/q.rb' './miniruby-qrb --yjit /tmp/q.rb'
Benchmark 1: ./miniruby --yjit /tmp/q.rb
Time (mean ± σ): 1.050 s ± 0.191 s [User: 0.988 s, System: 0.004 s]
Range (min … max): 0.984 s … 1.595 s 10 runs
Benchmark 2: ./miniruby-qrb --yjit /tmp/q.rb
Time (mean ± σ): 844.2 ms ± 3.1 ms [User: 840.4 ms, System: 2.8 ms]
Range (min … max): 838.6 ms … 848.9 ms 10 runs
Summary
./miniruby-qrb --yjit /tmp/q.rb ran
1.24 ± 0.23 times faster than ./miniruby --yjit /tmp/q.rb
```
```
q = Queue.new([1, 2, 3, 4, 5, 6, 7, 8])
i = 2_000_000
while i > 0
i -= 1
q.push(q.pop)
q.push(q.pop)
q.push(q.pop)
q.push(q.pop)
q.push(q.pop)
q.push(q.pop)
q.push(q.pop)
q.push(q.pop)
q.push(q.pop)
q.push(q.pop)
end
```