Commit graph

9282 commits

Author SHA1 Message Date
Nobuyoshi Nakada
97449338d6 [Bug #20649] Allow nil as 2nd argument of assign_error
Fallback to the last token element in that case, for the backward
compatibilities.
2024-07-24 22:18:36 +09:00
Jean Boussier
30f2d69825 Don't call Kernel#require in hot loop
Ref: https://bugs.ruby-lang.org/issues/20641

Even without the reference bug, `require 'date'` isn't cheap.

```ruby

require "benchmark/ips"
require "yaml"
require "date"

100.times do |i|
  $LOAD_PATH.unshift("/tmp/does/not/exist/#{i}")
end
payload = 100.times.map { Date.today }.to_yaml

Benchmark.ips do |x|
  x.report("100 dates") { YAML.unsafe_load(payload) }
end
```

Before:
```
$ ruby /tmp/bench-yaml.rb
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
           100 dates   416.000 i/100ms
Calculating -------------------------------------
           100 dates      4.309k (± 1.2%) i/s -     21.632k in   5.021003s
```

After:
```
$ ruby -Ilib /tmp/bench-yaml.rb
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
           100 dates   601.000 i/100ms
Calculating -------------------------------------
           100 dates      5.993k (± 1.8%) i/s -     30.050k in   5.016079s
```
2024-07-19 20:37:20 +00:00
Nobuyoshi Nakada
94b87084a6 [ruby/win32ole] win32ole.c: repeated code
* ext/win32ole/win32ole.c (ole_variant2val): reduce repeated code
  between byref and byval.

e753c6abdd
2024-07-12 09:45:06 +00:00
Ivo Anjo
ef563a696d Minor: Fix typo in bug name
This confused me for a few minutes -- the testcase for
https://bugs.ruby-lang.org/issues/14834 was mistyped in the file name,
as well as once in the source.

E.g. in some cases it was
`one-four-three-eight-four` instead of
`one-four-eight-three-four`.
2024-07-11 15:18:40 -04:00
Peter Zhu
51bd816517 [Feature #20470] Split GC into gc_impl.c
This commit splits gc.c into two files:

- gc.c now only contains code not specific to Ruby GC. This includes
  code to mark objects (which the GC implementation may choose not to
  use) and wrappers for internal APIs that the implementation may need
  to use (e.g. locking the VM).

- gc_impl.c now contains the implementation of Ruby's GC. This includes
  marking, sweeping, compaction, and statistics. Most importantly,
  gc_impl.c only uses public APIs in Ruby and a limited set of functions
  exposed in gc.c. This allows us to build gc_impl.c independently of
  Ruby and plug Ruby's GC into itself.
2024-07-03 09:03:40 -04:00
Grant Gardner
4d4ac00123 [ruby/openssl] Add SSLSocket#readbyte
Companion to getbyte but raise EOFError
Similar to https://github.com/ruby/openssl/pull/438

c40f70711a
2024-07-03 08:54:18 +00:00
eileencodes
d25b74b32c Resize arrays in rb_ary_freeze and use it for freezing arrays
While working on a separate issue we found that in some cases
`ary_heap_realloc` was being called on frozen arrays. To fix this, this
change does the following:

1) Updates `rb_ary_freeze` to assert the type is an array, return if
already frozen, and shrink the capacity if it is not embedded, shared
or a shared root.
2) Replaces `rb_obj_freeze` with `rb_ary_freeze` when the object is
always an array.
3) In `ary_heap_realloc`, ensure the new capa is set with
`ARY_SET_CAPA`. Previously the change in capa was not set.
4) Adds an assertion to `ary_heap_realloc` that the array is not frozen.

Some of this work was originally done in
https://github.com/ruby/ruby/pull/2640, referencing this issue
https://bugs.ruby-lang.org/issues/16291. There didn't appear to be any
objections to this PR, it appears to have simply lost traction.

The original PR made changes to arrays and strings at the same time,
this PR only does arrays. Also it was old enough that rather than revive
that branch I've made a new one. I added Lourens as co-author in addtion
to Aaron who helped me with this patch.

