2422 Commits

Author SHA1 Message Date
Jean Boussier
8cf4f373ff thread_sync.c: declare queue_data_type as parent of szqueue_data_type.
Allows to remove some duplicated code like szqueue_length, etc.
2025-12-18 20:57:05 +01:00
Nobuyoshi Nakada
b816f7bac5
[DOC] Fix documents of rb_intern_str and so on
* `rb_intern_str`: the argument must be `T_STRING`, no conversion.

* `rb_intern_str`, `rb_check_id`, `rb_to_id`, `rb_check_symbol`: raise
  `EncodingError` unless the "name" argument is a valid string in its
  encoding.
2025-12-18 11:27:05 +09:00
Nobuyoshi Nakada
f2d2a757d1
[DOC] Re-fill the paragraph 2025-12-18 10:14:40 +09:00
Augustin Gottlieb
cfa3e7cf75
[DOC] Fix double-word typos in comments
Found via `grep` for repeated words.

* set.c: Fix "or or"
* include/ruby/internal/symbol.h: Fix "is is"
* include/ruby/internal/ctype.h: Fix "in in"
2025-12-18 09:34:32 +09:00
Nobuyoshi Nakada
61bab18890 Rename to struct rbimpl_size_overflow_tag
This struct is used for addition not only for multiplication, so
remove the word `mul`, and make the member names more descriptive.
2025-12-17 17:35:58 +09:00
Jean Boussier
094418a6de gc.h: Reintroduce immediate guard in rb_obj_written
This guard was removed in https://github.com/ruby/ruby/pull/13497
on the justification that some GC may need to be notified even for
immediate.

But the two currently available GCs don't, and there are plenty
of assumtions GCs don't everywhere, notably in YJIT and ZJIT.

This optimization is also not so micro (but not huge either).
I routinely see 1-2% wasted there on micro-benchmarks.

