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

9290 Коммитов

Автор SHA1 Сообщение Дата
p0pemaru cb6dcc7746 [ruby/date] [DOC] specify the unit of return value for Date#-
https://github.com/ruby/date/commit/b3a2c7611e
2024-06-03 05:24:18 +00:00
Nobuyoshi Nakada 77e5e06846 [ruby/date] Prevent converted gregorian date from GC
`m_sf_in_sec` calls `rb_rational_new` that can cause GC.

https://github.com/ruby/date/commit/6de449ab6a
2024-06-03 05:23:44 +00:00
Yusuke Endoh b346eb8f14 Raise EAI_SYSTEM when pthread_create fails in getaddrinfo
Previously, EAI_AGAIN was raised.

In our CI, "Temporary failure in name resolution" (EAI_AGAIN) is often
raised. We are not sure if this was caused by pthread_create failure or
getaddrinfo failure. To make it possible to distinguish between them,
this changeset raises EAI_SYSTEM instead of EAI_AGAIN on pthread_create
failure.
2024-06-03 10:44:30 +09:00
Jean Boussier 730e3b2ce0 Stop exposing `rb_str_chilled_p`
[Feature #20205]

Now that chilled strings no longer appear as frozen, there is no
need to offer an API to check for chilled strings.

We however need to change `rb_check_frozen_internal` to no
longer be a macro, as it needs to check for chilled strings.
2024-06-02 13:53:35 +02:00
Nobuyoshi Nakada a720a1c447
Suppress -Wmaybe-uninitialized warnings with LTO 2024-06-01 16:22:31 +09:00
Jean Boussier 15501e13d7 [ruby/stringio] Remove special handling of chilled strings
[Feature #20205]

Followup: https://github.com/ruby/stringio/pull/94

They no longer need to be special cases. If StringIO end up
mutating a chilled string, a warning will be emitted.

https://github.com/ruby/stringio/commit/dc62d65449
2024-05-30 15:11:48 +00:00
Hiroshi SHIBATA 78bfde5d9f
Revert "[ruby/strscan] Doc for StringScanner"
This reverts commit 974ed1408c.
2024-05-30 21:13:10 +09:00
Hiroshi SHIBATA d70b0da482
Revert "Fix reference path for strscan documentation"
This reverts commit 1fa93fb948.
2024-05-30 21:13:01 +09:00
Hiroshi SHIBATA 1fa93fb948
Fix reference path for strscan documentation 2024-05-30 14:29:25 +09:00
Burdette Lamar 974ed1408c
[ruby/strscan] Doc for StringScanner
(https://github.com/ruby/strscan/pull/96)

#peek_byte and #scan_byte not updated (not available in my repo --
sorry).

---------

https://github.com/ruby/strscan/commit/0123da7352

Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
2024-05-30 12:34:18 +09:00
Hiroshi SHIBATA 79f9ed3072 [ruby/zlib] Update license files with ruby/ruby
https://github.com/ruby/zlib/commit/8341fa2e20
2024-05-29 23:23:49 +00:00
Mike Dalessio ca2d229e6b Test for compiling without warnings against public headers
Under compilers with WERRORFLAG, MakeMakefile.try_compile treats
warnings as errors, so we can use append_cflags to test whether the
public header files emit warnings with certain flags turned on.

[Regression test for feature #20507]
2024-05-28 07:33:07 +02:00
Nobuyoshi Nakada 4c7ec5e014
ripper: Extend to represent array access and splat 2024-05-21 13:52:30 +09:00
Nobuyoshi Nakada 66446b9435
ripper: Allow parenthesized comma in options 2024-05-21 13:52:29 +09:00
Nobuyoshi Nakada 47efdae602
ripper: Preserve indentation 2024-05-21 13:52:29 +09:00
Nobuyoshi Nakada 147134b474
ripper: Remove rb_ripper_none
Now it is used only for wheter `opt_paren_args` is `none`.  Introduce
a new special node to distinguish an empty parentheses from it .
2024-05-21 13:52:29 +09:00
Nobuyoshi Nakada 2e765c20db
ripper: Short hand for `rb_ary_new_from_args` 2024-05-21 13:52:29 +09:00
Nobuyoshi Nakada 2d92a4afba
ripper: Make `$:n` to refer each grammar values
Ripper DSL uses these values for callbacks, but does not need indexes.
2024-05-21 13:52:29 +09:00
Samuel Giddins e3e1e53098 [ruby/zlib] Avoid double copying into provided outbuf
https://github.com/ruby/zlib/commit/07f44b7546
2024-05-14 21:44:34 +00:00
Samuel Giddins e33336cb37 [ruby/zlib] Avoid allocating intermediary strings when read/readpartial are passed an outbuf
This accounts for a significant number of string allocations when reading rubygems, but we can avoid that in many places by only copying into the outbuf when present

https://github.com/ruby/zlib/commit/d25ef406c1
2024-05-14 21:44:34 +00:00
Samuel Giddins 841b45a442 [ruby/openssl] Add to_text for PKCS7 and Timestamp::Response
https://github.com/ruby/openssl/commit/71cd1e3f5c
2024-05-08 09:39:13 +00:00
Jean Boussier 7d42010fad [ruby/openssl] read: don't clear buffer when nothing can be read
To be consistent with regular Ruby IOs:

```ruby
r, _ = IO.pipe
buf = "garbage".b
r.read_nonblock(10, buf, exception: false) # => :wait_readable
p buf # => "garbage"
```

Ref: 98b8944460

https://github.com/ruby/openssl/commit/08452993d6
2024-05-05 08:00:00 +00:00
yui-knk cf74ff714a Change return value of `gets` function to be `rb_parser_string_t *` instead of `VALUE`
This change reduces parser's dependency on ruby object.
2024-05-04 11:59:10 +09:00
Nobuyoshi Nakada 7662e6fcd5
win32/registry: Shorten with safe navigation operator 2024-05-03 14:49:29 +09:00
Nobuyoshi Nakada 491c38bfcd
win32/registry: Make frozen_string_literal true 2024-05-03 14:49:29 +09:00
Nobuyoshi Nakada 0b091e6675
win32/registry: Refine pack/unpack
* Use 'J' for HANDLE.
* Use 'Q' for QWORD.
* Define template constants.
* Supply zero bytes in `unpackqw` as well as `unpackdw`.
* Use `String#unpack1`.
2024-05-03 14:49:29 +09:00
Jeremy Evans 55720f372d [ruby/openssl] pkcs7: raise PKCS7Error for PKCS7 without content in PKCS7.read_smime
[pkuzco: expanded the fix for other content types]
[ky: adjusted formatting and the exception type]

https://github.com/ruby/openssl/commit/07eceb7f63

Co-authored-by: pkuzco <b.naamneh@gmail.com>
Co-authored-by: Kazuki Yamaguchi <k@rhe.jp>
2024-05-02 16:26:11 +09:00
Jeremy Evans c9aa63a9e0 [ruby/openssl] pkcs7: raise ArgumentError for PKCS7 with no content in PKCS7.new
Fixes [Bug #19974]

[pkuzco: expanded the fix for other content types]
[ky: adjusted formatting and the exception type]

https://github.com/ruby/openssl/commit/27e11f2d1d

Co-authored-by: pkuzco <b.naamneh@gmail.com>
Co-authored-by: Kazuki Yamaguchi <k@rhe.jp>
2024-05-02 16:26:11 +09:00
Kazuki Yamaguchi eb6f0000a4 [ruby/openssl] cipher: fix buffer overflow in Cipher#update
OpenSSL::Cipher#update currently allocates the output buffer with size
(input data length)+(the block size of the cipher). This is insufficient
for the id-aes{128,192,256}-wrap-pad (AES keywrap with padding) ciphers.
They have a block size of 8 bytes, but the output may be up to 15 bytes
larger than the input.

Use (input data length)+EVP_MAX_BLOCK_LENGTH (== 32) as the output
buffer size, instead. OpenSSL doesn't provide a generic way to tell the
maximum required buffer size for ciphers, but this is large enough for
all algorithms implemented in current versions of OpenSSL.

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

https://github.com/ruby/openssl/commit/3035559f54
2024-05-02 16:26:11 +09:00
Jaymz Julian d39993a4ce [ruby/openssl] Fix performance regression in do_write(s)
This causes significant performance issues when using large (>10meg) writes

Fix by adjusting the buffer write function to clear the buffer once, rather than
piece by piece, avoiding a case where a large write (in our case, around
70mbytes) will consume 100% of CPU. This takes a webrick GET request via SSL
from around 200kbyts/sec and consuming 100% of a core, to line speed on gigabit
ethernet and 6% cpu utlization.

https://github.com/ruby/openssl/commit/d4389b425d
2024-05-02 16:24:36 +09:00
Kazuki Yamaguchi f5af620c61 [ruby/openssl] asn1: check error return from i2d_ASN1_TYPE()
i2d_ASN1_TYPE() is not expected to fail, but the return value should be
checked.

https://github.com/ruby/openssl/commit/21ed3c310e
2024-05-02 07:17:35 +00:00
Bart de Water 9d75d9f07c [ruby/openssl] Update Cipher#name to match Digest#name explanation
https://github.com/ruby/openssl/commit/79e6dead6e
2024-04-30 15:05:50 +00:00
Bart de Water cc6657e563 [ruby/openssl] Add OpenSSL::Digest.digests to get a list of available digests
https://github.com/ruby/openssl/commit/08dd3c73b7
2024-04-30 15:05:50 +00:00
Samuel Williams 368ce0758e [ruby/openssl] Further clarification of documentation.
https://github.com/ruby/openssl/commit/0697f2f8b4
2024-04-30 14:51:59 +00:00
Samuel Williams f1afae2459 [ruby/openssl] More documentation.
https://github.com/ruby/openssl/commit/c8377eaf8d
2024-04-30 14:51:59 +00:00
Samuel Williams 1699772ac4 [ruby/openssl] Introduce basic support for `close_read` and `close_write`.
https://github.com/ruby/openssl/commit/c99d24cee9
2024-04-30 14:51:58 +00:00
Nobuyoshi Nakada a6308ca958 ripper: Move DSL line pattern 2024-04-29 08:38:23 +09:00
ydah f9cf923af2 Use user defined parameterizing rules 2024-04-29 08:38:23 +09:00
卜部昌平 c844968b72 ruby tool/update-deps --fix 2024-04-27 21:55:28 +09:00
Sam Aaron 67b79d484f
Enable Ruby to run on Windows with frozen string literals 2024-04-26 15:10:42 +00:00
Nobuyoshi Nakada 91ff2fd9b5 Fix dllimport warnings
From Visual C:
```
../../../../../src/ext/-test-/load/resolve_symbol_target/resolve_symbol_target.c(5): warning C4273: 'rst_any_method': inconsistent dll linkage
D:\a\ruby\ruby\src\ext\-test-\load\resolve_symbol_target\resolve_symbol_target.h(4): note: see previous definition of 'rst_any_method'
../../../../../src/ext/-test-/load/stringify_target/stringify_target.c(5): warning C4273: 'stt_any_method': inconsistent dll linkage
D:\a\ruby\ruby\src\ext\-test-\load\stringify_target\stringify_target.h(4): note: see previous definition of 'stt_any_method'
```

From MinGW gcc:
```
../../../../../src/ext/-test-/load/resolve_symbol_target/resolve_symbol_target.c:5:1: warning: 'rst_any_method' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
compiling ../../../../../src/ext/-test-/marshal/compat/usrcompat.c
    5 | rst_any_method(VALUE klass)
      | ^~~~~~~~~~~~~~
../../../../../src/ext/-test-/load/stringify_target/stringify_target.c:5:1: warning: 'stt_any_method' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
    5 | stt_any_method(VALUE klass)
      | ^~~~~~~~~~~~~~
```
2024-04-24 18:02:09 +09:00
yui-knk 33929ef995 Move encoding object conversion outside of parser
Reduce the parser's dependence on `VALUE` and `rb_enc_from_encoding`.
2024-04-23 13:11:46 +09:00
Nobuyoshi Nakada afa0d58580
Adjust indent [ci skip] 2024-04-23 09:21:38 +09:00
yui-knk 2992e1074a Refactor parser compile functions
Refactor parser compile functions to reduce the dependence
on ruby functions.
This commit includes these changes

1. Refactor `gets`, `input` and `gets_` of `parser_params`

Parser needs two different data structure to get next line, function (`gets`) and input data (`input`).
However `gets_` is used for both function (`call`) and input data (`ptr`).
`call` is used for managing general callback function when `rb_ruby_parser_compile_generic` is used.
`ptr` is used for managing the current pointer on String when `parser_compile_string` is used.
This commit changes parser to used only `gets` and `input` then removes `gets_`.

2. Move parser_compile functions and `gets` functions from parse.y to ruby_parser.c

This change reduces the dependence on ruby functions from parser.

3. Change ruby_parser and ripper to take care of `VALUE input` GC mark

Move the responsibility of calling `rb_gc_mark` for `VALUE input` from parser to ruby_parser and ripper.
`input` is arbitrary data pointer from the viewpoint of parser.

4. Introduce rb_parser_compile_array function

Caller of `rb_parser_compile_generic` needs to take care about GC because ruby_parser doesn’t know
about the detail of `lex_gets` and `input`.
Introduce `rb_parser_compile_array` to reduce the complexity of ast.c.
2024-04-23 07:20:22 +09:00
Nobuyoshi Nakada 801e4a4feb
Remove UPDATE_LIBRARIES
It has not been used since e48375c112.
2024-04-19 14:12:42 +09:00
Jean byroot Boussier 75154dec73 [ruby/stringio] strio_read: preserve buffer encoding on partial
reads
(https://github.com/ruby/stringio/pull/95)

[[Bug #20418]](https://bugs.ruby-lang.org/issues/20418)

Ruby IO#read preserves the encoding on partial read, but change it when
reading the whole IO

from commit https://github.com/ruby/ruby/commit/0ca7036682da:
> * io.c (read_all): should associate default external encoding.
> * io.c (io_read): should NOT associate default external encoding.

https://github.com/ruby/stringio/commit/073172da31

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-04-17 01:29:18 +00:00
Peter Zhu f8f542bd9b [ruby/pathname] Remove check for File.birthtime
File.birthtime has existed since Ruby 2.2, and pathname requires Ruby
>= 2.7.0, so the method will always be there.

https://github.com/ruby/pathname/commit/aca9613bbf
2024-04-16 05:48:57 +00:00
Nobuyoshi Nakada 8d5d6ec6e7
[pty] Fix missing `or` 2024-04-14 20:35:34 +09:00
Nobuyoshi Nakada 3368913be3 [pty] Fix `ptsname_r` fallback
If `posix_openpt` is available, also `ptsname` should be available.
2024-04-14 20:27:05 +09:00
yui-knk 38b8bdb8ea Remove undefined function's prototype declaration
89cfc15207 removed the definition of these functions.
2024-04-14 10:51:16 +09:00
Nobuyoshi Nakada e7f8db9079
[pty] Support `ptsname_r` of glibc
Although glibc `ptsname_r` man page mentions Tru64 and HP-UX, this
function appears to be declared obsolete on both.
2024-04-11 17:57:52 +09:00
Nobuyoshi Nakada 0bc71828b5 [pty] Split `chfunc` into functions in steps
- start a new session
- obtain the new controlling terminal
- drop privileges
- finally, `exec`
2024-04-09 22:50:09 +09:00
Nobuyoshi Nakada c4dadfbd47
Fix a typo, missing `P` in `SETPGRP_VOID` 2024-04-07 20:54:00 +09:00
Nobuyoshi Nakada 3ac6a03b2e
Revert "hijack SIGCHLD handler for internal use"
This reverts commit 054a412d54.
SIGCHLD `waidpid`, `waitpid_lock` and related code, have been removed
at ruby/ruby#7527.
2024-04-04 21:48:14 +09:00
Hiroshi SHIBATA ab65148c78 [flori/json] Bump up 2.7.2
https://github.com/flori/json/commit/036944acc6
2024-04-04 12:46:02 +09:00
Hiroshi SHIBATA 514b415d90 [flori/json] Warn to install ostruct if json couldn't load it
https://github.com/flori/json/commit/fff285968d
2024-04-04 12:46:02 +09:00
tompng 066bd28cff [flori/json] Autoload GenericObject to avoid require ostruct warning in Ruby 3.4
https://github.com/flori/json/commit/b507f9e404
2024-04-04 12:46:01 +09:00
yui-knk e816ab0b0c Remove `rb_imemo_tmpbuf_t` from parser
No parser semantic value types are `VALUE` then no need to
use imemo for managing semantic value stack anymore.
2024-04-02 19:37:27 +09:00
yui-knk 799e854897 [Feature #20331] Simplify parser warnings for hash keys duplication and when clause duplication
This commit simplifies warnings for hash keys duplication and when clause duplication,
based on the discussion of https://bugs.ruby-lang.org/issues/20331.
Warnings are reported only when strings are same to ohters.
2024-04-02 08:26:58 +09:00
Hiroshi SHIBATA 7630a89a4b Use www.rfc-editor.org for RFC text.
We use the following site for that now:

* https://tools.ietf.org/ or http
* https://datatracker.ietf.org or http

Today, IETF said the official site of RFC is www.rfc-editor.org.

FYI: https://authors.ietf.org/en/references-in-rfcxml

I replaced them to www.rfc-editor.org.
2024-03-28 11:44:45 +09:00
Nobuyoshi Nakada 51e6becd39 [ruby/stringio] Extract `readonly_string_p`
https://github.com/ruby/stringio/commit/0da5b725c8
2024-03-27 17:41:38 +00:00
Nobuyoshi Nakada 06563d78a1 [ruby/stringio] Adjust styles [ci skip]
https://github.com/ruby/stringio/commit/4e8e82fc30
2024-03-28 02:27:20 +09:00
Étienne Barrié 0f5ab4ad52 [ruby/stringio] Eagerly defrost chilled strings
[Feature #20390]

https://github.com/ruby/stringio/commit/17ee957f34

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-03-28 02:27:19 +09:00
Peter Zhu 6e34386794
[flori/json] Fix memory leak when exception is raised during JSON generation
If an exception is raised the FBuffer is leaked.

For example, the following script leaks memory:

    o = Object.new
    def o.to_json(a) = raise

    10.times do
      100_000.times do
        begin
          JSON(o)
        rescue
        end
      end

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

Before:

    31824
    35696
    40240
    44304
    47424
    50944
    54000
    58384
    62416
    65296

After:

    24416
    24640
    24640
    24736
    24736
    24736
    24736
    24736
    24736
    24736

https://github.com/flori/json/commit/44df509dc2
2024-03-27 08:24:28 +09:00
Étienne Barrié 2b08406cd0 Expose rb_str_chilled_p
Some extensions (like stringio) may need to differentiate between
chilled strings and frozen strings.

They can now use rb_str_chilled_p but must check for its presence since
the function will be removed when chilled strings are removed.

[Bug #20389]

[Feature #20205]

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-03-26 12:54:54 +01:00
Nobuyoshi Nakada 8265a7531f
Use dedicated methods to abort
When `RUBY_DEBUG` is set, accessing a class in an invalid object will
cause a breakpoint trap instead of a segfault on some implementations.
2024-03-24 01:40:17 +09:00
Nobuyoshi Nakada 678cb80033
Move `-test-/fatal/rb_fatal` to `-test-/fatal` 2024-03-24 01:09:29 +09:00
Nobuyoshi Nakada 43fe89d921 [ruby/win32ole] Refine pathspecs for `spec.files`
https://github.com/ruby/win32ole/commit/8d443417a9
2024-03-23 13:06:40 +00:00
Nobuyoshi Nakada 14fba5a784 [ruby/win32ole] Exclude unused files from packages
https://github.com/ruby/win32ole/commit/f4aff99dda
2024-03-23 10:34:57 +00:00
Nobuyoshi Nakada af88ca4c07
Match `--with/--without` options against gem names
The simple names in `default_exclude_exts` do not match extension
paths under gems.

Extract each gem name from the gemspec file at the top level of each
gem directory.  For example, if `ext` is `syslog-0.1.2/ext/syslog/`,
find out `syslog-0.1.2/syslog.gemspec` and take the base name `syslog`
without the suffix `.gemspec`.
2024-03-22 14:09:12 +09:00
Nobuyoshi Nakada 235aa7ad63
Pass blocks to blocks as block parameters 2024-03-22 14:06:55 +09:00
S-H-GAMELINKS 060a71d4e7 Fix Ripper memory allocation size when enabled Universal Parser
The size of `struct parser_params` is 8 bytes difference in `ripper_s_allocate` and `rb_ruby_parser_allocate` when the universal parser is
enabled.
This causes a situation where `*r->p` is not fully initialized in `ripper_s_allocate` as shown below.

```console
(gdb) p *r->p
$2 = {heap = 0x0, lval = 0x0, yylloc = 0x0, lex = {strterm = 0x0, gets = 0x0, input = 0, string_buffer = {head = 0x0, last = 0x0}, lastlin
e = 0x0,
    nextline = 0x0, pbeg = 0x0, pcur = 0x0, pend = 0x0, ptok = 0x0, gets_ = {ptr = 0, call = 0x0}, state = EXPR_NONE, paren_nest = 0, lpar
_seen = 0,
    debug = 0, has_shebang = 0, token_seen = 0, token_info_enabled = 0, error_p = 0, cr_seen = 0, value = 0, result = 0, parsing_thread = 0, s_value = 0,
    s_lvalue = 0, s_value_stack = 2097}
````

This seems to cause `double free or corruption (!prev)` and SEGV.
So, fixing this by introduce `rb_ripper_parser_params_allocate` and `rb_ruby_parser_config` functions for Ripper, and `struct parser_params` same size is returned.
2024-03-21 18:10:02 +09:00
Benoit Daloze 6ecee4ec31 [ruby/openssl] Revert "Always respect the openssl prefix chosen by truffle/openssl-prefix on TruffleRuby"
* This reverts commit https://github.com/ruby/openssl/commit/ca738e7e1357.
* No longer needed since https://github.com/oracle/truffleruby/issues/3170 was fixed.

https://github.com/ruby/openssl/commit/1f641a5604
2024-03-20 11:44:13 +00:00
Étienne Barrié 12be40ae6b Implement chilled strings
[Feature #20205]

As a path toward enabling frozen string literals by default in the future,
this commit introduce "chilled strings". From a user perspective chilled
strings pretend to be frozen, but on the first attempt to mutate them,
they lose their frozen status and emit a warning rather than to raise a
`FrozenError`.

Implementation wise, `rb_compile_option_struct.frozen_string_literal` is
no longer a boolean but a tri-state of `enabled/disabled/unset`.

When code is compiled with frozen string literals neither explictly enabled
or disabled, string literals are compiled with a new `putchilledstring`
instruction. This instruction is identical to `putstring` except it marks
the String with the `STR_CHILLED (FL_USER3)` and `FL_FREEZE` flags.

Chilled strings have the `FL_FREEZE` flag as to minimize the need to check
for chilled strings across the codebase, and to improve compatibility with
C extensions.

Notes:
  - `String#freeze`: clears the chilled flag.
  - `String#-@`: acts as if the string was mutable.
  - `String#+@`: acts as if the string was mutable.
  - `String#clone`: copies the chilled flag.

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-03-19 09:26:49 +01:00
Nobuyoshi Nakada e670892497
Remove no longer needed matching 2024-03-17 18:47:18 +09:00
Nobuyoshi Nakada 9e470ebdcd
Revert "Remove flip-flop usages from build scripts"
This reverts commit 301fa452f7.
2024-03-17 18:28:28 +09:00
Nobuyoshi Nakada a1ced60692 [ruby/stringio] NULL StringIO by `StringIO.new(nil)`
https://github.com/ruby/stringio/commit/779f71359d
2024-03-15 04:34:14 +00:00
Jean Boussier 09d8c99cdc Ensure test suite is compatible with --frozen-string-literal
As preparation for https://bugs.ruby-lang.org/issues/20205
making sure the test suite is compatible with frozen string
literals is making things easier.
2024-03-14 17:56:15 +01:00
Nobuyoshi Nakada 578f96afb5 [ruby/stringio] [DOC] Package rdoc files
https://github.com/ruby/stringio/commit/8522c90e4b
2024-03-14 04:30:28 +00:00
Nobuyoshi Nakada c913f3347c [ruby/stringio] [DOC] Add missing documents
https://github.com/ruby/stringio/commit/9cc1dfa19c
2024-03-14 04:30:28 +00:00
Nobuyoshi Nakada 35706c608c [ruby/stringio] [DOC] Add rdoc task
https://github.com/ruby/stringio/commit/5dd52d4aec
2024-03-14 04:30:27 +00:00
Nobuyoshi Nakada b01d319ec8 [ruby/fcntl] [DOC] Package files for RDoc
https://github.com/ruby/fcntl/commit/b946e505f1
2024-03-14 04:19:46 +00:00
Nobuyoshi Nakada e394f5539e [ruby/fcntl] [DOC] Package document files
https://github.com/ruby/fcntl/commit/ed2d725505
2024-03-14 04:01:24 +00:00
Nobuyoshi Nakada 4ae67b1ab5 [ruby/fcntl] [DOC] Add missing documents
https://github.com/ruby/fcntl/commit/a201ed6682
2024-03-14 03:49:40 +00:00
Nobuyoshi Nakada 085daf4840 [ruby/fcntl] [DOC] Add task and files for RDoc
https://github.com/ruby/fcntl/commit/1c7c70fa5d
2024-03-14 03:49:40 +00:00
Nobuyoshi Nakada 5fe1853e9b [ruby/fcntl] Reduce duplicate `O_ACCMODE` definitions
https://github.com/ruby/fcntl/commit/6a6442a7f8
2024-03-14 03:49:38 +00:00
Nobuyoshi Nakada d49b41566b [ruby/fcntl] [DOC] Remove redundant directives
https://github.com/ruby/fcntl/commit/a99909a90f
2024-03-14 03:49:37 +00:00
Nobuyoshi Nakada 3f8ef7ff7c [ruby/stringio] Define `StringIO::MAX_LENGTH`
https://github.com/ruby/stringio/commit/0205bd1c86
2024-03-13 13:20:23 +00:00
Nobuyoshi Nakada 78725f14b2
RMDIRS includes `-p` option [ci skip] 2024-03-07 17:13:43 +09:00
Jean Boussier b4a69351ec Move FL_SINGLETON to FL_USER1
This frees FL_USER0 on both T_MODULE and T_CLASS.

Note: prior to this, FL_SINGLETON was never set on T_MODULE,
so checking for `FL_SINGLETON` without first checking that
`FL_TYPE` was `T_CLASS` was valid. That's no longer the case.
2024-03-06 13:11:41 -05:00
Lazarus Lazaridis 61ea202f8b
[DOC] Fix invalid documentation for `reachable_objects_from` (#10172)
Previous documentation is stating the opposite (that the method won't
work for CRuby).
2024-03-05 01:35:51 +09:00
Thomas Marshall 7e4b1f8e19
[Bug #20322] Fix rb_enc_interned_str_cstr null encoding
The documentation for `rb_enc_interned_str_cstr` notes that `enc` can be
a null pointer, but this currently causes a segmentation fault when
trying to autoload the encoding. This commit fixes the issue by checking
for NULL before calling `rb_enc_autoload`.
2024-03-03 10:43:35 +00:00
Nobuyoshi Nakada 93556d4620 [ruby/etc] Drop support for old ERB
https://github.com/ruby/etc/commit/11677318ac
2024-03-02 16:40:16 +00:00
Nobuyoshi Nakada e9a7801a93
Drop support for old ERB 2024-03-03 00:55:45 +09:00
KJ Tsanaktsidis fe0b704df5 Skip assert_no_memory_leak when ASAN is enabled
ASAN greatly increases the memory footprint of Ruby, so these static
thresholds are not appropriate. There's no real need to run these tests
under ASAN.

[Bug #20274]
2024-02-28 14:41:03 +11:00
Pierrick Bouvier 1ca3482e0a Fix compilation for platforms without pthread
Found when compiling ruby for windows-arm64 using msys2

Missing return type for function Init_lock_native_thread
lock_native_thread.c:45:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
   45 | Init_lock_native_thread(void)
      | ^
      | int
2024-02-26 20:45:48 +09:00
Aaron Patterson 164e464b04 [ruby/strscan] Add a method for peeking and reading bytes as
integers
(https://github.com/ruby/strscan/pull/89)

This commit adds `scan_byte` and `peek_byte`. `scan_byte` will scan the
current byte, return it as an integer, and advance the cursor.
`peek_byte` will return the current byte as an integer without advancing
the cursor.

Currently `StringScanner#get_byte` returns a string, but I want to get
the current byte without allocating a string. I think this will help
with writing high performance lexers.

---------

https://github.com/ruby/strscan/commit/873aba2e5d

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2024-02-26 15:54:54 +09:00
Nobuyoshi Nakada d4e24021d3
Revise 9ec342e07d 2024-02-26 13:12:05 +09:00
Nobuyoshi Nakada a0f7de814a
[Bug #20296] Fix the default assertion message 2024-02-26 12:29:23 +09:00
Misaki Shioi 9ec342e07d
Introduction of Happy Eyeballs Version 2 (RFC8305) in Socket.tcp (#9374)
* Introduction of Happy Eyeballs Version 2 (RFC8305) in Socket.tcp

This is an implementation of Happy Eyeballs version 2 (RFC 8305) in Socket.tcp.

[Background]
Currently, `Socket.tcp` synchronously resolves names and makes connection attempts with `Addrinfo::foreach.`
This implementation has the following two problems.

1. In name resolution, the program stops until the DNS server responds to all DNS queries.
2. In a connection attempt, while an IP address is trying to connect to the destination host and is taking time, the program stops, and other resolved IP addresses cannot try to connect.

[Proposal]
"Happy Eyeballs" ([RFC 8305](https://datatracker.ietf.org/doc/html/rfc8305)) is an algorithm to solve this kind of problem. It avoids delays to the user whenever possible and also uses IPv6 preferentially.

I implemented it into `Socket.tcp` by using `Addrinfo.getaddrinfo` in each thread spawned per address family to resolve the hostname asynchronously, and using `Socket::connect_nonblock` to try to connect with multiple addrinfo in parallel.

[Outcome]

This change eliminates a fatal defect in the following cases.

Case 1. One of the A or AAAA DNS queries does not return

---
require 'socket'

class Addrinfo
  class << self
    # Current Socket.tcp depends on foreach
    def foreach(nodename, service, family=nil, socktype=nil, protocol=nil, flags=nil, timeout: nil, &block)
      getaddrinfo(nodename, service, Socket::AF_INET6, socktype, protocol, flags, timeout: timeout)
        .concat(getaddrinfo(nodename, service, Socket::AF_INET, socktype, protocol, flags, timeout: timeout))
        .each(&block)
    end

    def getaddrinfo(_, _, family, *_)
      case family
      when Socket::AF_INET6 then sleep
      when Socket::AF_INET then [Addrinfo.tcp("127.0.0.1", 4567)]
      end
    end
  end
end

Socket.tcp("localhost", 4567)
---

Because the current `Socket.tcp` cannot resolve IPv6 names, the program stops in this case. It cannot start to connect with IPv4 address.
Though `Socket.tcp` with HEv2 can promptly start a connection attempt with IPv4 address in this case.

 Case 2. Server does not promptly return ack for syn of either IPv4 / IPv6 address family

---
require 'socket'

fork do
  socket = Socket.new(Socket::AF_INET6, :STREAM)
  socket.setsockopt(:SOCKET, :REUSEADDR, true)
  socket.bind(Socket.pack_sockaddr_in(4567, '::1'))
  sleep
  socket.listen(1)
  connection, _ = socket.accept
  connection.close
  socket.close
end

fork do
  socket = Socket.new(Socket::AF_INET, :STREAM)
  socket.setsockopt(:SOCKET, :REUSEADDR, true)
  socket.bind(Socket.pack_sockaddr_in(4567, '127.0.0.1'))
  socket.listen(1)
  connection, _ = socket.accept
  connection.close
  socket.close
end

Socket.tcp("localhost", 4567)
---

The current `Socket.tcp` tries to connect serially, so when its first name resolves an IPv6 address and initiates a connection to an IPv6 server, this server does not return an ACK, and the program stops.
Though `Socket.tcp` with HEv2 starts to connect sequentially and in parallel so a connection can be established promptly at the socket that attempted to connect to the IPv4 server.

In exchange, the performance of `Socket.tcp` with HEv2 will be degraded.

---
100.times { Socket.tcp("www.ruby-lang.org", 80) }
---

This is due to the addition of the creation of IO objects, Thread objects, etc., and calls to `IO::select` in the implementation.

* Avoid NameError of Socket::EAI_ADDRFAMILY in MinGW

* Support Windows with SO_CONNECT_TIME

* Improve performance

I have additionally implemented the following patterns:

- If the host is single-stack, name resolution is performed in the main thread. This reduces the cost of creating threads.
- If an IP address is specified, name resolution is performed in the main thread. This also reduces the cost of creating threads.
- If only one IP address is resolved, connect is executed in blocking mode. This reduces the cost of calling IO::select.

Also, I have added a fast_fallback option for users who wish not to use HE.
Here are the results of each performance test.

```ruby
require 'socket'
require 'benchmark'

HOSTNAME = "www.ruby-lang.org"
PORT = 80

ai = Addrinfo.tcp(HOSTNAME, PORT)

Benchmark.bmbm do |x|
  x.report("Domain name") do
    30.times { Socket.tcp(HOSTNAME, PORT).close }
  end

  x.report("IP Address") do
    30.times { Socket.tcp(ai.ip_address, PORT).close }
  end

  x.report("fast_fallback: false") do
    30.times { Socket.tcp(HOSTNAME, PORT, fast_fallback: false).close }
  end
end
```

```
                           user     system      total        real
Domain name            0.015567   0.032511   0.048078 (  0.325284)
IP Address             0.004458   0.014219   0.018677 (  0.284361)
fast_fallback: false   0.005869   0.021511   0.027380 (  0.321891)
````

And this is the measurement result when executed in a single stack environment.

```
                           user     system      total        real
Domain name            0.007062   0.019276   0.026338 (  1.905775)
IP Address             0.004527   0.012176   0.016703 (  3.051192)
fast_fallback: false   0.005546   0.019426   0.024972 (  1.775798)
```

The following is the result of the run on Ruby 3.3.0.

(on Dual stack environment)

```
                 user     system      total        real
Ruby 3.3.0   0.007271   0.027410   0.034681 (  0.472510)
```

(on Single stack environment)

```
                 user     system      total        real
Ruby 3.3.0  0.005353   0.018898   0.024251 (  1.774535)
```

* Do not cache `Socket.ip_address_list`

As mentioned in the comment at https://github.com/ruby/ruby/pull/9374#discussion_r1482269186, caching Socket.ip_address_list does not follow changes in network configuration.
But if we stop caching, it becomes necessary to check every time `Socket.tcp` is called whether it's a single stack or not, which could further degrade performance in the case of a dual stack.
From this, I've changed the approach so that when a domain name is passed, it doesn't check whether it's a single stack or not and resolves names in parallel each time.

The performance measurement results are as follows.

require 'socket'
require 'benchmark'

HOSTNAME = "www.ruby-lang.org"
PORT = 80

ai = Addrinfo.tcp(HOSTNAME, PORT)

Benchmark.bmbm do |x|
  x.report("Domain name") do
    30.times { Socket.tcp(HOSTNAME, PORT).close }
  end

  x.report("IP Address") do
    30.times { Socket.tcp(ai.ip_address, PORT).close }
  end

  x.report("fast_fallback: false") do
    30.times { Socket.tcp(HOSTNAME, PORT, fast_fallback: false).close }
  end
end

                           user     system      total        real
Domain name            0.004085   0.011873   0.015958 (  0.330097)
IP Address             0.000993   0.004400   0.005393 (  0.257286)
fast_fallback: false   0.001348   0.008266   0.009614 (  0.298626)

* Wait forever if fallback addresses are unresolved, unless resolv_timeout

Changed from waiting only 3 seconds for name resolution when there is no fallback address available, to waiting as long as there is no resolv_timeout.
This is in accordance with the current `Socket.tcp` specification.

* Use exact pattern to match IPv6 address format for specify address family
2024-02-26 12:14:11 +09:00