2339 Commits
Author SHA1 Message Date
nagachika 8d4a42139b merge revision(s) 493d26dcde:
[PATCH] Reject overflowed repeat/null-check IDs in huge regexps (#16801)

	Add explicit errors for excessive range-repeat and null-check IDs;
	map new errors in regerror; add regression tests for oversized generated
	patterns.
2026-10-22 21:55:13 +09:00
Hiroshi SHIBATAandClaude Opus 5 2d1859ffa6 Reject a compiled program too big for its offset type
Concatenated large repeats reach a program past INT_MAX from a few hundred
kilobytes of source, and the offsets emitted into it wrap.  Cap the size
while the program is emitted, which does not depend on the length pass that
overflows along with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-12 17:21:24 +09:00
nagachika 083198e9fb merge revision(s) 78b7646bdb, b4a62a1ca9: [Backport #21842]
[PATCH] [Bug #21842] Let `rb_interned_str` return US-ASCII if possible

	[PATCH] [DOC] Update docs for rb_interned_str and related functions (#15897)

	Related to [Bug #21842].

	* rb_interned_str: document what decides whether the returned string is
	  in US-ASCII or BINARY encoding.
	* rb_interned_str_cstr: include the same description as rb_interned_str
	  for the encoding. This one was still missing the update for US-ASCII
	  and erroneously said the returned string was alwasy in BINARY encoding
	* rb_str_to_interned_str: document how the encoding of the result is
	  defined.

	Co-authored-by: Herwin <herwinw@users.noreply.github.com>
2026-08-09 14:17:55 +09:00
nagachika 28db1b5c3d merge revision(s) 61bab18890: [Backport #21757]
[PATCH] 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.
2026-01-25 16:41:13 +09:00
nagachika c409e343fb merge revision(s) 99ff0224a5: [Backport #21757]
[PATCH] Move rbimpl_size_add_overflow from gc.c to memory.h
2026-01-25 16:40:50 +09:00
Takashi Kokubun da66b64a18 merge revision(s) 9d44cb0b2b, 367ddd445c, 48dce7874f: [Backport #21655]
[PATCH] Remove rbimpl_rstring_getmem() usage as workaround for GCC 15.2.1 optimization bug. [Bug #21655]

	[PATCH] include/ruby/internal/core/rstring.h: Remove rbimpl_rstring_getmem() definition.

	[PATCH] simplify RSRING_GETMEM() definition.
2025-12-08 14:36:06 -08:00
Takashi Kokubun 18e176659e merge revision(s) 2bb6fe3854: [Backport #21629]
[PATCH] [Bug #21629] Initialize `struct RString`

which appears to be missed in the previous commit for some reason.
2025-10-08 16:50:58 -07:00
Takashi Kokubun 846bb76075 merge revision(s) bbf1130f91, 43dbb9a93f, 2bb6fe3854, 7c9dd0ecff: [Backport #21629]
[PATCH] Add `RBIMPL_ATTR_NONSTRING_ARRAY()` macro for GCC 15

	[PATCH] [Bug #21629] Enable `nonstring` attribute on clang 21

	[PATCH] [Bug #21629] Initialize `struct RString`

	[PATCH] [Bug #21629] Initialize `struct RArray`
2025-10-08 16:45:24 -07:00
Takashi Kokubun 596126ee5a merge revision(s) b42afa1dbc, f1f0cc14cc, 543e3a1896, ed2806117a, 46e4c86737: [Backport #21500]
Suppress gcc 15 unterminated-string-initialization warnings

	Separate `__has_attribute` from `defined(__has_attribute)`

	Fix Visual C warnings:
	```
	regenc.h(121): warning C4067: unexpected tokens following preprocessor directive - expected a newline
	```

	Cast up `int` instruction code to `VALUE`

	Fix Visual C warnings:
	```
	iseq.c(3793): warning C4312: 'type cast': conversion from 'int' to 'void *' of greater size
	iseq.c(3794): warning C4312: 'type cast': conversion from 'int' to 'void *' of greater size
	```

	Do not let files depend on a phony target

	Detect `clock_gettime` and `clock_getres` for winpthreads
2025-07-14 14:50:56 -07:00
Alan Wu ca1ea95784 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], should be able take
that suggestion and include stdbool.h without a check. This worked
fine on rubyci.org.

[Backport #21340]

[1]: https://bugs.ruby-lang.org/issues/15347
[2]: https://bugs.ruby-lang.org/issues/19982
2025-05-22 09:21:10 -07:00
Takashi Kokubun 65e02ab1a6 merge revision(s) 3e47e7a499, b48b841378, 2fe8b9cd3d: [Backport #21327]
Fix redefinition of `clock_gettime` and `clock_getres`

	winpthreads-git 12.0.0.r720 provides `clock_gettime` and
	`clock_getres` as inline functions.

	digest.so needs ruby/digest.h which is installed by build-ext

	Copy to path with the base name
2025-05-13 17:18:43 -07:00
Alan Wu 7e44df91b6 Fix C23 (GCC 15) WIN32 compatibility for rb_define_* functions
Backport [Bug #21286]
2025-05-07 10:04:46 -07:00
Nobuyoshi Nakada b5c921e010 [Bug #21024] <cstdbool> header has been useless
And finally deprecated at C++-17.
Patched by jprokop (Jarek Prokop).
2025-02-13 17:40:19 -08:00
Naohisa Goto 528ec70604 use RBIMPL_ATTR_MAYBE_UNUSED
The macro MAYBE_UNUSED, prepared by ./configure, may not be defined in
some environments such as Oracle Developer Studio 12.5 on Solaris 10.

This fixes [Bug #20963]
2024-12-18 23:37:22 +09:00
Alan Wu 6336431a64 [DOC] rb_id2name(): Note truncation danger (+minor copyediting)
Thanks, nobu!
2024-12-17 21:50:00 -05:00
Peter Zhu 375fec7c53 [DOC] Add note to rb_id2name about GC compaction 2024-12-17 16:32:13 -05:00
Nobuyoshi Nakada 5a7a1a4a13 Win32: Fix rbimpl_size_mul_overflow on arm64
`_umul128` is specific to x86_64 platform, see higher words by
`__umulh` on arm64.
2024-12-17 20:25:06 +09:00
Nobuyoshi Nakada 86f00c9922 [DOC] Update rb_strlen_lit
It is not "in bytes" for wide char literal.
2024-12-13 13:49:33 +09:00
Alan Wu c0e12bf8d2 Fix typos in public headers [ci skip] 2024-12-04 16:26:31 -05:00
Alan Wu 88764dde78 [DOC] Rewrite docs for rb_sym2str()
Explaining this by reference to rb_id2str() obscures a few important
details because IDs and symbols don't map to each other perfectly (you
can have a dynamic symbol without an ID!) Also, it used to take 2
redirections to get to concrete information, and I think being more
direct is friendlier.
2024-11-29 18:33:44 -05:00
Alan Wu 2a0006c101 [DOC] Mention that rb_id2str() returns a frozen string 2024-11-29 18:33:44 -05:00
Samuel Williams 9c268302bf Introduce Fiber::Scheduler#blocking_operation_wait. (#12016)
Redirect `rb_nogvl` blocking operations to the fiber scheduler if possible
to prevent stalling the event loop.

[Feature #20876]
2024-11-20 19:40:17 +13:00
6deeec5d45 Mark strings returned by Symbol#to_s as chilled (#12065)
* Use FL_USER0 for ELTS_SHARED

This makes space in RString for two bits for chilled strings.

* Mark strings returned by `Symbol#to_s` as chilled

[Feature #20350]

`STR_CHILLED` now spans on two user flags. If one bit is set it
marks a chilled string literal, if it's the other it marks a
`Symbol#to_s` chilled string.

Since it's not possible, and doesn't make much sense to include
debug info when `--debug-frozen-string-literal` is set, we can't
include allocation source, but we can safely include the symbol
name in the warning message, making it much easier to find the source
of the issue.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>

---------

Co-authored-by: Étienne Barrié <etienne.barrie@gmail.com>
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-11-13 09:20:00 -05:00
Nobuyoshi Nakada f17cfb4958 Add missing macros for __has_builtin 2024-11-12 16:40:52 +09:00
Nobuyoshi Nakada bce1bd1dc1 rb_strlen_lit: support wide string literals 2024-11-10 22:52:17 +09:00
Nobuyoshi Nakada 2f88a9258d Fix sign-conversion warnings on IL32 platforms
If `long` and `int` are the same size, `unsigned int` max would exceed
`signed long` range.  It is guaranteed by `RB_POSFIXABLE` that `v` can
be casted to `long` safely here.
2024-11-10 21:57:56 +09:00
Samuel Williams 3b9896acfc Revert "Introduce Fiber Scheduler blocking_region hook. (#11963)" (#12013)
This reverts some of commit 87fb44dff6.

We will rename and propose a slightly different interface.
2024-11-06 22:19:40 +13:00
Koichi Sasada ab7ab9e450 Warning[:strict_unused_block]
to show unused block warning strictly.

```ruby
class C
  def f = nil
end

class D
  def f = yield
end

[C.new, D.new].each{|obj| obj.f{}}
```

In this case, `D#f` accepts a block. However `C#f` doesn't
accept a block. There are some cases passing a block with
`obj.f{}` where `obj` is `C` or `D`. To avoid warnings on
such cases, "unused block warning" will be warned only if
there is not same name which accepts a block.
On the above example, `C.new.f{}` doesn't show any warnings
because there is a same name `D#f` which accepts a block.

We call this default behavior as "relax mode".

`strict_unused_block` new warning category changes from
"relax mode" to "strict mode", we don't check same name
methods and `C.new.f{}` will be warned.

[Feature #15554]
2024-11-06 11:06:18 +09:00
Nobuyoshi Nakada e2909570bb Include windows.h for LONG and Interlocked functions 2024-11-02 22:27:03 +09:00
Samuel Williams 87fb44dff6 Introduce Fiber Scheduler blocking_region hook. (#11963) 2024-10-31 17:26:37 +13:00
Nobuyoshi Nakada 7d1011d3fa Fix false warning by gcc 14 for aarch64
gcc 14 for aarch64 with `-O3` may emit a false positive warning for a
pointer access of `RB_BUILTIN_TYPE` called from `RB_TYPE_P`.  `Qfalse`
shouldn't get there because of `RB_SPECIAL_CONST_P`, but the optimizer
seems to ignore this condition in some cases (`ASSUME` just before the
access doesn't seem to have any effect either).  Only by reversing the
order in `RB_SPECIAL_CONST_P` to compare with 0 first does the warning
seem to go away.
2024-10-23 23:02:15 +09:00
Nobuyoshi Nakada 9a90cd2284 Cast via uintptr_t function pointer between object pointer
- ISO C forbids conversion of function pointer to object pointer type
- ISO C forbids conversion of object pointer to function pointer type
2024-10-08 23:29:49 +09:00
Samuel Williams c878843b2c Better handling of timeout in rb_io_maybe_wait_*. (#9531) 2024-10-04 19:36:06 +13:00
Samuel Williams 96d69d2df2 Clarify rb_io_maybe_wait behaviour. (#9527) 2024-10-04 18:40:38 +13:00
NAITOH Jun 373f679e48 fix rb_memsearch() document
## Why?
The explanation of x and y is reversed.

https://github.com/ruby/ruby/blob/ddbd64400199fd408d23c85f9fb0d7f742ecf9e1/re.c#L251-L256
```
long
rb_memsearch(const void *x0, long m, const void *y0, long n, rb_encoding *enc)
{
    const unsigned char *x = x0, *y = y0;

    if (m > n) return -1;
```
2024-09-24 15:12:48 +09:00
Alan Wu 3fa5b4be19 [DOC] Mention rb_io_fdopen() takes ownership of the FD 2024-08-28 17:27:57 -04:00
Nobuyoshi Nakada 1fd0a1b4ce Fix sign-conversion warning
```
../../.././include/ruby/internal/special_consts.h:349:36: error: conversion to ‘VALUE’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Werror=sign-conversion]
  349 |     return RB_SPECIAL_CONST_P(obj) * RUBY_Qtrue;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
```
2024-08-11 16:04:37 +09:00
Peter Zhu 10574857ce Fix memory leak in Regexp capture group when timeout
[Bug #20650]

The capture group allocates memory that is leaked when it times out.

For example:

    re = Regexp.new("^#{"(a*)" * 10_000}x$", timeout: 0.000001)
    str = "a" * 1000000 + "x"

    10.times do
      100.times do
        re =~ str
      rescue Regexp::TimeoutError
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    34688
    56416
    78288
    100368
    120784
    140704
    161904
    183568
    204320
    224800

After:

    16288
    16288
    16880
    16896
    16912
    16928
    16944
    17184
    17184
    17200
2024-07-25 09:23:49 -04:00
Alan Wu 8cf708d7b4 Make rb_check_frozen_inline() static inline again
Since 730e3b2ce0
("Stop exposing `rb_str_chilled_p`"), we noticed a speed loss on a few
benchmarks that are string operations heavy. This is partially due to
routines no longer having the options to inline rb_check_frozen_inline()
in non-LTO builds. Make it an inlining candidate again to recover speed.

Testing this patch on my machine, the fannkuchredux benchmark gets a
1.15 speed-up with YJIT and 1.03 without YJIT.
2024-07-19 17:47:12 -04:00
Alan Wu 99825a539f [DOC] Note that rb_obj_freeze_inline() can raise NoMemoryError
And move it back to a public header because Doxygen might not be
scanning the .c files.

[Feature #18776]
2024-07-17 10:25:20 -04:00
Alan Wu cd428b490d [DOC] No more is rb_ary_freeze() an alias of rb_obj_freeze()
[Feature #20589]
2024-07-17 10:25:20 -04:00
卜部昌平 fa6bf1da57 give up USE_GC_MALLOC_OBJ_INFO_DETAILS
This feature is no longer possible under current design; now that our GC
is pluggable, we cannot assume what was achieved by this compiler flag
is always possble by the dynamically-loaded GC implementation.
2024-07-12 10:21:07 +09:00
Yusuke Endoh 114e32b357 Add rb_block_call2, a flexible variant of rb_block_call
This function accepts flags:

RB_NO_KEYWORDS, RB_PASS_KEYWORDS, RB_PASS_CALLED_KEYWORDS:
Works as the same as rb_block_call_kw.

RB_BLOCK_NO_USE_PACKED_ARGS:
The given block ("bl_proc") does not use "yielded_arg" of rb_block_call_func_t.
Instead, the block accesses the yielded arguments via "argc" and "argv".
This flag allows the called method to yield arguments without allocating an Array.
2024-07-10 13:00:47 +09:00
Nobuyoshi Nakada 249a1fb0eb Show more in RBIMPL_ASSERT_TYPE 2024-06-21 09:25:00 +09:00
Nobuyoshi Nakada b834c62efd Delegate from RBIMPL_ASSERT_OR_ASSUME to RUBY_ASSERT_ALWAYS
Get rid of expansion of the argument which often contains complicated
macros, and simplify the failure message.
2024-06-21 09:24:59 +09:00
Alan Wu 2699e230e4 Crash instead of raising with Check_Type() in RBIMPL_ASSERT_TYPE() in debug builds
Previously, RBIMPL_ASSERT_TYPE() used Check_Type() only in RUBY_DEBUG
builds. It raised TypeError, but only in debug builds. For people testing
type mismatch using debug builds looking for a Ruby exception, this can
be misleading -- the code could be missing a type check in non-debug builds
if it is relying on for example RSTRING_LEN() to raise.

Also, Check_Type() can obscure the true cause of error in debug mode.
When type check fails because the object is corrupt, instead of crashing
with a clear type assertion message, it can crash while trying to
construct an exception object to raise. You can see this for example in
<https://github.com/ruby/ruby/actions/runs/9489999591/job/26152506434?pr=10985>,
where RB_ENCODING_GET() is used on a corrupt object, but the crash
happens later and says "Assertion Failed:
../src/vm_method.c:1477:callable_method_entry_or_negative".
RBIMPL_ASSERT_TYPE() should assert right away.

RBIMPL_ASSERT_OR_ASSUME() asserts when RUBY_DEBUG and assumes in release
builds, as desired.

This should help investigate flaky CI failures that show up as TypeError
from `Kernel#require`, e.g.
"'Kernel#require': wrong argument type false (expected String) (TypeError)".

Same CI failure examples:
 - https://github.com/ruby/ruby/actions/runs/9034787861/job/24828147431
 - https://github.com/ruby/ruby/actions/runs/9418303667/job/25945492440
 - https://github.com/ruby/ruby/actions/runs/9505650952/job/26201031314

The failure occurs with and without use of YJIT.
2024-06-13 21:43:41 +00:00
Nobuyoshi Nakada 0396050f5a Cast RUBY_ATOMIC_PTR_CAS arguments
As well as `RUBY_ATOMIC_PTR_EXCHANGE` and `RUBY_ATOMIC_PTR_LOAD`.
2024-06-07 10:42:41 +09:00
Jean Boussier fbb61a26e7 Mark old Data API as deprecated
[Feature #19998]
2024-06-06 11:44:27 +02: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
Jean Boussier ceeb9957c3 Make value_type.h compatible with -Wconversion
[Feature #20507]

This was missed from the initial commit.

```
../../.././include/ruby/internal/value_type.h:446:27: error: implicit conversion changes signedness: 'enum ruby_value_type' to 'int' [-Werror,-Wsign-conversion]
    rb_unexpected_type(v, t);
    ~~~~~~~~~~~~~~~~~~    ^
```
2024-05-28 08:43:43 +02:00