So perhaps if in the future we actually need this, it might make
sense to introduce a way for GCs to declare that as an option,
but in the meantime it's extra overhead with little gain.
2025-12-16 21:00:27 +01:00
Benoit Daloze
b423204cb3 Fix documentation of RB_PASS_CALLED_KEYWORDS in C API 2025-12-13 21:09:05 +01:00
Luke Gruber
3add3db797
Fewer calls to GET_EC() and GET_THREAD() (#15506)
The changes are to `io.c` and `thread.c`.
I changed the API of 2 exported thread functions from `internal/thread.h` that
didn't look like they had any use in C extensions:

* rb_thread_wait_for_single_fd
* rb_thread_io_wait

I didn't change the following exported internal function because it's
used in C extensions:

* rb_thread_fd_select

I added a comment to note that this function, although internal, is used
in C extensions.
2025-12-12 14:47:43 -05:00
Nobuyoshi Nakada
5541c0d896 Win32: Make rb_w32_osid return Windows NT always
Since support for Windows 9x was dropped over a decade ago.
2025-12-12 14:24:03 +09:00
Nobuyoshi Nakada
f939f0433a Win32: Deprecate Windows version info API
`dwMajorVersion` alone has no meaning since Windows 7.  Use API in
VersionHelper.h instead.
2025-12-12 14:24:03 +09:00
Nobuyoshi Nakada
3636277dc5
Add NUM2PTR and PTR2NUM macros
These macros have been defined here and there, so collect them.
2025-12-10 12:09:50 +09:00
Jean Boussier
98390d9360 Don't declare rbimpl_check_typeddata as pure
[Bug #21771]

It may raise so it's incorrect and can lead to the compiler
optimizing the call out.
2025-12-09 18:08:00 +01:00
Nobuyoshi Nakada
e61b79b384
Fix a typo in the deprecation warning message 2025-12-09 02:16:45 +09:00
Kazuki Yamaguchi
be882278f2 Move RBIMPL_ATTR_DEPRECATED_* macros to the appropriate header file
Move these macros from include/ruby/backward.h to
include/ruby/internal/attr/deprecated.h, alongside the other similar
macros.

include/ruby/internal/intern/vm.h cannot currently use them because
include/ruby/backward.h is included too late.
2025-12-08 11:47:39 +09:00
Samuel Williams
42f5654b69
Yield to scheduler if interrupts are pending. (#14700) 2025-12-06 21:44:14 +13:00
Koichi Sasada
2aaea665bb fix typo s/sharable/shareable/ 2025-12-05 03:10:50 +09:00
Koichi Sasada
f2cd772329 (experimental) RUBY_TYPED_FROZEN_SHAREABLE_NO_REC
`T_DATA` has a flag `RUBY_TYPED_FROZEN_SHAREABLE` which means
if the `T_DATA` object is frozen, it can be sharable.
On the `Ractor.make_sharable(obj)`, rechable objects from the
`T_DATA` object will be apply `Ractor.make_shareable` recursively.

`RUBY_TYPED_FROZEN_SHAREABLE_NO_REC` is similar to the
`RUBY_TYPED_FROZEN_SHAREABLE`, but doesn't apply `Ractor.make_sharable`
recursively for children.
If it refers to unshareable objects, it will simply raise an error.

I'm not sure this pattern is common or not, so it is not in public.
If we find more cases, we can discuss publication.
2025-12-05 02:28:30 +09:00
Nobuyoshi Nakada
b872fbe3dd
Deprecate rb_eval_cmd_kw 2025-12-04 18:07:49 +09:00
Jean Boussier
fcf3939780 Speedup TypedData_Get_Struct
While profiling `Monitor#synchronize` and `Mutex#synchronize`
I noticed a fairly significant amount of time spent in
`rb_check_typeddata`.

By implementing a fast path that assumes the object is valid
and that can be inlined, it does make a significant difference:

Before:

```
  Mutex     13.548M (± 3.6%) i/s   (73.81 ns/i) -     68.566M in   5.067444
Monitor     10.497M (± 6.5%) i/s   (95.27 ns/i) -     52.529M in   5.032698s
```

After:

```
  Mutex     20.887M (± 0.3%) i/s   (47.88 ns/i) -    106.021M in   5.075989s
Monitor     16.245M (±13.3%) i/s   (61.56 ns/i) -     80.705M in   5.099680s
```

```ruby
require 'bundler/inline'

gemfile do
  gem "benchmark-ips"
end

mutex = Mutex.new
require "monitor"
monitor = Monitor.new

Benchmark.ips do |x|
  x.report("Mutex") { mutex.synchronize { } }
  x.report("Monitor") { monitor.synchronize { } }
end
```
2025-12-03 17:54:27 +01:00
Peter Zhu
404e6aa9b5 [DOC] Fix typo in rb_debug_inspector_current_depth 2025-11-27 18:23:56 -08:00
Nobuyoshi Nakada
7743123551 Win32: Drop support for older than MSVC 12.0/_MSC_VER 1800
Visual C++ 2013 (12.0):
- _MSC_VER: 1800
- MSVCRT_VERSION: 120
2025-11-19 11:03:42 +09:00
Nobuyoshi Nakada
cdb9893c55 Win32: Drop support for older than MSVC 8.0/_MSC_VER 1400
Visual C++ 2005 (8.0):
- _MSC_VER: 1400
- MSVCRT_VERSION: 80
2025-11-19 11:03:42 +09:00
nagachika
48dce7874f simplify RSRING_GETMEM() definition. 2025-11-11 18:57:30 +09:00
nagachika
367ddd445c include/ruby/internal/core/rstring.h: Remove rbimpl_rstring_getmem() definition. 2025-11-11 18:57:30 +09:00
nagachika
9d44cb0b2b Remove rbimpl_rstring_getmem() usage as workaround for GCC 15.2.1 optimization bug. [Bug #21655] 2025-11-11 18:57:30 +09:00
Earlopain
a2201570bd Remove rb_path_check declaration
Implementation was removed in a4c051b870
2025-11-07 23:35:51 +09:00
Yukihiro "Matz" Matsumoto
6d81969b47
Development of 4.0.0 started. 2025-11-07 16:41:47 +09:00
Satoshi Tagomori
c4691ef061 Rename Namespace to Ruby::Box 2025-11-07 13:14:54 +09:00
Nobuyoshi Nakada
0a924d4615
Use pointer to the member
Instead of the offset calculation.
2025-10-25 22:48:01 +09:00
Nobuyoshi Nakada
31e14ac7da
[DOC] Follow up GH-14470
`IS_TYPED_DATA` is no longer a flag in `type`, and the "embedded" flag
has been shifted accordingly.

ruby/ruby#14470
2025-10-25 18:10:15 +09:00
Koichi Sasada
45907b1b00 add SET_SHAREABLE macros
* `RB_OBJ_SET_SHAREABLE(obj)` makes obj shareable.
  All of reachable objects from `obj` should be shareable.
* `RB_OBJ_SET_FROZEN_SHAREABLE(obj)` same as above
  but freeze `obj` before making it shareable.

Also `rb_gc_verify_shareable(obj)` is introduced to check
the `obj` does not violate shareable rule (an shareable object
only refers shareable objects) strictly.

The rule has some exceptions (some shareable objects can refer to
unshareable objects, such as a Ractor object (which is a shareable
object) can refer to the Ractor local objects.
To handle such case, `check_shareable` flag is also introduced.

`STRICT_VERIFY_SHAREABLE` macro is also introduced to verify
the strict shareable rule at `SET_SHAREABLE`.
2025-10-23 13:08:26 +09:00
Nobuyoshi Nakada
1546362fd1
win32: Prefix clock_getclock and clock_getres
Get rid of conflict with inline versions provided in time.h.
2025-10-17 15:09:15 +09:00
Nobuyoshi Nakada
b2d4dc9c46 win32: Support more clockid_t
Add `CLOCK_PROCESS_CPUTIME_ID` and `CLOCK_THREAD_CPUTIME_ID`.
2025-10-17 14:52:19 +09:00
Nobuyoshi Nakada
2bb6fe3854
[Bug #21629] Initialize struct RString 2025-10-08 18:19:47 +09:00
Nobuyoshi Nakada
43dbb9a93f
[Bug #21629] Enable nonstring attribute on clang 21 2025-10-08 18:17:19 +09:00
Étienne Barrié
8ad5a0a8d9 [DOC] Fix typos in comments 2025-09-15 12:08:02 +02:00
Jean Boussier
5ee083c71a Bump ABI version
Followup changes in https://github.com/ruby/ruby/pull/14470 /
03c86b053197f3cd6bece1925e634c1d74d196d0
2025-09-08 18:33:51 +02:00
Jean Boussier
03c86b0531 Move IS_TYPED_DATA in RBasic.flags
Ref: https://github.com/ruby/ruby/pull/14134#issuecomment-3207733725

We can't safely use low-bit pointer tagging anymore because `RTypedData.type`
lines up with `RData.dfree` and there is no aligment guarantee on function
pointers, as evidenced by `memcached` and `gpgme` gems.

We also can't use FL_USER* for this, because extensions may use these
for other purposes.

Using a general flag for this is a bit unfortunate, as general flags
are hard to come by, however I recently freed several of them, and
we still have two or three free ones left.
2025-09-08 13:24:21 +02:00
Alan Wu
cc07159fba [DOC] rb_str_resurrect(): Reword to remove wrong guess; used by zlib 2025-08-29 15:40:06 -04:00
Jean Boussier
5257e1298c Replace ROBJECT_EMBED by ROBJECT_HEAP
The embed layout is way more common than the heap one,
especially since WVA.

I think it makes for more readable code to inverse the
flag.
2025-08-27 12:41:07 +02:00
Jean Boussier
14bdf4b57d Ensure T_OBJECT and T_IMEMO/fields have identical layout 2025-08-26 13:44:59 +02:00
Takashi Kokubun
9bbd24977d
Fix a static assertion incompatible with C++98 (#14229) 2025-08-14 14:52:59 -07:00
Étienne Barrié
5aa5112443 Fix documentation about struct RData's data field
Also adds a static assertion to ensure the documented behavior stays
true, namely that the data field is at the same position in the RData
and RTypedData structs.
2025-08-14 19:53:04 +02:00
Jean Boussier
360be94d04 RTypedData: keep direct reference to IMEMO/fields
Similar to f3206cc79bec2fd852e81ec56de59f0a67ab32b7 but for TypedData.

It's quite common for TypedData objects to have a mix of reference in
their struct and some ivars.
Since we do happen to have 8B free in the RtypedData struct, we could
use it to keep a direct reference to the IMEMO/fields saving having
to synchronize the VM and lookup the `gen_fields_tbl` on every ivar
access.

For old school Data classes however, we don't have free space, but
this API is soft-deprecated and no longer very common.
2025-08-12 21:57:16 +02:00
John Hawthorn
4cf05ea77a Replace stdatomic ops with explicit mem order
My previous pass missed these atomic operations using operators.
2025-08-12 10:38:00 -07:00
John Hawthorn
cb360b0b4b Implement rbimpl_atomic_value_load
This only adds the rbimpl_ version to include/ruby/atomic.h so that it
is not a new public interface.

We were already using RUBY_ATOMIC_VALUE_LOAD in a few locations. This
will allow us to use other memory orders internally when desired.
2025-08-12 10:38:00 -07:00
John Hawthorn
1d9f76096e Update rbimpl_atomic_* to all take a memory order 2025-08-12 10:38:00 -07:00
John Hawthorn
2f95eb4e80 Rename rbimpl_atomic.*_set to _store
"store" is the terminology the C11 standard uses, which allows us to use
this as a fallback.

This only changes the private rbimpl_ version of the method,
RUBY_ATOMIC_SET et al. keep the same name.
2025-08-12 10:38:00 -07:00
Peter Zhu
7913aff2b3 [DOC] Fix return value of rb_str_hash_cmp
rb_str_hash_cmp returns 0 if the two strings are identical and 1 if they
are different.
2025-07-28 09:34:25 -04:00
Samuel Williams
64f508ade8
Support cause: in Thread#raise and Fiber#raise. (#13967)
* Add support for `cause:` argument to `Fiber#raise` and `Thread#raise`.

The implementation behaviour is consistent with `Kernel#raise` and
`Exception#initialize` methods, allowing the `cause:` argument to be
passed to `Fiber#raise` and `Thread#raise`. This change ensures that
the `cause:` argument is handled correctly, providing a more consistent
and expected behavior when raising exceptions in fibers and threads.

[Feature #21360]

* Shared specs for Fiber/Thread/Kernel raise.

---------

Co-authored-by: Samuel Williams <samuel.williams@shopify.com>
2025-07-24 14:45:43 +12:00