Commit graph

9970 commits

Author SHA1 Message Date
Kazuki Yamaguchi
0a8a641d0a [ruby/openssl] ssl: fix SSLSocket#syswrite with String-convertible objects
Correctly pass the new object assigned by StringValue() to
ossl_ssl_write_internal_safe().

This is a follow-up to commit 0d8c17aa85 (Reduce
OpenSSL::Buffering#do_write overhead, 2024-12-21).

3ff096196a
2025-04-16 15:16:50 +00:00
Samuel Williams
28491e53cd [ruby/stringio] Support for rb_io_mode_t
(https://github.com/ruby/stringio/pull/129)

Companion PR to <https://github.com/ruby/ruby/pull/7894>.

2d3988e12f
2025-04-15 11:15:35 +00:00
Jean Boussier
77a52787a6 [ruby/json] Cleanup Kernel#JSON
573ebdca89
2025-04-15 16:48:22 +09:00
Jean Boussier
26a9ccbf83 [ruby/json] Deprecate Kernel#j and Kernel#jj
27155b6500
2025-04-15 16:48:22 +09:00
Jean Boussier
1afc539900 [ruby/json] Get rid of JSONError.wrap
3e7e661ef5
2025-04-15 16:48:21 +09:00
Jean Boussier
62b7ae955a [ruby/json] Don't create custom NaN and Infinity objects.
ff8e18392d
2025-04-15 16:48:20 +09:00
Sutou Kouhei
ad8cb532d5 [ruby/strscan] Bump version
7b1eb1e4ed
2025-04-14 16:18:48 +09:00
Jean byroot Boussier
0db87b8943 [ruby/strscan] Allow parsing strings larger than 2GiB
(https://github.com/ruby/strscan/pull/147)

For a reason unknown, even though `pos` is stored as a `long`, the
`#pos` and `#pos=` treat it as an `int`, which prevent seeking into
strings larger than 2GiB.

b76368416e

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2025-04-14 16:18:47 +09:00
Nobuyoshi Nakada
311167ee3a [ruby/etc] Suppress unused function warning
410c8dd4ae
2025-04-13 22:03:59 +00:00
Nobuyoshi Nakada
6d00fa2270 [ruby/etc] Check members only for defined structs
15c2696794
2025-04-13 22:03:59 +00:00
Haruna Tsujita
3700ae2e99
Fix typos finised -> finished (#13104) 2025-04-13 20:46:40 +09:00
Jean Boussier
ae45a7a952 [ruby/json] Cleanup jeaiii-ltoa to not need pragmas
97f2924d0a
2025-04-09 08:11:03 +09:00
Nobuyoshi Nakada
b1362e26c7 [ruby/json] Suppress -Wunknown-pragmas warnings
97f47d1cfd
2025-04-09 08:11:03 +09:00
John Hawthorn
5eb3efcf2d Fix timeline_value not being marked in test
T_DATA with a NULL pointer are not marked. Let's wrap 1 instead to
ensure that our mark function is actually run.
2025-04-03 10:39:47 -07:00
Jean Boussier
580aa60051 Improve backtrace of errors raised by Socket.tcp_with_fast_fallback
[Bug #21211]

Socket errors raised from background threads are hard to track down because
their backtrace starts from the spawned thread.

To solve this we can raise a new error with the old one as `cause`.
2025-04-02 13:24:22 +02:00
Hiroshi SHIBATA
502fcfcc46
stringio-3.1.6 has been released 2025-03-31 16:13:46 +09:00
Jean Boussier
ec171b4075 [ruby/json] Move create_addtions logic in Ruby.
By leveraging the `on_load` callback we can move all this logic
out of the parser. Which mean we no longer have to duplicate
that logic in both parser and that we'll later be able to extract
it entirely from the gem.

f411ddf1ce
2025-03-28 12:44:53 +09:00
Jean Boussier
e8c46f4ca5 [ruby/json] JSON.load invoke the proc callback directly from the parser.
And substitute the return value like `Marshal.load` doesm
which I can only assume was the intent.

This also open the door to re-implement all the `create_addition`
logic in `json/common.rb`.

73d2137fd3
2025-03-28 12:44:53 +09:00
Jean Boussier
80a59a6244 [ruby/json] Remove more dead code
eda239ad34
2025-03-28 12:44:53 +09:00
Jean Boussier
756b75f242 [ruby/json] Remove Class#json_creatable? monkey patch.
1ca7efed1f
2025-03-28 12:44:53 +09:00
Jean Boussier
96ecac1e24 [ruby/json] Get rid of JSON::NOT_SET
760d922265
2025-03-28 12:44:53 +09:00
Jean Boussier
bba30bee62 [ruby/json] Remove outdated JSON.iconv
3de8702354
2025-03-28 12:44:53 +09:00
Jean Boussier
26e55562ce [ruby/json] Cleanup JSON.pretty_generate
01c47a0555
2025-03-28 12:44:53 +09:00
Jean Boussier
2b9a9300ac [ruby/json] Deprecate JSON.fast_generate
6508455d82
2025-03-28 12:44:53 +09:00
Nobuyoshi Nakada
49d49d5985 [ruby/psych] Format Date in ISO-8601 explicitly
Fix https://github.com/ruby/psych/pull/644

b1ade765ba
2025-03-27 14:56:49 +00:00
Jean Boussier
9f17a0c7cb Get rid of SAFE_STATE_PROTOTYPE
It was only used by JRuby and TruffleRuby to call `SAFE_STATE_PROTOTYPE.dup`
instead of `State.new` which isn't an worthy optimization.
2025-03-27 13:54:12 +09:00
Jean Boussier
4dde7101c7 Refactor jeaiii-ltoa.h
Some relatively minor change to make the library more in line
with the gem. Some renaming, etc.
2025-03-27 13:54:12 +09:00
Hiroshi SHIBATA
6d82ea7db8 Update ext/json/generator/depend 2025-03-27 11:37:27 +09:00
Hiroshi SHIBATA
ee85745c61 Removed trailing spaces 2025-03-27 11:37:27 +09:00
eno
d1f3c81258 Faster integer formatting
This commit provides an alternative implementation for a
long → decimal conversion.

The main difference is that it uses an algorithm pulled from
https://github.com/jeaiii/itoa.
The source there is C++, it was converted by hand to C for
inclusion with this gem.
jeaiii's algorithm is covered by the MIT License, see source code.

On addition this version now also generates the string directly into
the fbuffer, foregoing the need to run a separate memory copy.

As a result, I see a speedup of 32% on Apple Silicon M1 for an
integer set of benchmarks.
2025-03-27 11:37:27 +09:00
Jean Boussier
dc6ffbbe9e [ruby/json] Remove unused FAST_STATE_PROTOTYPE and PRETTY_STATE_PROTOTYPE
18e5c3c67c
2025-03-27 11:37:27 +09:00
Jean Boussier
b71ec1196e [ruby/json] Remove unparse and restore aliases.
These were deprecated 16 years ago.

a88d825a91
2025-03-27 11:37:27 +09:00
Jean Boussier
f4529ecbe7 [ruby/json] Deprecate all *_default_options
Globally changing the behavior of the library is a bad idea, as
many different libraries may rely on `json` and may not expect it
and likely never tested that a different default config works for them.

If you need to change the behavior of JSON, it's best to do it only
locally, and not globally.

In addition the new `JSON::Coder` interface is much more suited for
that.

Another reason for the deprecation is that it's impossible to
make `JSON.load` and `JSON.dump` Ractor-safe with such API.

172762c6e4
2025-03-27 11:37:27 +09:00
Benoit Daloze
bfc5b8305d [ruby/etc] Etc.sysconfdir does not work in a Ractor
* Because it uses RbConfig::CONFIG.
* See 3939950214 (step):12:947

12dbe03b6a
2025-03-25 21:27:16 +00:00
Benoit Daloze
b9e9a1034a [ruby/etc] Most Etc methods are not Ractor-safe currently
* See https://bugs.ruby-lang.org/issues/21115

ae62b7619c
2025-03-25 20:17:01 +00:00
Hiroshi SHIBATA
c5f30e9567
Update ext/json/generator/depend 2025-03-24 15:24:47 +09:00
Hiroshi SHIBATA
6b15857e25
Removed trailing space 2025-03-24 15:20:59 +09:00
Jean Boussier
f3f4524d19
Reorganize fpconv vendoring
Make it a single file and declare the dependency.
2025-03-24 14:49:44 +09:00
eno
c98e6a9b89 [ruby/json] Extends license description
cce3d1f6c1
2025-03-24 14:35:05 +09:00
eno
528c08cc5f [ruby/json] Adjust fpconv to add ".0" to integers
Adds a test case

fix

fa5bdf87cb
2025-03-24 14:35:04 +09:00
eno
a59333c58b [ruby/json] Faster float formatting
This commit provides an alternative implementation for a float → decimal conversion.

It integrates a C implementation of Fabian Loitsch's Grisu-algorithm [[pdf]](http://florian.loitsch.com/publications/dtoa-pldi2010.pdf), extracted from https://github.com/night-shift/fpconv. The relevant files are added in this PR, they are, as is all of https://github.com/night-shift/fpconv, available under a MIT License.

As a result, I see a speedup of 900% on Apple Silicon M1 for a float set of benchmarks.

floats don't have a single correct  string representation: a float like `1000.0` can be represented as "1000", "1e3", "1000.0" (and more).

The Grisu algorithm converts floating point numbers to an optimal decimal string representation without loss of precision. As a result, a float that is exactly an integer (like `Float(10)`) will be converted by that algorithm into `"10"`. While technically correct – the JSON format treats floats and integers identically –, this differs from the current behaviour of the `"json"` gem. To address this, the integration checks for that case, and explicitely adds a ".0" suffix in those cases.

This is sufficient to meet all existing tests; there is, however, a chance that the current implementation and this implementation occasionally encode floats differently.

```
== Encoding floats (4179311 bytes)
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
        json (local)     4.000 i/100ms
Calculating -------------------------------------
        json (local)     46.046 (± 2.2%) i/s   (21.72 ms/i) -    232.000 in   5.039611s

Normalize to 2090234 byte
== Encoding floats (4179242 bytes)
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
       json (2.10.2)     1.000 i/100ms
Calculating -------------------------------------
       json (2.10.2)      4.614 (± 0.0%) i/s  (216.74 ms/i) -     24.000 in   5.201871s
```

These benchmarks are run via a script ([link](https://gist.github.com/radiospiel/04019402726a28b31616df3d0c17bd1c)) which is based on the gem's `benchmark/encoder.rb` file. There are probably better ways to run benchmarks :) My version allows to combine multiple test cases into a single one.

The `dumps` benchmark, which covers the JSON files in `benchmark/data/*.json` – with the exception of `canada.json` – , reported a minor speedup within statistical uncertainty.

7d77415108
2025-03-24 14:35:04 +09:00
Susan van den Broek
76aaf8ddf4 [ruby/date] Add license files (COPYING, BSDL) to gem files
a3d85e0be5
2025-03-18 07:28:50 +00:00
Nobuyoshi Nakada
8d6f153fba Manage skipping instance variable IDs in one place 2025-03-17 23:42:16 +09:00
Luke Jahnke
b148dfef5a Fix crash in TCPSocket.open
Fix segfault crash observable with TCPSocket.open(nil, nil)
2025-03-15 15:50:46 +09:00
Peter Zhu
bdb25959fb Move object_id to flags for ObjectSpace dumps
Moving object_id dumping from ObjectSpace to the GC flags allows ObjectSpace
to not assume the FL_SEEN_OBJ_ID flag and instead move it to the responsibility
of the GC.
2025-03-13 10:12:24 -04:00
Jean Boussier
069ecfe869 [ruby/json] Release 2.10.2
350c1fd154
2025-03-13 10:33:38 +09:00
Jean Boussier
e6a2cf9fd7
[ruby/json] Fix potential out of bound read in json_string_unescape.
cf242d89a0
2025-03-13 10:33:25 +09:00
Sarun Rattanasiri
9ec8dc9c65 [ruby/openssl] mark initialize_copy as :nodoc:
17f87d2cf0
2025-03-12 16:03:47 +00:00
Jean Boussier
1d07deb422 [ruby/json] Raise a ParserError on all incomplete unicode escape sequence.
This was the behavior until `2.10.0` unadvertently changed it.

`"\u1"` would raise, but `"\u1zzz"` wouldn't.

7d0637b9e6
2025-03-12 18:02:09 +09:00
Jean Boussier
ba5fb74583 Fix Socket.tcp_with_fast_fallback to be usable from a Ractor
[Bug #21179]

```
socket.rb:1046:in 'Socket::HostnameResolutionStore#get_addrinfo': can not access non-shareable objects in constant
Socket::HostnameResolutionStore::PRIORITY_ON_V6 by non-main ractor. (Ractor::IsolationError)
	from socket.rb:724:in 'block in Socket.tcp_with_fast_fallback'
	from socket.rb:720:in 'Socket.tcp_with_fast_fallback'
```
2025-03-10 22:57:44 +01:00