Commit graph

9854 commits

Author SHA1 Message Date
Hiroshi SHIBATA
ddf0080fd3 [ruby/io-console] Bump up 0.8.0
467508a0c6
2024-12-03 05:05:14 +00:00
Hiroshi SHIBATA
80a5db55e3 [ruby/etc] Use same license files with ruby/ruby
8d585ea0c9
2024-12-03 04:59:13 +00:00
Hiroshi SHIBATA
9bd1e6ee04 [ruby/io-nonblock] Bump up 0.3.1
16727a8ab3
2024-12-03 04:38:16 +00:00
Nobuyoshi Nakada
8ec58a91f7 [ruby/io-console] Add IO#ttyname that returns the tty name or nil
fdad351501
2024-12-02 08:03:30 +00:00
Hiroshi SHIBATA
229592f175 [ruby/date] Bump up 3.4.1
a3295ad262
2024-12-02 07:51:06 +00:00
Nobuyoshi Nakada
9948a8c8df [ruby/io-console] Freeze the version string
aa79919f79
2024-12-02 05:00:47 +00:00
Nobuyoshi Nakada
decc02996a [ruby/io-console] Check if rb_syserr_fail_str is available
Truffle ruby seems to lack it.

839c1e80eb
2024-12-02 03:37:15 +00:00
Hiroshi SHIBATA
9b6036667e Removed trailing spaces 2024-12-02 10:50:34 +09:00
Jean Boussier
636d57bd1c [ruby/strscan] Micro optimize encoding checks
(https://github.com/ruby/strscan/pull/117)

Profiling shows a lot of time spent in various encoding check functions.
I'm working on optimizing them on the Ruby side, but if we assume most
strings are one of the simple 3 encodings, we can skip a lot of
overhead.

```ruby
require 'strscan'
require 'benchmark/ips'

source = 10_000.times.map { rand(9999999).to_s }.join(",").force_encoding(Encoding::UTF_8).freeze

def scan_to_i(source)
  scanner = StringScanner.new(source)
  while number = scanner.scan(/\d+/)
    number.to_i
    scanner.skip(",")
  end
end

def scan_integer(source)
  scanner = StringScanner.new(source)
  while scanner.scan_integer
    scanner.skip(",")
  end
end

Benchmark.ips do |x|
  x.report("scan.to_i") { scan_to_i(source) }
  x.report("scan_integer") { scan_integer(source) }
  x.compare!
end
```

Before:

```
ruby 3.3.4 (2024-07-09 revision be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
           scan.to_i    93.000 i/100ms
        scan_integer   232.000 i/100ms
Calculating -------------------------------------
           scan.to_i    933.191 (± 0.2%) i/s    (1.07 ms/i) -      4.743k in   5.082597s
        scan_integer      2.326k (± 0.8%) i/s  (429.99 μs/i) -     11.832k in   5.087974s

Comparison:
        scan_integer:     2325.6 i/s
           scan.to_i:      933.2 i/s - 2.49x  slower
```

After:

```
ruby 3.3.4 (2024-07-09 revision be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
           scan.to_i    96.000 i/100ms
        scan_integer   274.000 i/100ms
Calculating -------------------------------------
           scan.to_i    969.489 (± 0.2%) i/s    (1.03 ms/i) -      4.896k in   5.050114s
        scan_integer      2.756k (± 0.1%) i/s  (362.88 μs/i) -     13.974k in   5.070837s

Comparison:
        scan_integer:     2755.8 i/s
           scan.to_i:      969.5 i/s - 2.84x  slower
```

c02b1ce684
2024-12-02 10:50:34 +09:00
Jean Boussier
79cc3d26ed StringScanner#scan_integer support base 16 integers (#116)
Followup: https://github.com/ruby/strscan/pull/115

`scan_integer` is now implemented in Ruby as to efficiently handle
keyword arguments without allocating a Hash. Given the goal of
`scan_integer` is to more effciently parse integers without having to
allocate an intermediary object, using `rb_scan_args` would defeat the
purpose.

Additionally, the C implementation now uses `rb_isdigit` and
`rb_isxdigit`, because on Windows `isdigit` is locale dependent.
2024-12-02 10:50:34 +09:00
Misaki Shioi
3d07754ee2
Improve the conditions for clearing the Connection Attempt Delay upon connection failure (#12223)
* Improve the conditions for clearing the Connection Attempt Delay upon connection failure

This change addresses a case that was overlooked in ruby/ruby#12087.
In the previous change, the Connection Attempt Delay was cleared at the point of a connection failure only if both of the following conditions were met:

- No other sockets were attempting a connection
- There were addresses still available to start a new connection

In this update, the second condition has been removed.
As a result, if name resolution succeeds after a connection failure and new addresses are obtained, it will be able to immediately attempt a connection to one of them.

If there are no sockets attempting a connection, no addresses available for connection, and name resolution has completed, an exception will still be raised as before.

---

Additionally, the following minor fixes have been made:

* Refactor: Remove unnecessary members
2024-11-30 18:51:53 +09:00
Misaki Shioi
49d2e79fb0
Ensure to close pipes when TCPSocket.new finishes processing (#12181)
`TCPSocket.new` with HEv2 uses three threads.
The last of these threads to exit closed pipes.
However, if pipes were open at the end of the main thread, they would leak.
This change avoids this by closing pipes at the end of the main thread.
2024-11-29 18:49:02 +09:00
Misaki Shioi
22e1a8c478
Allow disable to fast_fallback of TCPSocket.new (#12210)
with `Socket.tcp_fast_fallback=`
The functions that `Socket.tcp` had are now also available in `TCPSocket.new`.
2024-11-29 14:18:09 +09:00
Yusuke Endoh
f9d0bc22f5 Remove a useless check if fd is negative
If `slave` is negative, neither `dup2(slave,0)` or `close(slave)` should
be executed. I believe this check is completely useless.
2024-11-29 12:38:20 +09:00
Nobuyoshi Nakada
43dd9c721f [ruby/date] Fix mixed declarations and code
This still support ruby 2.6 which does not require C99.

61d849758f
2024-11-29 02:48:10 +00:00
Nobuyoshi Nakada
b910de641b [ruby/date] Suppress compound-token-split-by-macro warnings
It was used intentionally.

291b40f939
2024-11-29 02:48:09 +00:00
Misaki Shioi
47f8a552f6
Ensure to free fast_fallback_getaddrinfo_shared with single family (#12199)
With https://github.com/ruby/ruby/pull/12156,
the memory of the `struct fast_fallback_getaddrinfo_shared`
is now allocated even if there is only one address family.
This change will always free it when `TCPSocket.new` finishes.
2024-11-28 22:39:35 +09:00
Yusuke Endoh
209f8ba7c4 [ruby/json] Prevent a warning of "a candidate for gnu_printf format attribute"
GCC 13 prints the following warning.

20241127T001003Z.log.html.gz
```
compiling generator.c
generator.c: In function ‘raise_generator_error’:
generator.c:91:5: warning: function ‘raise_generator_error’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
   91 |     VALUE str = rb_vsprintf(fmt, args);
      |     ^~~~~
```

This change prevents the warning by specifying the format attribute.

b8c1490846
2024-11-27 23:35:20 +09:00
Alan Wu
c41af37ee6 [ruby/io-console] Read errno before calling rb_io_path()
Possible fix for recent crashes seen on CI.

     [BUG] rb_sys_fail_str(<STDIN>) - errno == 0

rb_io_path() calls rb_obj_dup(), which could call initialize_dup in Ruby
and clobber errno before rb_sys_fail_str() gets to read errno. So
save it out first.

(Using separate statements because order of evaluation in function call
list is unspecified, and order is important here.)

0ba400b5e7
2024-11-27 03:19:39 +00:00
Yusuke Endoh
3face42d8a Revert "Add a temporal debugging code"
This reverts commit 5bd144c1bb.
2024-11-27 11:43:02 +09:00
Jean Boussier
d5de1a5789 [ruby/strscan] Implement #scan_integer to efficiently parse Integer
(https://github.com/ruby/strscan/pull/115)

Fix: https://github.com/ruby/strscan/issues/113

This allows to directly parse an Integer from a String without needing
to first allocate a sub string.

Notes:

The implementation is limited by design, it's meant as a first step,
only the most straightforward, based 10 integers are supported.

6a3c74b4c8
2024-11-27 09:24:07 +09:00
Jean Boussier
693a793521 JSON::GeneratorError expose invalid object
Fix: https://github.com/ruby/json/issues/710

Makes it easier to debug why a given tree of objects can't
be dumped as JSON.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
2024-11-26 15:11:05 +09:00
Jean Boussier
6805e88935 [ruby/json] Stop using rb_gc_mark_locations
It's using `rb_gc_mark_maybe` under the hood, which isn't what
we need.

e10d0bffcd
2024-11-26 15:11:05 +09:00
Jean Boussier
ee0de3fd4e [ruby/json] JSON.dump: write directly into the provided IO
Ref: https://github.com/ruby/json/issues/524

Rather than to buffer everything in memory.

Unfortunately Ruby doesn't provide an API to write into
and IO without first allocating a string, which is a bit
wasteful.

f017af6c0a
2024-11-26 15:11:05 +09:00
Yusuke Endoh
92585898fb Prevent memory leak
```
for (int i = 0; i < arg->family_size; i++) {
    arg->getaddrinfo_entries[i] = allocate_fast_fallback_getaddrinfo_entry();
    if (!(arg->getaddrinfo_entries[i])) rb_syserr_fail(errno, "calloc(3)");
```

If the allocation fails in the second interation, the memory allocated
in the first iteration would be leaked.

This change prevents the memory leak by allocating the memory in
advance.
(The struct name `fast_fallback_getaddrinfo_shared` might no longer be
good.)
2024-11-25 20:18:48 +09:00
Nobuyoshi Nakada
4d8c793bc3 Fix initialization of struct wait_fast_fallback_arg::cancelled 2024-11-25 17:40:14 +09:00
Misaki Shioi
ff5fc4b5a1
Do not save the last error without sockets in the connection attempt (#12153)
* Do not save the last_error if there are no sockets waiting to be connected

In this implementation, the results of both name resolution and connection attempts are awaited using select(2).
When it returned, the implementation attempted to check for connections even if there were no sockets currently attempting to connect, treating the absence of connected sockets as a connection failure.
With this fix, it will no longer check for connections when there are no sockets waiting to be connected.

Additionally, the following minor fixes have been made:

* Handle failure of getsockopt(2) and removed unnecessary continue in the loop

* Tweak: Use common API to check in_progress_fds

* Safely call TCPServer.new in test

* Set empty writefds when there is no socket waiting to be connected

* Enable fast_fallback option
2024-11-25 14:10:54 +09:00
Misaki Shioi
31997661e4
UBF is also required for synchronous name resolution (#12156)
`rb_thread_call_without_gvl2` is used to wait for the results of name resolution and connection attempts.
When there is only one address family to resolve, the necessary resources were not being passed to the UBF.
With this change, the handling of resources has been revised and organized to work consistently, whether there are two address families to resolve or only one.
2024-11-24 00:44:13 +09:00
Misaki Shioi
8d575e4972
Save the error that occurred during name resolution (#12155)
even if a system call error happens after the name resolution failure in the child thread.

pipe and write(2) are used to notify the main thread of the name resolution results from the child thread.
After name resolution is completed in the child thread, if the call to write(2) fails, the main thread retrieves the resolved addresses.
However, when name resolution failed, the corresponding error was not being saved in `last_error`.
With this change, name resolution failures will now be saved in last_error even if the write(2) call in the child thread fails.
2024-11-23 23:04:02 +09:00
Josh Cooper
b4d13fac3d [ruby/openssl] Support signing CRLs using Ed25519
Allow CRLs to be signed using Ed25519 private keys by passing a nil digest.

b62375bcde
2024-11-22 17:26:03 +00:00
Josh Cooper
6389c9a395 [ruby/openssl] Support signing requests using Ed25519
Allow requests to be signed using Ed25519 private keys by passing a nil digest.
This is similar to commit b0fc100091 when signing certs.

Calling PKey#public_key is deprecated and does not work for Ed25519. The same
can be accomplished by passing the private key.

d96090320d
2024-11-22 17:26:02 +00:00
Yusuke Endoh
5bd144c1bb Add a temporal debugging code
... to check the return value of ioctl

http://ci.rvm.jp/results/trunk_asan@ruby-sp1/5423172
```
/tmp/ruby/src/trunk_asan/lib/reline/io/ansi.rb:192: [BUG] rb_sys_fail_str(<STDIN>) - errno == 0
```
2024-11-22 15:00:20 +09:00
Nobuyoshi Nakada
4e01878bad
[Bug #20903] rb_econv_str_append arguments expected to be String 2024-11-22 10:36:05 +09:00
Yusuke Endoh
d43f796292 Fix the usage of realloc
http://ci.rvm.jp/results/trunk-repeat50@ruby-sp2-noble-docker/5420911
```
/tmp/ruby/src/trunk-repeat50/ext/socket/ipsocket.c: In function ‘reallocate_connection_attempt_fds’:
/tmp/ruby/src/trunk-repeat50/ext/socket/ipsocket.c:292:62: warning: pointer ‘fds’ may be used after ‘realloc’ [-Wuse-after-free]
  292 |     for (int i = current_capacity; i < new_capacity; i++) fds[i] = -1;
      |                                                              ^
/tmp/ruby/src/trunk-repeat50/ext/socket/ipsocket.c:288:9: note: call to ‘realloc’ here
  288 |     if (realloc(fds, new_capacity * sizeof(int)) == NULL) {
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
2024-11-21 00:20:11 -06:00
Samuel Williams
f6e6e66870 [ruby/zlib] Add support for safe offload of nogvl code.
(https://github.com/ruby/zlib/pull/89)

a535271862
2024-11-20 21:40:55 +00:00
Samuel Williams
b143fd5bd8 [ruby/zlib] Don't call rb_str_set_len while released the GVL.
(https://github.com/ruby/zlib/pull/88)

* Only release the GVL where necessary.

- Several string manipulation methods were invoked while the GVL was
  released. This is unsafe.
- The mutex protecting multi-threaded access was not covering buffer state
  manipulation, leading to data corruption and out-of-bounds writes.
- Using `rb_str_locktmp` prevents changes to buffer while it's in use.

[Bug #20863]

e445cf3c80
2024-11-20 21:02:16 +00:00
Thierry Deo
2bf5d26eb9 [ruby/psych] Eagerly require date.
b2aa0032c0
2024-11-20 16:59:55 +00:00
Nobuyoshi Nakada
577e6a3e19 [ruby/etc] Prefer rb_intern_const over rb_intern for literal strings
53362d891c
2024-11-20 16:38:33 +00:00
Nobuyoshi Nakada
f962394481 [ruby/digest] Remove obsolete test runner [ci skip]
This file is platform dependent, outdated and already not working.
Use `rake` instead.

a2a917dc71
2024-11-20 15:14:26 +00:00
Nobuyoshi Nakada
727b2a2999 [ruby/digest] Fix -Wundef warnings
0ea3ac9926
2024-11-19 03:42:43 +00:00
Nobuyoshi Nakada
0f75ac8380 [ruby/digest] Adjust styles [ci skip]
- Use the C90 standard style for comments, since this gem supports
  versions prior to ruby 2.7.

- Adjust the indentation.

4751402e50
2024-11-18 07:43:33 +00:00
Yuta Saito
29fdb73c5b [ruby/digest] Fix loading of digest ext libraries with --with-static-linked-ext
`rb_ext_resolve_symbol` is not always available on some platforms
including WASI, and we don't need to use it when the extension is built
as a static library. This commit prefers to use `rb_digest_wrap_metadata`
directly when the extension is built as a static library to avoid the
unnecessary use of `rb_ext_resolve_symbol`.

f8ff014622
2024-11-18 04:34:40 +00:00
Jean Boussier
9c6217fd05 [ruby/json] Fix the BEWARE documentation in load and unsafe_load.
2d62ec449f
2024-11-18 04:23:18 +01:00
Jean Boussier
f3e17a84f4 [ruby/json] Release 2.8.2
d5e4a6e3fd
2024-11-18 04:23:18 +01:00
razokulover
62e1469e8b [ruby/json] Fix redundant to_str call
61f022dfbd
2024-11-18 04:23:18 +01:00
Misaki Shioi
3c30af77fe
Fix stack-use-after-return (#12105)
http://ci.rvm.jp/results/trunk_asan@ruby-sp1/5409001

```
=================================================================
==3263562==ERROR: AddressSanitizer: stack-use-after-return on address 0x735a8f190da8 at pc 0x735a6f58dabc bp 0x735a639ffd10 sp 0x735a639ffd08
READ of size 4 at 0x735a8f190da8 thread T211
=================================================================
```
2024-11-17 10:36:33 +09:00
HoneyryderChuck
002438767d [ruby/io-nonblock] mark extension as ractor safe
ba445b37d5
2024-11-16 04:18:14 +00:00
Misaki Shioi
51666c827b
Make fast_fallback option false by default temporarily (#12070)
to suppress failing output in CI.
2024-11-15 09:18:09 +09:00
Yusuke Endoh
4074c6b427 Fix a stack-buffer-overflow bug
http://ci.rvm.jp/results/trunk_asan@ruby-sp1/5408428
```
==3159643==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x796cf8f09041 at pc 0x6539bbf68ded bp 0x796cfadffcf0 sp 0x796cfadff4b8
READ of size 2 at 0x796cf8f09041 thread T13
    #0 0x6539bbf68dec in strlen (/tmp/ruby/build/trunk_asan/ruby+0x18edec) (BuildId: cca267c7ae091060e1b82a6b4ed1aeaf00edebab)
```
2024-11-14 11:29:47 -06:00
Misaki Shioi
fd4b27472e
Do not wait connection attempt delay without in progress fds (#12087)
Do not wait Connection Attempt Delay without in progress fds

Reset Connection Attempt Delay when connection fails and there is no other socket connection in progress.
This is intended to resolve an issue that was temporarily worked around in Pull Request #12062.

`TCPServer::new` (used in tests such as `TestNetHTTP_v1_2_chunked#test_timeout_during_non_chunked_streamed_HTTP_session_write`) can only connect over either IPv6 or IPv4, depending on the environment.
Since HEv2 attempts to connect over IPv6 first, environments where IPv6 connections are unavailable return ECONNREFUSED immediately.
In such cases, the client should immediately retry the connection over IPv4.
However, HEv2 includes a specification for a "Connection Attempt Delay," where it waits 250ms after the previous connection attempt before starting the next one.
This delay causes Net::OpenTimeout (100ms) to be exceeded while waiting for the next connection attempt to start.

With this change, when a connection attempt fails, if there are sockets still attempting to connect and there are addresses yet to be tried, the Connection Attempt Delay will be resetted, allowing the next connection attempt to start immediately.

---

Additionally, the following minor fixes have been made:

- The `nfds` value used for select(2) is now reset with each wait.
2024-11-15 00:25:59 +09:00