Граф коммитов

20012 Коммитов

Автор SHA1 Сообщение Дата
Stan Lo ee0915feeb [ruby/rdoc] Extract excerpt from raw pages correctly
(https://github.com/ruby/rdoc/pull/1200)

Fixes https://bugs.ruby-lang.org/issues/20862

https://github.com/ruby/rdoc/commit/3c678249e2
2024-11-18 10:32:31 +00:00
Misaki Shioi 84470d72c5
Disable HEv2 tests temporarily (#12097)
* Disable HEv2 tests temporarily

To suppress error log output in CI.
They should have been DISABLE in PR #12070.

---

Additionally, the following fixes have been made:

- Remove unnecessary `assert_separately` from the related tests
2024-11-15 18:12:37 +09: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
Dave Corson-Knowles facb82aba5 [rubygems/rubygems] Update test_project_sanity.rb
https://github.com/rubygems/rubygems/commit/279eefb8a3
2024-11-14 23:21:05 +00:00
tomoya ishida 8f3a6ebcf4 [ruby/reline] Drop loading terminfo, remove fiddle dependency in
non-windows environment.
(https://github.com/ruby/reline/pull/769)

Reline works perfectly in most major terminal emulators without terminfo.
In minor/old terminal emulator, we used to get key bindings from terminfo, but I think it is not used so much.

https://github.com/ruby/reline/commit/3ceba3bff7
2024-11-14 23:14:18 +00: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
Matt Valentine-House 42501015b4 rb_raise when attempting to set the GC implementation name
Instead of silently ignoring the key, we should raise to clearly tell
the user that this key is read-only.
2024-11-14 10:46:36 +00:00
Matt Valentine-House ee290c94a3 Include the currently active GC in RUBY_DESCRIPTION
This will add +MOD_GC to the version string and Ruby description when
Ruby is compiled with shared gc support.

When shared GC support is compiled in and a GC module has been loaded
using RUBY_GC_LIBRARY, the version string will include the name of
the currently active GC as reported by the rb_gc_active_gc_name function
in the form

+MOD_GC[gc_name]

[Feature #20794]
2024-11-14 10:46:36 +00:00
Matt Valentine-House fa10441981 Expose GC.config[:implementation], to query the currently active GC
And a default and readonly key to the GC.config hash that names the
current GC implementation.

This is provided by each implementation by the API function
rb_gc_impl_active_gc_name
2024-11-14 10:46:36 +00:00
Kazuki Yamaguchi a0f1f16145 asn1: fix ObjectId#==
Compare by the dotted decimal notation rather than the NID.

OpenSSL::ASN1::ObjectId can store OIDs that are not registered in
OpenSSL's internal table. NID is not defined for such an OID, but it is
not an error.

The == method also should not raise TypeError if the other object is
not an instance of OpenSSL::ASN1::ObjectId.

Fixes: https://github.com/ruby/openssl/issues/791
2024-11-14 11:21:39 +09:00
Kazuki Yamaguchi 419fb2f3b9 [ruby/openssl] x509: fix handling of multiple URIs in Certificate#crl_uris
The implementation of OpenSSL::X509::Certificate#crl_uris makes the
assumption that each DistributionPoint in the CRL distribution points
extension contains a single general name of type URI. This is not
guaranteed by RFC 5280. A DistributionPoint may contain zero or more
than one URIs.

Let's include all URIs found in the extension. If only non-URI pointers
are found, return nil.

Fixes: https://github.com/ruby/openssl/issues/775

https://github.com/ruby/openssl/commit/71f4fef2fa
2024-11-14 11:21:39 +09:00
Kazuki Yamaguchi 97be56fc62 [ruby/openssl] test_x509cert.rb: break up test_extension into smaller units
test_extesion is testing too many features at once and is hard to
navigate. Let's split each chunk apart for more clarity.

https://github.com/ruby/openssl/commit/461cfcb070
2024-11-14 11:21:39 +09:00
Hiroshi SHIBATA 1bab8bf88f [ruby/uri] Removed duplicated declare step for constants under the URI::RFC2396_REGEXP::PATTERN
https://github.com/ruby/uri/commit/60a8bc1575
2024-11-14 02:20:04 +00:00
Hiroshi SHIBATA 1d6c986104 [ruby/uri] Restore constants like URI::REGEXP::PATTERN::IPV6ADDR
https://github.com/ruby/uri/commit/ee9a38701a
2024-11-14 02:20:04 +00:00
Takashi Kokubun 01db456196 Move Array#map to Ruby
Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
2024-11-13 12:27:26 -08:00
HoneyryderChuck 2335768437 [ruby/openssl] make bn shareable when frozen
https://github.com/ruby/openssl/commit/d3c8e661e8
2024-11-13 07:25:51 +00:00
Jean Boussier ee1cd1656f ObjectSpace.dump: handle Module#set_temporary_name
[Bug #20892]

Until the introduction of that method, it was impossible for a
Module name not to be valid JSON, hence it wasn't going through
the slower escaping function.

This assumption no longer hold.
2024-11-12 20:21:27 +01:00
Peter Zhu eca3680c27 [ruby/prism] Fix use of uninitialized value when parsing regexp
Parsing the regexp /\A{/ causes uses an uninitialized value because it
tries to parse it as a range quantifier, so it reads the character after
the closing curly bracket. This is using uninitialized values because
prism strings are not null terminated. This can be seen in the Valgrind
output:

    ==834710== Conditional jump or move depends on uninitialised value(s)
    ==834710==    at 0x5DA010: pm_regexp_parse_range_quantifier (regexp.c:163)
    ==834710==    by 0x5DA010: pm_regexp_parse_quantifier (regexp.c:243)
    ==834710==    by 0x5DAD69: pm_regexp_parse_expression (regexp.c:738)
    ==834710==    by 0x5DAD69: pm_regexp_parse_pattern (regexp.c:761)
    ==834710==    by 0x5DAD69: pm_regexp_parse (regexp.c:773)
    ==834710==    by 0x5A2EE7: parse_regular_expression_named_captures (prism.c:20886)
    ==834710==    by 0x5A2EE7: parse_expression_infix (prism.c:21388)
    ==834710==    by 0x5A5FA5: parse_expression (prism.c:21804)
    ==834710==    by 0x5A64F3: parse_statements (prism.c:13858)
    ==834710==    by 0x5A9730: parse_program (prism.c:22011)
    ==834710==    by 0x576F0D: parse_input_success_p (extension.c:1062)
    ==834710==    by 0x576F0D: parse_success_p (extension.c:1084)

This commit adds checks for the end of the string to
pm_regexp_parse_range_quantifier.

https://github.com/ruby/prism/commit/be6cbc23ef
2024-11-12 14:19:46 +00:00
Misaki Shioi fee706d9dd
Allow Net::HTTP#request to raise Net::OpenTimeout (#12062)
with a TCPSoerver that is only listening
to avoid AssertionFailedError on Ubuntu.

---

The tests such as
`TestNetHTTP_v1_2_chunked#test_timeout_during_non_chunked_streamed_HTTP_session_write`
expect to raise a `Net::WriteTimeout` due to a failure in writing to the server.

However, on Ubuntu environments,
the server immediately returns a "Connection Refused" in such cases.
The socket created with `TCPSocket.new` that supports HEv2 catches this immediately
and raises a `Net::OpenTimeout`.
As a result, these tests fail due to raising a different exception than expected.
This PR adds `Net::OpenTimeout` asexceptions to avoid these test failures.
2024-11-12 19:14:05 +09:00
John Hawthorn 8409edc497 Fix regex timeout double-free after stack_double
As of 10574857ce, it's possible to crash
on a double free due to `stk_alloc` AKA `msa->stack_p` being freed
twice, once at the end of match_at and a second time in `FREE_MATCH_ARG`
in the parent caller.

Fixes [Bug #20886]
2024-11-11 23:33:21 -08:00
Jean Boussier 83702f7157 [ruby/pp] Handle BasicObject
Right now attempting to pretty print a BasicObject or any other
object lacking a few core Object methods will result in an error

```
Error: test_basic_object(PPTestModule::PPInspectTest): NoMethodError: undefined method `is_a?' for an instance of BasicObject
lib/pp.rb:192:in `pp'
lib/pp.rb:97:in `block in pp'
lib/pp.rb:158:in `guard_inspect_key'
lib/pp.rb:97:in `pp'
test/test_pp.rb:131:in `test_basic_object'
     128:
     129:   def test_basic_object
     130:     a = BasicObject.new
  => 131:     assert_match(/\A#<BasicObject:0x[\da-f]+>\n\z/, PP.pp(a, ''.dup))
     132:   end
     133: end
     134:
```

With some fairly small changes we can fallback to `Object#inspect`
which is better than an error.

https://github.com/ruby/pp/commit/4e9f6c2de0
2024-11-12 02:13:15 +00:00
Jean Boussier 107a4da122 [ruby/pp] Data#pretty_print handle privated or removed members
[Bug #20808]

The previous implementation assumed all members are accessible,
but it's possible for users to change the visibility of members or
to entirely remove the accessor.

https://github.com/ruby/pp/commit/fb19501434
2024-11-12 02:11:43 +00:00
Misaki Shioi 4c270200db
[Feature #120782] Introduction of Happy Eyeballs Version 2 (RFC8305) in TCPSocket.new (#11653)
* Introduction of Happy Eyeballs Version 2 (RFC8305) in TCPSocket.new

This is an implementation of Happy Eyeballs version 2 (RFC 8305) in `TCPSocket.new`.
See https://github.com/ruby/ruby/pull/11653

1. Background
Prior to this implementation, I implemented Happy Eyeballs Version 2 (HEv2) for `Socket.tcp` in https://github.com/ruby/ruby/pull/9374.
HEv2 is an algorithm defined in [RFC 8305](https://datatracker.ietf.org/doc/html/rfc8305), aimed at improving network connectivity.
For more details on the specific cases that HEv2 helps, please refer to https://bugs.ruby-lang.org/issues/20108.

2. Proposal & Outcome
This proposal implements the same HEv2 algorithm in `TCPSocket.new`.
Since `TCPSocket.new` is used more widely than `Socket.tcp`, this change is expected to broaden the impact of HEv2's benefits.
Like `Socket.tcp`, I have also added `fast_fallback` keyword argument to `TCPSocket.new`.
This option is set to true by default, enabling the HEv2 functionality.
However, users can explicitly set it to false to disable HEv2 and use the previous behavior of `TCPSocket.new`.

It should be noted that HEv2 is enabled only in environments where pthreads are available.
This specification follows the approach taken in https://bugs.ruby-lang.org/issues/19965 , where name resolution can be interrupted.
(In environments where pthreads are not available, the `fast_fallback` option is ignored.)

3. Performance
Below is the benchmark of 100 requests to `www.ruby-lang.org` with the fast_fallback option set to true and false, respectively.
While there is a slight performance degradation when HEv2 is enabled, the degradation is smaller compared to that seen in `Socket.tcp`.

```
~/s/build ❯❯❯ ../install/bin/ruby ../ruby/test.rb
Rehearsal --------------------------------------------------------
fast_fallback: true    0.017588   0.097045   0.114633 (  1.460664)
fast_fallback: false   0.014033   0.078984   0.093017 (  1.413951)
----------------------------------------------- total: 0.207650sec

                           user     system      total        real
fast_fallback: true    0.020891   0.124054   0.144945 (  1.473816)
fast_fallback: false   0.018392   0.110852   0.129244 (  1.466014)
```

* Update debug prints

Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>

* Remove debug prints

* misc

* Disable HEv2 in Win

* Raise resolution error with hostname resolution

* Fix to handle errors

* Remove warnings

* Errors that do not need to be handled

* misc

* Improve doc

* Fix bug on cancellation

* Avoid EAI_ADDRFAMILY for resolving IPv6

* Follow upstream

* misc

* Refactor connection_attempt_fds management

- Introduced allocate_connection_attempt_fds and reallocate_connection_attempt_fds for improved memory allocation of connection_attempt_fds
- Added remove_connection_attempt_fd to resize connection_attempt_fds dynamically.
- Simplified the in_progress_fds function to only check the size of connection_attempt_fds.

* Rename do_pthread_create to raddrinfo_pthread_create to avoid conflicting

---------

Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>
2024-11-12 10:06:48 +09:00
Peter Zhu 64827b15e8 [ruby/json] Fix $VERBOSE restore
Manually sync this commit that was missed.

https://github.com/ruby/json/commit/6ae9155
2024-11-11 15:13:24 -05:00
tomoya ishida 25d17868de [ruby/reline] Refactor perform_completon
(https://github.com/ruby/reline/pull/778)

Flatten recursive method
Remove CompletionState::COMPLETE

https://github.com/ruby/reline/commit/aa5b278f3d
2024-11-11 15:31:04 +00:00
Jean Boussier 1b6a26e23a [ruby/json] JSON.load_file: explictly load the file as UTF-8
Fix: https://github.com/ruby/json/issues/697

This way even if `Encoding.default_external` is set to a weird value
the document will be parsed just fine.

https://github.com/ruby/json/commit/3a8505a8fa
2024-11-11 09:40:11 +09:00
Sutou Kouhei a23c6db5c5 [ruby/fiddle] Accept Symbol as Function name again
GitHub: fix https://github.com/ruby/fiddle/pull/159

It's used by FFI test. So Symbol may be used by other use cases.

https://github.com/ruby/fiddle/pull/139 introduced the "Function name is String" limitation. This
commit removed the limitation.

Reported by Mamoru TASAKA. Thanks!!!

https://github.com/ruby/fiddle/commit/cea30fe5f9
2024-11-11 09:19:48 +09:00
tomoya ishida 5eaa4c76c6 [ruby/reline] Remove unused things from reline/unicode.rb
(https://github.com/ruby/reline/pull/759)

* Remove garbage(nil) from Reline::Unicode.split_by_width result

* Remove unused width from Reline::Unicode vi_ ed_ em_ method return value

* Remove unused height from Unicode.split_by_width return value

* Rename split_by_width to split_line_by_width and add legacy split_by_width for IRB

https://github.com/ruby/reline/commit/f32446ebc4
2024-11-10 19:11:58 +00:00
KJ Tsanaktsidis 2694585fb3 Fix race condition in test_self_stop
This test was relying on a sleep to synchronise the parent and child
processes. By having the child be the process that stops itself with
SIGSTOP, instead of the parent, we can actually properly wait for that
using waitpid2 and be notified of the stop.

This use of sleep to synchronise processes is potentially flaky and
caused failures under rr's `--chaos` mode.
2024-11-08 22:13:15 -07:00
John Hawthorn 1f6dd9071c Fix update_coderange for binary strings
Although a binary (aka ASCII-8BIT) string will never have a broken
coderange, it still has to differentiate between "valid" and "7bit".

On Ruby 3.4/trunk this problem is masked because we now clear the
coderange more agressively in rb_str_resize, and we happened to always
be strinking this string, but we should not assume that.

On Ruby 3.3 this created strings where `ascii_only?` was true in cases
it shouldn't be as well as other problems.

Fixes [Bug #20883]

Co-authored-by: Daniel Colson <danieljamescolson@gmail.com>
Co-authored-by: Matthew Draper <matthew@trebex.net>
2024-11-08 17:39:19 -08:00
Peter Zhu 51ffef2819 Fix memory leak in prism when syntax error in iseq compilation
If there's a syntax error during iseq compilation then prism would leak
memory because it would not free the pm_parse_result_t.

This commit changes pm_iseq_new_with_opt to have a rb_protect to catch
when an error is raised, and return NULL and set error_state to a value
that can be raised by calling rb_jump_tag after memory has been freed.

For example:

    10.times do
      10_000.times do
        eval("/[/=~s")
      rescue SyntaxError
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    39280
    68736
    99232
    128864
    158896
    188208
    217344
    246304
    275376
    304592

After:

    12192
    13200
    14256
    14848
    16000
    16000
    16000
    16064
    17232
    17952
2024-11-08 15:43:41 -05:00
Haldun Bayhantopcu 6767117b07 [ruby/prism] Fix splat after kwsplat
https://github.com/ruby/prism/commit/70c1cd480f
2024-11-08 15:50:54 +00:00
Yusuke Endoh fde6d189b2 Avoid calculating large powers
... for slow CI machines like macOS.
2024-11-08 20:53:21 +09:00
Yusuke Endoh 45cd4a8296 Do not round `a**b` to infinity
... instead, just calculate the value unless it is too big.
Also, this change raises an ArgumentError if it is expected to exceed
16 GB in a 64-bit environment.

(It is possible to calculate it straightforward, but it would likely be
out-of-memory, so I didn't think it would make sense.)

[Feature #20811]
2024-11-08 19:48:56 +09:00
Hiroshi SHIBATA d7c65398e0 [ruby/uri] Added more fallback constants like URI::PARTTERN and URI::REGEXP
Fixed https://github.com/ruby/uri/issues/125

https://github.com/ruby/uri/commit/1f3d3df02a
2024-11-08 06:06:30 +00:00
YO4 b99c17a95b [ruby/reline] Windows fix (https://github.com/ruby/reline/pull/775)
* test_yamatanooroti: close tempfile before unlink

* test_yamatanooroti: omit because of windows does not support job control

* test_yamatanooroti: change startup message detection for windows

* windows.rb: can call win32api using nil as NULL for pointer argument

Exception occurred when interrupted with Ctrl+C on legacy conhost

* windows.rb: fix get_screen_size

return [window height, buffer width] insted of [buffer height, buffer width]

* windows.rb: import scroll_down() from ansi.rb

* windows.rb: add auto linewrap control if VT output not supported (legacy console)

* unfreeze WIN32API pointer arguments

They internally duplicate arguments so api functions write to another place.
This breaks the console mode detection with ruby-head.

* remove useless code from Win32API#call

argument repacking and return value tweaking is not needed for Reline::Windows requirements.

* Correctly handle top of console viewport

* Revert "remove useless code from Win32API#call"

This reverts commit https://github.com/ruby/reline/commit/060ba140ed43.

* Revert "windows.rb: can call win32api using nil as NULL for pointer argument"

This reverts commit https://github.com/ruby/reline/commit/93a23bc5d0c9.

https://github.com/ruby/reline/commit/47c1ffbabe
2024-11-08 03:28:57 +00:00
Kaíque Kandy Koga 9523f53465
[ruby/benchmark] Adjust ljust Benchmark#bm with labels was not using the highest length among the labels to adjust the correct ljust. Instead of printing the result during the report generation, now it is waiting to print the result once it is generated.
Benchmark.bm { |x|
  x.item("aaaa") { 1 }
  x.item("aaaaaaaa") { 0 }
}

After

              user     system      total        real
aaaa      0.000005   0.000002   0.000007 (  0.000003)
aaaaaaaa  0.000001   0.000001   0.000002 (  0.000002)

Before

       user     system      total        real
aaaa  0.000005   0.000001   0.000006 (  0.000003)
aaaaaaaa  0.000002   0.000001   0.000003 (  0.000003)

https://github.com/ruby/benchmark/commit/3e74533ead
2024-11-08 11:32:30 +09:00
Nobuyoshi Nakada ee29aade1a
[Bug #20869] Discard read buffer and encoding converters at seeking 2024-11-07 21:03:37 +09:00
Nobuyoshi Nakada 1701ddea73
[Bug #20802] Copy encodings at reopen as well 2024-11-07 19:33:41 +09:00
Yusuke Endoh f87ec81e08 Prevent method redefinition warnings in test 2024-11-07 13:18:57 +09:00
Yusuke Endoh 6a39e6fc2d Prevent a warning: ambiguous `/` 2024-11-07 13:18:57 +09:00
Hartley McGuire 342455e56f [ruby/logger] Enable subclasses to configure level isolation
(https://github.com/ruby/logger/pull/103)

`Logger#with_level` was recently added to enable configuring a
`Logger`'s level for the duration of a block. However, the configured
level is always tied to the currently running `Fiber`, which is not
always ideal in applications that mix `Thread`s and `Fiber`s.

For example, Active Support has provided a similar feature
(`ActiveSupport::Logger#log_at`) which, depending on configuration, can
be isolated to either `Thread`s or `Fiber`s.

This commit enables subclasses of `Logger` to customize the level
isolation. Ideally, it will enable replacing most of Active Support's
`#log_at`, since both methods end up serving the same purpose.

https://github.com/ruby/logger/commit/dae2b832cd
2024-11-07 00:17:16 +00:00
Nobuyoshi Nakada 8254f6492c [ruby/json] Categorize deprecated warning
https://github.com/ruby/json/commit/1acce7aceb
2024-11-06 23:31:30 +01:00
Kasumi Hanazuki 35bf660337
io_buffer.c: Allow copies between overlapping buffers with #copy and #set_string (#11640)
The current implementation of `IO::Buffer#copy` and `#set_string` has
an undefined behavior when the source and destination memory overlaps,
due to the underlying use of the `memcpy` C function.

This patch guarantees the methods to be safe even when copying between
overlapping buffers by replacing `memcpy` with `memmove`,

Fixes: [Bug #20745]
2024-11-06 20:55:39 +00:00
Peter Zhu 56ecc243e2 [Bug #20868] Fix Method#hash to not change after compaction
The hash value of a Method must remain constant after a compaction, otherwise
it may not work as the key in a hash table.

For example:

    def a; end

    # Need this method here because otherwise the iseq may be on the C stack
    # which would get pinned and not move during compaction
    def get_hash
      method(:a).hash
    end

    puts get_hash # => 2993401401091578131

    GC.verify_compaction_references(expand_heap: true, toward: :empty)

    puts get_hash # => -2162775864511574135
2024-11-06 10:34:20 -05:00
KJ Tsanaktsidis 96e695ad00 Fix flakiness in TestGc#test_thrashing_for_young_objects
I caught a reproduction of this test failing under rr, and was able to
replay it to isolate the failure. The call to
`before_stat_heap = GC.stat_heap` is itself allocating a hash, which in
unlucky circumstances can result in a new page being allocated and thus
`before_stats[:heap_allocated_pages]` no longer equals
`after_stats[:heap_allocated_pages]`.

The solution is to use the form of GC.stat/stat_heap which takes a hash
as an argument, and thus needs to perform no Ruby allocations itself.
2024-11-06 09:58:47 -05:00
David Rodríguez 350baed6a9 [rubygems/rubygems] Fix manifest in gem package using incorrect platform sometimes
If a gem package is built from a specification whose platform has been
modified, it will include metadata using the old platform.

This change should fix the problem by making sure `original_platform` is
always properly set.

https://github.com/rubygems/rubygems/commit/ecd5cd4547
2024-11-06 11:37:29 +00:00
Samuel Williams 3b9896acfc
Revert "Introduce Fiber Scheduler `blocking_region` hook. (#11963)" (#12013)
This reverts some of commit 87fb44dff6.

We will rename and propose a slightly different interface.
2024-11-06 22:19:40 +13:00
Hiroshi SHIBATA a2dd471d9e
macOS 15 is the stable version today 2024-11-06 15:45:32 +09:00
Nobuyoshi Nakada d71be7274b
[Bug #20873] Consider `-FIXNUM_MIN` overflow
`-FIXNUM_MIN` is usually greater than `FIXNUM_MAX` on platforms using
two's complement representation.
2024-11-06 13:31:38 +09:00