The original PR made this change for performance reasons, and while
that's still true for this PR, the goal of this PR is to avoid
calling `ary_heap_realloc` on frozen arrays. The capacity should be
shrunk _before_ the array is frozen, not after.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Co-Authored-By: methodmissing <lourens@methodmissing.com>
2024-07-02 10:34:23 -07:00
HoneyryderChuck
9c5e9d29f0 [ruby/openssl] rewriting most of the asn1 init code in ruby
to have as much of the lib in ruby as possible

8305051728
2024-06-27 16:00:55 +00:00
Nobuyoshi Nakada
04c86a63cd [ruby/date] Update zonetab.h at 2024-06-26
ef5a0dac5b
2024-06-26 10:01:21 +00:00
Nobuyoshi Nakada
e428ee7bbe [ruby/io-console] Use locale insensitive casecmp
4b2e876dd7
2024-06-24 15:38:11 +00:00
Nobuyoshi Nakada
f4f8aa0f89 [ruby/io-console] Use strcasecmp
f8ec8a0617
2024-06-24 15:38:10 +00:00
Nobuyoshi Nakada
25c2aa0a1c [ruby/io-console] Use gperf 3.1 to generate ANSI-C code
3798aae42d
2024-06-24 15:38:10 +00:00
Nobuyoshi Nakada
865a2027a1 [ruby/date] Use locale insensitive casecmp
cfbd6a6b13
2024-06-24 15:36:56 +00:00
Nobuyoshi Nakada
7aafd3ed0e [ruby/date] Use strncasecmp
5974ac9c7e
2024-06-24 15:36:56 +00:00
Nobuyoshi Nakada
12e66f11e5 [ruby/date] Use gperf 3.1 to generate ANSI-C code
5d67437b1f
2024-06-24 15:36:55 +00:00
Nobuyoshi Nakada
d8c6e91748
Fix dangling else 2024-06-23 09:42:25 +09:00
Dmitry Davydov
fba8aff7af [Bug #20592] Fix segfault when sending NULL to freeaddrinfo
On alpine freeaddrinfo does not accept NULL pointer
2024-06-22 22:05:31 +09:00
Koichi Sasada
bd583ca645 retry on cancelling of getaddrinfo
When the registerred unblock function is called, it should retry
the cancelled blocking function if possible after checkints.

For example, `SIGCHLD` can cancel this method, but it should not
raise any exception if there is no trap handlers.

The following is repro-code:

```ruby
require 'socket'
PN = 10_000

1000000.times{
  p _1
  PN.times{
    fork{
      sleep rand(0.3)
    }
  }
  i = 0
  while i<PN
    cpid = Process.wait -1, Process::WNOHANG
    if cpid
      # p [i, cpid]
      i += 1
    end

    begin
      TCPServer.new(nil, 0).close
    rescue
      p $!
      exit!
    end
  end
}
```
2024-06-21 22:36:42 +09:00
Aaron Patterson
0e1182f93c [ruby/fiddle] Remove Vim commands
(https://github.com/ruby/fiddle/pull/140)

Some of these commands just don't work (for example `sws` is not a Vim
setting). I think we should just remove these.

c3dbf7ba9a
2024-06-20 15:16:57 +09:00
Nobuyoshi Nakada
c2fd3dfb98
[ruby/date] Update zonetab.h at 2024-06-19
8e5efd4f59
2024-06-20 15:16:48 +09:00
Yuta Saito
7cbe54714c extmk.rb: define Gem.target_rbconfig not to break Gem::Platform.local 2024-06-18 11:12:52 +09:00
Yuta Saito
b73dd8f6d0 [ruby/io-console] Skip building extension on WASI
WASI does not support concept to provide termios, so it is not possible
to build io/console extension on WASI at the moment.

However, `io/console` is used by many gems, and removing the dependency
from them *conditionally* is impossible. So, this commit adds a
check to skip building `io/console` extension on WASI just to pass `gem
install` for the platform.

ba9bf00184
2024-06-17 07:40:56 +00:00
tompng
04467218ce Add rb_str_resize coderange test 2024-06-13 18:27:02 +02:00
Sutou Kouhei
205da89680 [ruby/stringio] Development of 3.1.2 started.
9ad5551160
2024-06-13 09:48:38 +00:00
gartens
c735f4947e [ruby/openssl] Pass through nil as digest when signing certificates
(https://github.com/ruby/openssl/pull/761)

In order to sign certificates with Ed25519 keys, NULL must be passed
as md to X509_sign.  This NULL is then passed
(via ASN1_item_sign_ex) as type to EVP_DigestSignInit.  The
documentation[1] of EVP_DigestSignInit states that type must be NULL
for various key types, including Ed25519.

[1]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestSignInit.html

b0fc100091
2024-06-11 17:12:28 +00:00
Nobuyoshi Nakada
8abdd56c31
Test rb_ext_resolve_symbol without Windows .def files
`RUBY_FUNC_EXPORTED` is working on Windows since 906a86e4de.
And as .def files are not processed by the preprocessor, it is less
flexible than `RUBY_FUNC_EXPORTED`, (e.g., select symbols by
conditions such as ruby version).
2024-06-10 17:47:35 +09:00
Nobuyoshi Nakada
1b7aabb90d
Remove digest.def that fails on older Ruby versions 2024-06-09 18:22:06 +09:00
Nobuyoshi Nakada
6ea9cd4909
Provisionally export new API 2024-06-09 02:26:34 +09:00
Kazuki Yamaguchi
69c0b1438a [ruby/openssl] Fix references to the license text
Update the references to the file "LICENCE" with "COPYING".

The file LICENCE doesn't exist in ruby/ruby nor ruby/openssl. This has
been always the case since OpenSSL for Ruby 2 was merged to the ruby
tree as a standard library in 2003.

In OpenSSL for Ruby 2's CVS repository[1], the LICENCE file contained
an old version of the Ruby License, identical to the COPYING file that
was in Ruby's tree at that time (r4128[2]).

[1] http://cvs.savannah.gnu.org/viewvc/rubypki/ossl2/LICENCE?revision=1.1.1.1&view=markup
[2] 231247c010/COPYING

5bccf07d04
2024-06-08 10:59:17 +00:00
Kazuki Yamaguchi
6475b093fb [ruby/openssl] Rename LICENSE.txt to COPYING
This is for consistency with ruby/ruby.

00ad542791
2024-06-08 10:59:16 +00:00
Kazuki Yamaguchi
5f380dfdb2 [ruby/openssl] openssl.gemspec: add BSD-2-Clause to the list of licenses
ruby/openssl is licensed under the terms of either the Ruby License or
the 2-Clause BSD License.

The git repository and built .gem files always contained the license
text for both license, but the metadata in the gemspec only specified
the Ruby License. Let's include both.

c71714d738
2024-06-08 10:59:14 +00:00
Samuel Giddins
0b92929e52 [ruby/openssl] Add X509::Certificate#tbs_bytes
Ref https://github.com/ruby/openssl/issues/519

This makes verifying embedded certificate transparency signatures
significantly easier, as otherwise the alternative was manipulating the
ASN1 sequence, as in
656d992fa8

99128bea5d
2024-06-08 10:57:02 +00:00
Nobuyoshi Nakada
18fcec23bf
ripper: Introduce RIPPER_ID macro instead of ripper_id_ macros 2024-06-08 13:20:46 +09:00
Nobuyoshi Nakada
bf95a17c84 [ruby/digest] [DOC] Update document to use rb_digest_make_metadata
c5c1debd43
2024-06-08 03:40:33 +00:00
Nobuyoshi Nakada
0619312bb5 [ruby/digest] Use typed data in digest
9a22f921c9
2024-06-08 03:40:27 +00:00
Nobuyoshi Nakada
ec7babd12d
[Feature #19998] Untyped Data API has been marked as deprecated 2024-06-07 00:49:52 +09:00
KJ Tsanaktsidis
63e9eaa5be [ruby/openssl] Fix test_create_with_mac_iter accidently setting keytype not maciter
This test was accidentally passing the value 2048 into the keytype
parameter of PKCS12_create, not the mac_iter parameter (because it had
one too many `nil`s in the call). This value is invalid, and will make
OpenSSL perform an out-of-bounds read which is caught when compiling
with ASAN.

This commit fixes the tests, and also adds some validation to
PKCS12.create to make sure any keytype passed is actually valid. Since
there only two valid keytype constants, and the whole feature is an
export-grade crypto era thing only ever supported by old MSIE, it seems
far more likely that code in the whild is using keytype similarly by
mistake rather than as intended. So this validation might catch that.

47028686d2
2024-06-05 00:45:53 +00:00
Hiroshi SHIBATA
892849ac98 Remove dependency on fiddle from test/ruby
Co-authored-by: "Nobuyoshi Nakada" <nobu@ruby-lang.org>
2024-06-04 19:53:04 +09:00
Hiroshi SHIBATA
7bc4b5f17f [ruby/win32ole] Added missing extensions
8456e8830e
2024-06-04 07:50:20 +00:00
Benoit Daloze
9c4a28b826 [flori/json] Use the pure-Ruby generator on TruffleRuby as it is much faster
* Using the benchmark from https://github.com/flori/json/pull/580
$ ruby benchmarks/bench.rb dump pure
JSON::Pure::Generator
truffleruby 24.0.0, like ruby 3.2.2, Oracle GraalVM Native [x86_64-linux]
Warming up --------------------------------------
      JSON.dump(obj)   116.000 i/100ms
      JSON.dump(obj)   235.000 i/100ms
      JSON.dump(obj)   317.000 i/100ms
      JSON.dump(obj)   372.000 i/100ms
      JSON.dump(obj)   374.000 i/100ms
Calculating -------------------------------------
      JSON.dump(obj)      3.735k (± 0.9%) i/s  (267.76 μs/i) -     18.700k in   5.007526s
      JSON.dump(obj)      3.738k (± 0.7%) i/s  (267.49 μs/i) -     18.700k in   5.002252s
      JSON.dump(obj)      3.743k (± 0.7%) i/s  (267.18 μs/i) -     19.074k in   5.096375s
      JSON.dump(obj)      3.747k (± 0.5%) i/s  (266.87 μs/i) -     19.074k in   5.090463s
      JSON.dump(obj)      3.746k (± 0.5%) i/s  (266.96 μs/i) -     19.074k in   5.092069s
$ ruby benchmarks/bench.rb dump ext
JSON::Ext::Generator
truffleruby 24.0.0, like ruby 3.2.2, Oracle GraalVM Native [x86_64-linux]
Warming up --------------------------------------
      JSON.dump(obj)    19.000 i/100ms
      JSON.dump(obj)    18.000 i/100ms
      JSON.dump(obj)    18.000 i/100ms
      JSON.dump(obj)    18.000 i/100ms
      JSON.dump(obj)    21.000 i/100ms
Calculating -------------------------------------
      JSON.dump(obj)    221.260 (±10.8%) i/s    (4.52 ms/i) -      1.092k in   5.004381s
      JSON.dump(obj)    221.983 (± 8.1%) i/s    (4.50 ms/i) -      1.113k in   5.055574s
      JSON.dump(obj)    221.446 (± 8.6%) i/s    (4.52 ms/i) -      1.113k in   5.073167s
      JSON.dump(obj)    226.452 (± 7.9%) i/s    (4.42 ms/i) -      1.134k in   5.048568s
      JSON.dump(obj)    227.795 (± 8.3%) i/s    (4.39 ms/i) -      1.134k in   5.025187s

8256455cdc
2024-06-04 14:44:43 +09:00
Hiroshi SHIBATA
3eda59e975
Sync strscan HEAD again.
https://github.com/ruby/strscan/pull/99 split document with multi-byte
chars.
2024-06-04 12:40:08 +09:00
Jean Boussier
c5ae432ec8
[flori/json] Cleanup useless ifdef
The json gem now requires Ruby 2.3, so there is no point keeping
compatibility code for older releases that don't have the
TypedData API.

45c86e153f
2024-06-04 12:23:48 +09:00
p0pemaru
cb6dcc7746 [ruby/date] [DOC] specify the unit of return value for Date#-
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.

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.

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