688 Commits
Author SHA1 Message Date
Yusuke EndohandClaude Opus 5.5 d193fd3217 Load the error decoration gems by firing their autoloads
The lazy loading of error_highlight, did_you_mean, and syntax_suggest
claimed the load by an atomic exchange before the load started. So a
caller in another Ractor or thread during the load returned the
undecorated message without waiting for the load to complete.

    rs = 2.times.map do
      Ractor.new do
        nil.upcase
      rescue => e
        e.detailed_message(highlight: false)
      end
    end
    rs.each { puts it.value, "" }
    # One of them lacks the snippet by error_highlight

Load the gems with rb_autoload_load instead of rb_require_string, as a
constant reference would. The autoload's own synchronization makes
concurrent callers wait until the load is done. The flag to load the
gems only once is no longer needed: rb_autoload_load does nothing once
the gems are loaded, and whether to re-dispatch is now decided by whether
the load has just put a decorator above Exception#detailed_message.

This also makes the gems loaded through RubyGems' Kernel#require, so a
newer version of the gems installed by the user is activated, as it was
before they were lazily loaded.

[Bug #22442]

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 13:50:39 +09:00
Hiroshi SHIBATAandClaude Opus 5 454c9df847 Use rb_len_t to iterate over Array elements
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-09 14:00:15 +09:00
Hiroshi SHIBATAandClaude Opus 5 cc3ba11012 Use rb_len_t in the C API for lengths and indices
Once rb_len_t widens this changes the `long *` output parameters of rb_range_beg_len(), rb_str_subpos(), rb_arithmetic_sequence_beg_len_step(), ruby_enc_find_basename() and ruby_enc_find_extname(), so extensions passing `long *` to them will need to be updated. The extension guides list these signatures verbatim and follow along.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-09 14:00:15 +09:00
Hiroshi SHIBATAandClaude Opus 5.5 3e96f16643 Require Mac OS X 10.6 or later
Mac OS X 10.6 came out in 2009, and the code removed here exists only for 10.5 and earlier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 07:04:09 +09:00
Hiroshi SHIBATAandClaude Opus 5.5 957caeef23 Drop support for Darwin on PowerPC
The last Mac OS X release for PowerPC Macs is 10.5, and nothing else runs this code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 07:04:09 +09:00
Shugo MaedaandClaude Fable 5.1 611bb146b0 [Feature #22304] Add rb_warn_to_remove_at and rb_warn_scheduled_deprecation
rb_warn_deprecated_to_remove_at warns only when Warning[:deprecated]
is enabled, so a deprecation scheduled to warn by default in a later
version needed a hand-written rb_warn and a separate commit to switch.

rb_warn_to_remove_at emits the same message with rb_warn and no
category.  rb_warn_scheduled_deprecation(X.Y, X.Z, ...) selects
between the two at compile time by RUBY_API_VERSION_CODE: gated by
Warning[:deprecated] before X.Y, shown by default from X.Y, and a
compile error in RUBY_DEBUG builds at X.Z, like the existing removal
check.  ruby/version.h is now included unconditionally and RUBY_VERSION_SINCE
and the version-string macros are always defined for that, while the
compile-time checks and RBIMPL_TODO stay RUBY_DEBUG only.  Both
functions are exported so that the new -test-/warning extension can
exercise both phases.

Use it for the two alias deprecations in rb_alias, which are scheduled
to warn by default in 4.2 and to be removed in 4.3.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-24 20:33:14 +09:00
Koichi SasadaandClaude Opus 5 844ffa9007 Let only the first thread write a bug report
When two Ractors fail an assertion at nearly the same time both write into
the same stream, and the first report -- the interesting one -- is cut
short by the second:

    rs = 100.times.map { Ractor.new { sleep rand(1..3); Ractor.fail_assert } }

produced a 25-line report ending in "Crashed while printing bug report",
every time.

Take a claim before writing.  The first thread through writes its report
and aborts the process; a later one waits for that instead of writing its
own.  The claiming thread is let through again, so the existing
crash-while-reporting path still works.  The wait is bounded, so a writer
that hangs still ends the process as a crash rather than a hang.

rb_assert_failure_detail() writes a report without going through
report_bug(), so it needs the same claim.

The example above now produces one complete report.

[Bug #21146]

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-09 14:01:07 +09:00
Jean Boussier 56abc30ec2 Righ-size more hashes
The pattern of allocating an empty hash with `rb_hash_new()` and
then appending to it is relatively wasteful, because every time
we go over the hash capacity, we'll have to `realloc`, rehash etc.

It may even get worse if https://github.com/ruby/ruby/pull/18345
lands, as right now an empty hash starts with a capacity of 8,
but it may very well start with a capacity of 2.

Hence in cases where the final hash size is easy to predict, we
should use `rb_hash_new_capa()`.
2026-08-23 11:50:40 +02:00
Peter Zhu a0c1b4fbfd Make rb_get_message static 2026-08-02 09:16:50 -04:00
Hiroshi SHIBATA 22258b1d5f Load the error decoration gems from non-main Ractors too
rb_require_string delegates requires from non-main Ractors to the
main Ractor via rb_ractor_require, so the main-Ractor guard here was
unnecessary. Drop it and claim the load with an atomic exchange,
because Ractors run in parallel and the plain bool flag was only safe
under that guard. did_you_mean already keeps its state Ractor-safe,
so suggestions now appear in non-main Ractors as well.

Suggested by John Hawthorn.
2026-07-21 11:49:03 +09:00
Hiroshi SHIBATA 67dc1dfbc8 Preserve the caller's $! while loading the error decoration gems
require_decoration_gems is called while an exception is being displayed,
so $! holds that exception. rb_protect does not preserve errinfo across
the call, and the previous code cleared it to nil whenever a require
raised, losing the exception being shown. Save errinfo before the
requires and restore it afterward so $! is left untouched whether or not
a require fails.
2026-07-21 11:49:03 +09:00
Hiroshi SHIBATAandClaude Fable 5 201dece9d7 Eager load the error decoration gems from Process.warmup
The decoration gems are loaded lazily on the first error display, which
in a pre-forking server happens after fork in each child. That loads
their code outside copy-on-write shared memory and busts method caches
at runtime when they prepend Exception#detailed_message.

Process.warmup, called before the first fork by such servers, now loads
them eagerly so the prepended decorators land in shared memory and the
cache invalidation happens during boot.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 11:49:03 +09:00
Hiroshi SHIBATAandClaude Fable 5 cadf8e7933 Lazy load error_highlight, did_you_mean, and syntax_suggest
[Feature #21951]

Defer loading these gems from boot to the first error display. They
only decorate Exception#detailed_message, so requiring them at boot is
unnecessary overhead. `ruby -e1` with user-installed gems drops from
114.3ms to 30.2ms on Apple M1 Pro, matching the --disable-* flags for
the three gems.

exc_detailed_message forces the autoload entries once on the first
call, only in the main Ractor, and then re-dispatches to pick up the
detailed_message decorators the gems prepend. When the first call
arrives through an already-prepended decorator, re-dispatching is
skipped to avoid decorating twice. The gems are loaded with the
C-level require so that displaying an error neither invokes nor
depends on Kernel#require monkeypatches.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 11:49:03 +09:00
Nobuyoshi Nakada 37d2bb3c8c Search NameError messages within string bounds
Use the message length when looking for the receiver placeholder
instead of requiring a NUL-terminated string.
2026-07-15 13:28:39 +09:00
Jean Boussier 2c574ca7e2 Symbol#to_s now returns a frozen string.
[Feature #22137]

It has returned a chilled string, hence emitting deprecation
warnings for two versions.
2026-07-10 10:02:00 +02:00
John HawthornandLuke Gruber daffaaee73 Mark most TypedData types as THREAD_SAFE_FREE
Set RUBY_TYPED_THREAD_SAFE_FREE on TypedData types whose dfree function
is trivially safe, and only frees its own memory

Types not yet marked as THREAD_SAFE_FREE:
- id2ref_tbl_type: sets the process-global id2ref_tbl to NULL.
- mutex_data_type: unlinks itself from another thread's keeping_mutexes list.
- autoload_data_type: deletes nodes from a shared intrusive list.
- autoload_const_type: deletes itself from a shared list.
- rb_cont_data_type: mutates the shared fiber pool and the global first_jit_cont list.
- rb_fiber_data_type: delegates to cont_free.
- FiberPoolDataType: mutates shared fiber pool free-lists.
- ractor_data_type: reconfigures global VM event-hook flags and call caches.
- exported_object_registry: frees a global table under the VM lock.
- rb_box_data_type (Box::Entry): unlinks classext from other live class and module objects.
- box_ext_cleanup_type: dereferences another String object and calls unlink.
- monitor_data_type: uses the default free, so the flag has no effect.

Co-authored-by: Luke Gruber <luke.gruber@shopify.com>
2026-06-23 13:30:26 -07:00
Nobuyoshi Nakada 5497859f40 Remove use of RTYPEDDATA_P and rbimpl_rtypeddata_p 2026-05-28 19:29:32 +09:00
Benoit Daloze b583dd6879 Fix typo and improve docs of Exception#exception 2026-05-04 17:15:53 +02:00
Takashi Kokubun ee60b99b2f Rename rb_cfp_iseq to CFP_ISEQ and rb_cfp_pc to CFP_PC
Rename for consistency with ISEQ_BODY naming convention. Remove the
separate rb_cfp_has_iseq/rb_cfp_has_pc wrappers — CFP_ISEQ and CFP_PC
return NULL for missing values, which works directly in if conditions.
2026-03-27 16:26:12 -07:00
Takashi Kokubun 226f37059e Rename cfp->iseq to cfp->_iseq and rb_zjit_cfp_iseq to rb_cfp_iseq
Per tenderlove's review, every cfp->iseq read should go through an
accessor that accounts for JITFrame. Rename the field to _iseq so
direct access causes a compile error, and rename the accessors to
drop the zjit prefix (rb_cfp_iseq, rb_cfp_has_iseq, rb_cfp_pc,
rb_cfp_has_pc).
2026-03-27 16:26:12 -07:00
Takashi KokubunandAlan Wu c8f97943ef ZJIT: Lightweight Frames
Co-authored-by: Alan Wu <alanwu@ruby-lang.org>
2026-03-27 16:26:12 -07:00
Takashi Kokubun 1b2dfdf4be Fix crash report being truncated by secondary crashes (#16586)
When rb_bug() is called (e.g. from a ZJIT Rust panic), the crash report
file could be truncated and left nearly empty due to two issues:

1. The crash report file was opened with default (buffered) I/O. If
   rb_vm_bugreport() triggered a secondary crash, buffered output was
   lost. Fix by setting the file to unbuffered with setvbuf().

2. After rb_bug() wrote the crash report, die() called abort() which
   triggered our custom SIGABRT handler. The handler re-opened the same
   crash report file with "w" mode, truncating the report that was
   already written. Fix by resetting SIGABRT to SIG_DFL before abort().
2026-03-27 16:25:04 -07:00
Jean BoussierandBenoit Daloze d066b9e01c Refactor type error to be more consistent
[Bug #21864]

Co-Authored-By:  Benoit Daloze <eregontp@gmail.com>
2026-02-07 10:06:36 +01:00
卜部昌平 60cf8598b2 [nit] refactor rename inline functions
Pretty sure commit 0f64da9672 didn't
intend to welcome extension libraries to use these functions.
2026-01-13 11:53:43 +09:00
Burdette Lamar 58fb95af36 [DOC] Harmonize #== methods (#15805) 2026-01-06 17:13:15 -05:00
Nobuyoshi Nakada 0f64da9672 Make rb_check_typeddata and rbimpl_check_typeddata identical 2025-12-29 18:40:47 +09:00
Jeremy Evans 76fb0d244b Use actual class instead of singleton class in frozen error message
With the following code:

```ruby
object = []
object.singleton_class
object.freeze
object.instance_variable_set(:@a, 42)
```

The previous error message was:

```
can't modify frozen #<Class:#<Array:0x00000631d1308f78>>: []
```

With this change, the error message is:

```
can't modify frozen Array: []
```

Since we show the inspect value of the affected object, I think
including the singleton class instead of the actual class if it
exists makes the error message harder to understand.
2025-12-10 07:35:50 +09:00
Nobuyoshi Nakada 7840ef2f43 Win32: Allow some mingw implemeations to use old msvcrt 2025-11-19 22:51:09 +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
Étienne Barrié 79b2685675 [DOC] Fix typos
Inspired by 42ba82424d, I looked for other
occurrences of "the the".
2025-10-13 15:21:36 -04:00
Nobuyoshi Nakada 2bb6fe3854 [Bug #21629] Initialize struct RString 2025-10-08 18:19:47 +09:00
Luke Gruber d869164124 rb_bug shouldn't assume ec is available (don't use GET_EC())
ec is unavailable on timer thread, for instance.
2025-09-24 10:41:04 -07:00
Jean Boussier bc9781c264 Convert name_err_mesg to use rb_gc_mark_and_move
The `p->field = rb_gc_location(p->field)` isn't ideal because it means all
references are rewritten on compaction, regardless of whether the referenced
object has moved. This isn't good for caches nor for Copy-on-Write.

`rb_gc_mark_and_move` avoid needless writes, and most of the time allow to
have a single function for both marking and updating references.
2025-08-07 21:00:00 +02:00
ydah 3d8af5df11 Fix typo in documentation comment for exc_inspect method in error.c 2025-08-05 21:58:12 +09:00
Nobuyoshi Nakada 6179cc0118 [DOC] Fill undocumented documents 2025-08-04 02:23:43 +09:00
Nobuyoshi Nakada c218862d3c Fix style [ci skip] 2025-04-19 22:02:10 +09:00
Nobuyoshi Nakada 022ab41374 [DOC] Improve Errno and SystemCallError.new 2025-01-31 21:30:07 +09:00
Nobuyoshi Nakada e433e6515e [DOC] Exclude 'Class' and 'Module' from RDoc's autolinking 2025-01-02 12:36:06 +09:00
Victor Shepelev 58460b4dbd [DOC] Adjust documentation related to backtraces (#12420) 2024-12-24 20:49:55 +02:00
zverok 3808d29e20 Fix extra 'warning:' prefix for chilled Symbol#to_s 2024-12-22 15:08:19 +09:00
Stan Lo 2a44a57e14 [DOC] Link to special fatal class through rdoc-ref 2024-12-19 14:15:23 -08:00
Takashi Kokubun 923f831804 Suppress -Wsuggest-attribute=format 2024-12-15 23:27:43 -08:00
Stan Lo ff8570b005 Fix LoadError's linking issue
Original issue: https://github.com/ruby/rdoc/issues/1128

The problem is caused by the `# :stopdoc:` directive in `bundled_gems.rb`,
which's scope covers the redefinition of `LoadError`.

Since the goal of `# :stopdoc:` is to hide the documentation of `Gem::BUNDLED_GEMS`,
we can use `# :nodoc:` on it instead.
2024-12-12 16:43:25 -05:00
Peter Zhu ca2d19d4e5 Implement rb_bug_without_die 2024-12-12 14:07:56 -05:00
Nobuyoshi Nakada 267ecf5f02 Add rb_warn_reserved_name_at 2024-12-12 17:45:06 +09:00
Peter Zhu 14ce2443db Make rb_bug_without_die static
It's not used outside of error.c.
2024-11-27 11:32:58 -05:00
Jean BoussierandÉtienne Barrié cedcf2d681 error.c: call va_end before jumping
The man page is clear that every `va_start` call MUST be succeeded by
the corresponding `va_end` call.

So `rb_raise` can't call `rb_exc_raise` before `va_end`, otherwise
`va_end` is never called.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
2024-11-25 18:18:39 +01: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
Alan Wu fca07d73e3 Respect RUBY_CRASH_REPORT path when RUBY_ASSERT() fails
Previously, it always used stderr. Slight shuffle of the first line
of the crash due to reusing code from rb_bug():

```diff
-Assertion Failed: /ruby/object.c:649:rb_obj_itself:false
+/ruby/object.c:649: Assertion Failed: rb_obj_itself:false
```

Tested locally to confirm that it writes to the file given with
RUBY_CRASH_REPORT. Follow-up for [Feature #19790].
2024-11-07 09:35:19 -05: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