summaryrefslogtreecommitdiff
path: root/ext
AgeCommit message (Collapse)Author
2024-12-02[ruby/io-console] Add IO#ttyname that returns the tty name or nilNobuyoshi Nakada
https://github.com/ruby/io-console/commit/fdad351501
2024-12-02[ruby/date] Bump up 3.4.1Hiroshi SHIBATA
https://github.com/ruby/date/commit/a3295ad262
2024-12-02[ruby/io-console] Freeze the version stringNobuyoshi Nakada
https://github.com/ruby/io-console/commit/aa79919f79
2024-12-02[ruby/io-console] Check if `rb_syserr_fail_str` is availableNobuyoshi Nakada
Truffle ruby seems to lack it. https://github.com/ruby/io-console/commit/839c1e80eb
2024-12-02Removed trailing spacesHiroshi SHIBATA
2024-12-02[ruby/strscan] Micro optimize encoding checksJean Boussier
(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 https://github.com/ruby/strscan/commit/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 https://github.com/ruby/strscan/commit/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 ``` https://github.com/ruby/strscan/commit/c02b1ce684
2024-12-02StringScanner#scan_integer support base 16 integers (#116)Jean Boussier
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-11-30Improve the conditions for clearing the Connection Attempt Delay upon ↵Misaki Shioi
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 Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-29Ensure to close pipes when `TCPSocket.new` finishes processing (#12181)Misaki Shioi
`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. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-29Allow disable to `fast_fallback` of `TCPSocket.new` (#12210)Misaki Shioi
with `Socket.tcp_fast_fallback=` The functions that `Socket.tcp` had are now also available in `TCPSocket.new`. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-29Remove a useless check if fd is negativeYusuke Endoh
If `slave` is negative, neither `dup2(slave,0)` or `close(slave)` should be executed. I believe this check is completely useless. Notes: Merged: https://github.com/ruby/ruby/pull/12207
2024-11-29[ruby/date] Fix mixed declarations and codeNobuyoshi Nakada
This still support ruby 2.6 which does not require C99. https://github.com/ruby/date/commit/61d849758f
2024-11-29[ruby/date] Suppress compound-token-split-by-macro warningsNobuyoshi Nakada
It was used intentionally. https://github.com/ruby/date/commit/291b40f939
2024-11-28Ensure to free fast_fallback_getaddrinfo_shared with single family (#12199)Misaki Shioi
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. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-27[ruby/json] Prevent a warning of "a candidate for gnu_printf format attribute"Yusuke Endoh
GCC 13 prints the following warning. https://rubyci.s3.amazonaws.com/ubuntu/ruby-master/log/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. https://github.com/ruby/json/commit/b8c1490846
2024-11-27[ruby/io-console] Read errno before calling rb_io_path()Alan Wu
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.) https://github.com/ruby/io-console/commit/0ba400b5e7
2024-11-27Revert "Add a temporal debugging code"Yusuke Endoh
This reverts commit 5bd144c1bb20e22e4d9f5e5e0264820fd3ef8137.
2024-11-27[ruby/strscan] Implement #scan_integer to efficiently parse IntegerJean Boussier
(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. https://github.com/ruby/strscan/commit/6a3c74b4c8
2024-11-26JSON::GeneratorError expose invalid objectJean Boussier
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[ruby/json] Stop using `rb_gc_mark_locations`Jean Boussier
It's using `rb_gc_mark_maybe` under the hood, which isn't what we need. https://github.com/ruby/json/commit/e10d0bffcd
2024-11-26[ruby/json] JSON.dump: write directly into the provided IOJean Boussier
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. https://github.com/ruby/json/commit/f017af6c0a
2024-11-25Prevent memory leakYusuke Endoh
``` 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.) Notes: Merged: https://github.com/ruby/ruby/pull/12163
2024-11-25Fix initialization of `struct wait_fast_fallback_arg::cancelled`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12161
2024-11-25Do not save the last error without sockets in the connection attempt (#12153)Misaki Shioi
* 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 Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-24UBF is also required for synchronous name resolution (#12156)Misaki Shioi
`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. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-23Save the error that occurred during name resolution (#12155)Misaki Shioi
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. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-22[ruby/openssl] Support signing CRLs using Ed25519Josh Cooper
Allow CRLs to be signed using Ed25519 private keys by passing a nil digest. https://github.com/ruby/openssl/commit/b62375bcde
2024-11-22[ruby/openssl] Support signing requests using Ed25519Josh Cooper
Allow requests to be signed using Ed25519 private keys by passing a nil digest. This is similar to commit https://github.com/ruby/openssl/commit/b0fc10009120 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. https://github.com/ruby/openssl/commit/d96090320d
2024-11-22Add a temporal debugging codeYusuke Endoh
... 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 ``` Notes: Merged: https://github.com/ruby/ruby/pull/12147
2024-11-22[Bug #20903] `rb_econv_str_append` arguments expected to be StringNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12145
2024-11-21Fix the usage of reallocYusuke Endoh
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-20[ruby/zlib] Add support for safe offload of nogvl code.Samuel Williams
(https://github.com/ruby/zlib/pull/89) https://github.com/ruby/zlib/commit/a535271862
2024-11-20[ruby/zlib] Don't call `rb_str_set_len` while released the GVL.Samuel Williams
(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] https://github.com/ruby/zlib/commit/e445cf3c80
2024-11-20[ruby/psych] Eagerly require `date`.Thierry Deo
https://github.com/ruby/psych/commit/b2aa0032c0
2024-11-20[ruby/etc] Prefer `rb_intern_const` over `rb_intern` for literal stringsNobuyoshi Nakada
https://github.com/ruby/etc/commit/53362d891c
2024-11-20[ruby/digest] Remove obsolete test runner [ci skip]Nobuyoshi Nakada
This file is platform dependent, outdated and already not working. Use `rake` instead. https://github.com/ruby/digest/commit/a2a917dc71
2024-11-19[ruby/digest] Fix `-Wundef` warningsNobuyoshi Nakada
https://github.com/ruby/digest/commit/0ea3ac9926
2024-11-18[ruby/digest] Adjust styles [ci skip]Nobuyoshi Nakada
- Use the C90 standard style for comments, since this gem supports versions prior to ruby 2.7. - Adjust the indentation. https://github.com/ruby/digest/commit/4751402e50
2024-11-18[ruby/digest] Fix loading of digest ext libraries with ↵Yuta Saito
`--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`. https://github.com/ruby/digest/commit/f8ff014622
2024-11-18[ruby/json] Fix the BEWARE documentation in `load` and `unsafe_load`.Jean Boussier
https://github.com/ruby/json/commit/2d62ec449f Notes: Merged: https://github.com/ruby/ruby/pull/12103
2024-11-18[ruby/json] Release 2.8.2Jean Boussier
https://github.com/ruby/json/commit/d5e4a6e3fd Notes: Merged: https://github.com/ruby/ruby/pull/12103
2024-11-18[ruby/json] Fix redundant to_str callrazokulover
https://github.com/ruby/json/commit/61f022dfbd Notes: Merged: https://github.com/ruby/ruby/pull/12103
2024-11-17Fix stack-use-after-return (#12105)Misaki Shioi
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 ================================================================= ``` Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-16[ruby/io-nonblock] mark extension as ractor safeHoneyryderChuck
https://github.com/ruby/io-nonblock/commit/ba445b37d5
2024-11-15Make fast_fallback option false by default temporarily (#12070)Misaki Shioi
to suppress failing output in CI. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-14Fix a stack-buffer-overflow bugYusuke Endoh
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) ``` Notes: Merged: https://github.com/ruby/ruby/pull/12089
2024-11-15Do not wait connection attempt delay without in progress fds (#12087)Misaki Shioi
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. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-14asn1: fix ObjectId#==Kazuki Yamaguchi
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[ruby/openssl] pkcs7: fix memory leak in error path of PKCS7.new and .read_smimeKazuki Yamaguchi
A follow-up to commit https://github.com/ruby/openssl/commit/27e11f2d1dcd and https://github.com/ruby/openssl/commit/07eceb7f6326. The PKCS7 object must be freed before raising an exception. https://github.com/ruby/openssl/commit/172eee4665
2024-11-14[ruby/openssl] x509: fix handling of multiple URIs in Certificate#crl_urisKazuki Yamaguchi
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