Commit graph

9686 commits

Author SHA1 Message Date
Benoit Daloze
15e6f13ff7 [ruby/fiddle] Fix Fiddle.last_error on FFI backend and improve test
to work for all
(https://github.com/ruby/fiddle/pull/173)

ef2382a7ef
2025-02-03 10:22:16 +09:00
Nobuyoshi Nakada
b5b5097663 [ruby/fiddle] Define Fiddle.last_error family and Fiddle.dlopen
statically
(https://github.com/ruby/fiddle/pull/172)

`RUBY_ENGINE` and `Fiddle::WINDOWS` should not change in a process, no
need to be checked inside the methods.

Also, `win32_last_error` and `win32_last_socket_error` are equal to
`last_error` on JRuby.

50ac00ed53
2025-02-03 10:22:15 +09:00
Jean Boussier
98c56de823 [ruby/json] Refactor further to expose the simpler escape search possible
e03515ac8b
2025-02-03 10:05:26 +09:00
Jean Boussier
98e1c2845a [ruby/json] Refactor convert_UTF8_to_JSON to split searching and escaping code
The goal is to be able to dispatch to more optimized search implementations
without having to duplicate the escaping code.

Somehow, this is a few % faster already:

```
== Encoding activitypub.json (52595 bytes)
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
               after     2.257k i/100ms
Calculating -------------------------------------
               after     22.930k (± 1.3%) i/s   (43.61 μs/i) -    115.107k in   5.020814s

Comparison:
              before:    21604.0 i/s
               after:    22930.1 i/s - 1.06x  faster

== Encoding citm_catalog.json (500298 bytes)
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
               after   137.000 i/100ms
Calculating -------------------------------------
               after      1.397k (± 1.1%) i/s  (715.57 μs/i) -      6.987k in   5.000408s

Comparison:
              before:     1344.4 i/s
               after:     1397.5 i/s - 1.04x  faster

== Encoding twitter.json (466906 bytes)
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
               after   249.000 i/100ms
Calculating -------------------------------------
               after      2.464k (± 1.8%) i/s  (405.81 μs/i) -     12.450k in   5.054131s

Comparison:
              before:     2326.5 i/s
               after:     2464.2 i/s - 1.06x  faster
```

8fb5ae807f
2025-02-03 10:05:25 +09:00
Peter Zhu
d729c1575e Output object_id in ObjectSpace.dump
Outputs the object ID in the dump for objects that have it seen.
2025-01-30 11:48:14 -05:00
Nobuyoshi Nakada
dc3d2a3c2f
[ruby/json] Avoid plain char for ctype macros
On some platforms ctype functions are defined as macros accesing tables.
A plain char may be `signed` or `unsigned` per implementations and the
extension result implementation dependent.

gcc warns such case:

```
parser.c: In function 'rstring_cache_fetch':
parser.c:138:33: warning: array subscript has type 'char' [-Wchar-subscripts]
  138 |     if (RB_UNLIKELY(!isalpha(str[0]))) {
      |                              ~~~^~~
parser.c: In function 'rsymbol_cache_fetch':
parser.c:190:33: warning: array subscript has type 'char' [-Wchar-subscripts]
  190 |     if (RB_UNLIKELY(!isalpha(str[0]))) {
      |                              ~~~^~~
```

4431b362f6
2025-01-30 16:56:02 +09:00
Edouard CHIN
7f70ef64af
[ruby/json] Few doc tweaks:
- Also modified the gemspec files' blob as the ragel's `parser.rl`
  file was removed in c8d5236a92

b2b106e314
2025-01-30 16:56:02 +09:00
Nobuyoshi Nakada
2b6fc9ea72
[Bug #21092] Fallback variables after execonf has done
When reading from a dummy makefile, the global variables initialized
in `init_mkmf` may not be overridden.
2025-01-30 14:52:01 +09:00
Nobuyoshi Nakada
8f77e694f9 [ruby/resolv] w32error_raise never returns
d00e86f7e4
2025-01-30 05:18:31 +00:00
Kazuki Yamaguchi
1b731c1f43 [ruby/openssl] pkey: avoid calling i2d_PUBKEY family on an incomplete key
Call ossl_pkey_check_public_key() to ensure that
EVP_PKEY_missing_parameters() passes. This check should be cheap.

DSA#{to_der,to_pem,export,to_s} and PKey#{public_to_der,public_to_pem}
cause a segfault if the receiver is an empty DSA instance with no
parameters set.

Fixes <https://github.com/ruby/openssl/issues/845>.

5aeed935e5
2025-01-29 17:14:41 +00:00
Misaki Shioi
63b6323e04
Ensure that memory is not freed before calling free_fast_fallback_getaddrinfo_* (#12661)
Ensure that `getaddrinfo_entry` and `getaddrinfo_shared` exist before free them in the main thread.
2025-01-29 22:19:04 +09:00
Étienne Barrié
89e316ad06
Introduce JSON::Coder
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2025-01-28 15:41:47 +09:00
Jean Boussier
53cf2170f9 [ruby/json] Update gemspec URIs
edd61b4a8b
2025-01-28 15:39:17 +09:00
Jean Boussier
77af41ea65 [ruby/json] Add some JSON::Fragment documentation
dbcf614e50
2025-01-28 15:39:17 +09:00
Nobuyoshi Nakada
a7dfd0c69f
Yield from create_makefile in bundled gems too 2025-01-23 14:17:40 +09:00
Kazuki Yamaguchi
495b1cad04 [ruby/openssl] ts: use TS_VERIFY_CTX_set0_{store,certs}() on OpenSSL 3.4
In OpenSSL 3.4, TS_VERIFY_CTX_set_certs() and TS_VERIFY_CTX_set_store()
are deprecated in favor of the new functions with "set0" in the names.

The new functions have a slightly different behavior. They will free the
previous value automatically. Increment the reference counter of
X509_STORE before setting it to TS_VERIFY_CTX, and do not try to
manually unset it.

We avoided doing this to work around a bug that was present in older
versions of OpenSSL, which has now been fixed in OpenSSL 1.0.2 by commit
bff9ce4db3.

ce37f7d93a
2025-01-23 01:45:52 +09:00
Kazuki Yamaguchi
87316d58fa [ruby/openssl] pkey: change PKey::{RSA,DSA,DH}#params to use nil for missing parameters
The returned Hash from these methods contain 0 in place of a missing
parameter in the key, for example:

	pkey = OpenSSL::PKey.read(OpenSSL::PKey::RSA.new(2048).public_to_pem)
	pp pkey.params
	#=>
	# {"n"=>#<OpenSSL::BN 2869346734[...snip]>,
	#  "e"=>#<OpenSSL::BN 65537>,
	#  "d"=>#<OpenSSL::BN 0>,
	#  "p"=>#<OpenSSL::BN 0>,
	#  "q"=>#<OpenSSL::BN 0>,
	#  "dmp1"=>#<OpenSSL::BN 0>,
	#  "dmq1"=>#<OpenSSL::BN 0>,
	#  "iqmp"=>#<OpenSSL::BN 0>}

Let's use nil instead, which is more appropriate for indicating a
missing value.

f247ec3dec
2025-01-23 01:45:52 +09:00
Kazuki Yamaguchi
ec4592280f [ruby/openssl] pkey: implement PKey::{RSA,DSA,DH}#params in Ruby
Move the definitions to lib/openssl/pkey.rb. They need not to be in the
extension and can be implemented using existing methods.

This reduces direct usage of the now-deprecated OpenSSL APIs around the
low-level structs such as DH, DSA, or RSA.

c14178f387
2025-01-23 01:45:51 +09:00
Kazuki Yamaguchi
72480389d1 [ruby/openssl] ssl: fix SSLSocket#sysread leaking locktmp String on timeout
Commit 3bbf5178a9 made blocking methods on SSLSocket follow the
IO#timeout= value. The commit changed io_wait_readable() to potentially
raise an exception without unlocking the String.

The String is currently locked for the entire duration of a #sysread
method call. This does not seem to be necessary, as SSL_read() does not
require that the same buffer is specified when retrying. Locking the
String during each SSL_read() call should be sufficient.

8f791d73f5
2025-01-22 16:45:19 +00:00
Theo Buehler
72fdba156d [ruby/openssl] Use X509_ALGOR_get0() accessor for X509_ALGOR
While the struct is currently still public in OpenSSL, there has been
an accessor since OpenSSL 0.9.8h. It would be nice if this accessor
could be used so that the struct can be made opaque at some point in
the future.

812aeab2f5
2025-01-21 18:17:06 +00:00
Kazuki Yamaguchi
43c48e3030 [ruby/openssl] Require OpenSSL 1.1.1 or later
Drop support for OpenSSL 1.1.0. OpenSSL 1.1.0 was a non-LTS release and
it has reached upstream EOL in 2019-12 along with OpenSSL 1.0.2.
Distributions that shipped with OpenSSL 1.1.0 include:

 - Debian 9 (EOL 2022-06)
 - Ubuntu 18.04 LTS (EOL 2023-04)

ba83abe920
2025-01-21 18:14:14 +00:00
Kazuki Yamaguchi
c6c1e7a92a [ruby/openssl] extconf.rb: remove dir_config("kerberos")
The dir_config was introduced by Ruby trunk r4181. Since support for
Kerberos cipher suites has been removed in OpenSSL 1.1.0, it is no
longer necessary.

Although ruby/openssl did not directly depend on the MIT Kerberos
library, it was an optional transitive dependency. Unless it was
disabled by a compile-time option, the OpenSSL headers would try to
include <krb5.h>.

78d028c332
2025-01-20 17:12:57 +00:00
Kazuki Yamaguchi
441862dc9f [ruby/openssl] Require OpenSSL 1.1.0 or later
Drop support for OpenSSL 1.0.2. It has reached upstream EOL in 2019-12.

Most distributions that shipped with OpenSSL 1.0.2 have also reached
EOL, or provide a newer version in the package repository:

 - RHEL 7 (EOL 2024-06)
 - Ubuntu 16.04 LTS (EOL 2021-04)
 - Amazon Linux 2 (EOL 2026-06, but OpenSSL 1.1.1 can be installed via
   the openssl11{,-devel} package)

38ec6fd50e
2025-01-20 17:12:57 +00:00
Kazuki Yamaguchi
010e8bff88 [ruby/openssl] pkcs7: remove unnecessary const cast
PKCS7_encrypt() and PKCS7_SIGNER_INFO_set() take const EVP_CIPHER and
EVP_MD at least since OpenSSL 0.9.7.

9db621a5c0
2025-01-20 17:12:55 +00:00
Kazuki Yamaguchi
04cc762941 [ruby/openssl] engine: remove constants for ENGINE_METHOD_BN_MOD_EXP{,_CRT}
These macros do not exist in OpenSSL 0.9.7 or later, which was released
in 2002.

938a1e6aab
2025-01-20 17:12:55 +00:00
tompng
86b262179d [ruby/json] Reject invalid number: - -.1 -e0
b9bfeecfa9
2025-01-20 14:20:55 +01:00
tompng
525d7a68e4 [ruby/json] Raise parse error on invalid comments
2f57f40467
2025-01-20 14:20:55 +01:00
tompng
c026e44bb5 [ruby/json] Fix parsing incomplete unicode escape "\uaaa"
86c0d4eb7e
2025-01-20 14:20:55 +01:00
Jean Boussier
2b4b7bdb10 [ruby/json] Fix JSON::Fragment#to_json signature
f8817fe56c
2025-01-20 14:20:55 +01:00
Étienne Barrié
e8676cada8 [ruby/json] Introduce JSON::Fragment
9e3500f345

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2025-01-20 14:20:55 +01:00
Nobuyoshi Nakada
ba44e92573 ext/json no longer uses ragel 2025-01-20 21:37:20 +09:00
Jean Boussier
33708f2dc4 [ruby/json] Fix a regression in the parser with leading /
Ref: https://github.com/ruby/ruby/pull/12598

This could lead to an infinite loop.

f8cfa2696a
2025-01-20 10:31:56 +01:00
Hiroshi SHIBATA
e3ba5207b5 Removed parser.rl from ext/json/parser/depend 2025-01-20 16:09:00 +09:00
Jean Boussier
df8f93848e [ruby/json] json_string_unescape: use memchr to search for backslashes
5e6cfcf724
2025-01-20 16:09:00 +09:00
Jean Boussier
ba8f22c040 [ruby/json] Cleanup json_decode_float
Move all the decimal_class option parsing in the constructor.

e9adefdc38
2025-01-20 16:09:00 +09:00
Jean Boussier
6c6f9672e2 [ruby/json] parser.c: Pass the JSON_ParserConfig pointer
Doesn't make a measurable performance difference but is a
bit clearer.

314d117c61
2025-01-20 16:09:00 +09:00
Jean Boussier
f664e863d8 [ruby/json] Use RSTRING_END
dd9c46c805
2025-01-20 16:09:00 +09:00
Jean Boussier
e4b54b0a36 [ruby/json] Replace fbuffer by stack buffers or RB_ALLOCV in parser.c
We only use that buffer for parsing integer and floats, these
are unlikely to be very big, and if so we can just use RB_ALLOCV as it will
almost always end in a small `alloca`.

This allow to no longer need `rb_protect` around the parser.

994859916a
2025-01-20 16:09:00 +09:00
Jean Boussier
99e9eb5380 [ruby/json] Implement write barriers for ParserConfig objects
591056a526
2025-01-20 16:09:00 +09:00
Jean Boussier
ef585744c0 Finalize Kevin's handrolled parser.
And get rid of the Ragel parser.

This is 7% faster on activitypub, 15% after on twitter and 11% faster
on citm_catalog.

There might be some more optimization opportunities, I did a quick
optimization pass to fix a regression in string parsing, but other
than that I haven't dug much in performance.
2025-01-20 16:09:00 +09:00
Charles Oliver Nutter
1574b90451 [ruby/psych] Bump version for release
2af9f6ac02
2025-01-17 15:15:39 +00:00
Hiroshi SHIBATA
721891688b
Migrate win32ole as bundled gems 2025-01-16 12:35:21 +09:00
Charles Oliver Nutter
a50d612a0c [ruby/psych] Update to SnakeYAML-Engine 2.9
Fixes ruby/psych#689

ac887cdc76
2025-01-15 22:12:25 +00:00
Aaron Patterson
cd0abd696f [ruby/psych] remove vim settings
2f46abf4e1
2025-01-15 20:11:51 +00:00
Nobuyoshi Nakada
e0be1b9025
Link bin as well as lib so that Gem.bin_path works 2025-01-15 15:19:05 +09:00
Kazuki Yamaguchi
318519caaa [ruby/openssl] engine: remove mention of LibreSSL from OpenSSL::Engine
These paths are only reachable when it is compiled against OpenSSL.
LibreSSL 3.9 does not support ENGINE and defines OPENSSL_NO_ENGINE.

e153d6ab47
2025-01-14 12:38:17 +00:00
Kazuki Yamaguchi
731d3ec301 [ruby/openssl] ossl.c: use OPENSSL_init_ssl() and OpenSSL_version() with LibreSSL
LibreSSL 2.7.0 added support for OPENSSL_init_ssl() and
OpenSSL_version().

1328415097
2025-01-14 12:38:16 +00:00
Kazuki Yamaguchi
0fb64bda9b [ruby/openssl] Require LibreSSL 3.9 or later
Drop support for LibreSSL 3.1-3.8. LibreSSL 3.8 has reached its EOL in
2024-10.

f33d611f9f
2025-01-14 12:38:16 +00:00
Jean Boussier
4f79485889 [ruby/openssl] Refactor buffer usage to only use append_as_bytes
28f2901c48
2025-01-14 11:54:47 +00:00
Jean Boussier
2f5d31d38a [ruby/openssl] Reduce OpenSSL::Buffering#do_write overhead
[Bug #20972]

The `rb_str_new_freeze` was added in https://github.com/ruby/openssl/issues/452
to better handle concurrent use of a Socket, but SSL sockets can't be used
concurrently AFAIK, so we might as well just error cleanly.

By using `rb_str_locktmp` we can ensure attempts at concurrent write
will raise an error, be we avoid causing a copy of the bytes.

We also use the newer `String#append_as_bytes` method when available
to save on some more copies.

0d8c17aa85

Co-Authored-By: luke.gru@gmail.com
2025-01-14 11:54:47 +00:00