2399 Commits

Author SHA1 Message Date
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
fuhsnn
98aa2a6608 atomic.h: Add C11 <stdatomic.h> implementation
The implementation is only active if `HAVE_STDATOMIC_H` is defined,
and only after the compiler fails to match all currently supported
systems.
2025-07-17 15:46:37 +09:00
fuhsnn
a7992400f1 atomic.h: Use explicit logic for 32-bit #else branches
These branches are only active for 32-bit Windows and Solaris platforms,
codify the fact by changing `#else` to `#elif`'s that explicitly include
those targets and `#error`-out otherwise.
2025-07-17 15:46:37 +09:00
Jeremy Evans
2ab38691a2 Add Set C-API
This should be a minimal C-API needed to deal with Set objects. It
supports creating the sets, checking whether an element is the set,
adding and removing elements, iterating over the elements, clearing
a set, and returning the size of the set.

Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>
2025-07-11 15:24:23 +09:00
John Hawthorn
6b7f56d2db Never use flags on T_NODE
Previously, any time we used FL_TEST or variations we would need to add
an additional test that it wasn't a T_NODE. I think that was only needed
historically and we can avoid generating that extra code.
2025-06-25 15:58:53 -07:00
Jean Boussier
15084fbc3c Get rid of FL_EXIVAR
Now that the shape_id gives us all the same information, it's no
longer needed.
2025-06-13 23:50:30 +02:00
Samuel Williams
ead14b19aa Fix blocking_operation_wait use-after-free bug. 2025-06-06 13:13:16 +09:00
Peter Zhu
ea8b53a539 Allow pass special constants to the write barrier
Some GC implementations want to always know when an object is written to,
even if the written value is a special constant. Checking special constants
in rb_obj_written was a micro-optimization that made assumptions about
the GC implementation.
2025-06-03 12:04:24 -04:00
Jean Boussier
e9fd44dd72 shape.c: Implement a lock-free version of get_next_shape_internal
Whenever we run into an inline cache miss when we try to set
an ivar, we may need to take the global lock, just to be able to
lookup inside `shape->edges`.

To solve that, when we're in multi-ractor mode, we can treat
the `shape->edges` as immutable. When we need to add a new
edge, we first copy the table, and then replace it with
CAS.

This increases memory allocations, however we expect that
creating new transitions becomes increasingly rare over time.

```ruby
class A
  def initialize(bool)
    @a = 1
    if bool
      @b = 2
    else
      @c = 3
    end
  end

  def test
    @d = 4
  end
end

def bench(iterations)
  i = iterations
  while i > 0
    A.new(true).test
    A.new(false).test
    i -= 1
  end
end

if ARGV.first == "ractor"
  ractors = 8.times.map do
    Ractor.new do
      bench(20_000_000 / 8)
    end
  end
  ractors.each(&:take)
else
  bench(20_000_000)
end
```

The above benchmark takes 27 seconds in Ractor mode on Ruby 3.4,
and only 1.7s with this branch.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
2025-06-02 17:49:53 +02:00
Nobuyoshi Nakada
18a036a613
[Feature #21205] Define File::Stat#birthtime by statx 2025-05-30 20:55:12 +09:00
John Hawthorn
d1343e12d2 Use flag for RCLASS_IS_INITIALIZED
Previously we used a flag to set whether a module was uninitialized.
When checked whether a class was initialized, we first had to check that
it had a non-zero superclass, as well as that it wasn't BasicObject.

With the advent of namespaces, RCLASS_SUPER is now an expensive
operation, and though we could just check for the prime superclass, we
might as well take this opportunity to use a flag so that we can perform
the initialized check with as few instructions as possible.

It's possible in the future that we could prevent uninitialized classes
from being available to the user, but currently there are a few ways to
do that.
2025-05-28 11:44:07 -04:00
John Hawthorn
f483befd90 Add shape_id to RBasic under 32 bit
This makes `RBobject` `4B` larger on 32 bit systems
but simplifies the implementation a lot.

[Feature #21353]

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2025-05-26 10:31:54 +02:00
Samuel Williams
627a5ac53b
Bump fiber scheduler version and add missing documentation. (#13424) 2025-05-23 16:20:33 +09:00
Samuel Williams
73c9d6ccaa
Allow IO#close to interrupt IO operations on fibers using fiber_interrupt hook. (#12839) 2025-05-23 14:55:05 +09:00
Nobuyoshi Nakada
ec41b1e823 Fix for old mingw without clock_gettime and clock_getres 2025-05-22 13:08:39 +09:00
Alan Wu
2297afda7f
Include stdbool.h without checking with autoconf
As reported in <https://bugs.ruby-lang.org/issues/21340>, older autoconf
have an AC_HEADER_STDBOOL that's incompatible with C23. Autoconf 2.72
fixed the macro, but also mentions that it's obsolescent since all
current compilers have this header.

Since we require C99 [1] and VS 2015 [2], we might actually be able take
that suggestion and include stdbool.h without a check. I want to try
this on rubyci.org and will revert if this cause any issues. Not
touching AC_HEADER_STDBOOL in configure.ac for now.

[1]: https://bugs.ruby-lang.org/issues/15347
[2]: https://bugs.ruby-lang.org/issues/19982
2025-05-20 15:58:32 +00:00
Jean Boussier
76ec41bf3d Bump ABI_VERSION
`struct RTypedData` was changed significantly in https://github.com/ruby/ruby/pull/13190
which breaks many extensions.

Bumping the ABI version might save some people from needlessly
investigating crashes.
2025-05-14 21:01:32 +02:00
Jean Boussier
b5575a80bc Reduce Object#object_id contention.
If the object isn't shareable and already has a object_id
we can access it without a lock.

If we need to generate an ID, we may need to lock to find
the child shape.

We also generate the next `object_id` using atomics.
2025-05-14 14:41:46 +02:00
Jean Boussier
5974841d11 Remove outdated references to FL_SEEN_OBJ_ID 2025-05-13 12:02:19 +02:00
Samuel Williams
425fa0aeb5
Make waiting_fd behaviour per-IO. (#13127)
- `rb_thread_fd_close` is deprecated and now a no-op.
- IO operations (including close) no longer take a vm-wide lock.
2025-05-13 19:02:03 +09:00
Nobuyoshi Nakada
3e47e7a499 Fix redefinition of clock_gettime and clock_getres
winpthreads-git 12.0.0.r720 provides `clock_gettime` and
`clock_getres` as inline functions.
2025-05-12 02:50:25 +09:00
Satoshi Tagomori
382645d440 namespace on read 2025-05-11 23:32:50 +09:00
Jean Boussier
f48e45d1e9 Move object_id in object fields.
And get rid of the `obj_to_id_tbl`

It's no longer needed, the `object_id` is now stored inline
in the object alongside instance variables.

We still need the inverse table in case `_id2ref` is invoked, but
we lazily build it by walking the heap if that happens.

The `object_id` concern is also no longer a GC implementation
concern, but a generic implementation.

Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
2025-05-08 07:58:05 +02:00
Jean Boussier
0ea210d1ea Rename ivptr -> fields, next_iv_index -> next_field_index
Ivars will longer be the only thing stored inline
via shapes, so keeping the `iv_index` and `ivptr` names
would be confusing.

Instance variables won't be the only thing stored inline
via shapes, so keeping the `ivptr` name would be confusing.

`field` encompass anything that can be stored in a VALUE array.

Similarly, `gen_ivtbl` becomes `gen_fields_tbl`.
2025-05-08 07:58:05 +02:00