597 Commits

Author SHA1 Message Date
Peter Zhu
1d096c1e53 Fix crash in NoMethodError for dummy frames
[Bug #19793]

Dummy frames are created at the top level when requiring another file.
While requiring a file, it will try to convert using encodings. Some of
these encodings will not respond to to_str. If method_missing is
redefined on Object, then it will call method_missing and attempt raise
an error. However, the iseq is invalid as it's a dummy frame so it will
write an invalid iseq to the created NoMethodError.

The following script crashes:

```
GC.stress = true

class Object
  public :method_missing
end

File.write("/tmp/empty.rb", "")
require "/tmp/empty.rb"
```

With the following backtrace:

```
frame #0: 0x00000001000fa8b8 miniruby`RVALUE_MARKED(obj=4308637824) at gc.c:1638:12
frame #1: 0x00000001000fb440 miniruby`RVALUE_BLACK_P(obj=4308637824) at gc.c:1763:12
frame #2: 0x00000001000facdc miniruby`gc_writebarrier_incremental(a=4308637824, b=4308332208, objspace=0x000000010180b000) at gc.c:8822:9
frame #3: 0x00000001000faad8 miniruby`rb_gc_writebarrier(a=4308637824, b=4308332208) at gc.c:8864:17
frame #4: 0x000000010016aff0 miniruby`rb_obj_written(a=4308637824, oldv=36, b=4308332208, filename="../iseq.c", line=1279) at gc.h:804:9
frame #5: 0x0000000100162a60 miniruby`rb_obj_write(a=4308637824, slot=0x0000000100d09888, b=4308332208, filename="../iseq.c", line=1279) at gc.h:837:5
frame #6: 0x0000000100165b0c miniruby`iseqw_new(iseq=0x0000000100d09880) at iseq.c:1279:9
frame #7: 0x0000000100165a64 miniruby`rb_iseqw_new(iseq=0x0000000100d09880) at iseq.c:1289:12
frame #8: 0x00000001000d8324 miniruby`name_err_init_attr(exc=4309777920, recv=4304780496, method=827660) at error.c:1830:35
frame #9: 0x00000001000d1b80 miniruby`name_err_init(exc=4309777920, mesg=4308332496, recv=4304780496, method=827660) at error.c:1869:12
frame #10: 0x00000001000d1bd4 miniruby`rb_nomethod_err_new(mesg=4308332496, recv=4304780496, method=827660, args=4308332448, priv=0) at error.c:1957:5
frame #11: 0x000000010039049c miniruby`rb_make_no_method_exception(exc=4304914512, format=4308332496, obj=4304780496, argc=1, argv=0x000000016fdfab00, priv=0) at vm_eval.c:959:16
frame #12: 0x00000001003b3274 miniruby`raise_method_missing(ec=0x0000000100b06f40, argc=1, argv=0x000000016fdfab00, obj=4304780496, last_call_status=MISSING_NOENTRY) at vm_eval.c:999:15
frame #13: 0x00000001003945d4 miniruby`rb_method_missing(argc=1, argv=0x000000016fdfab00, obj=4304780496) at vm_eval.c:944:5
...
frame #23: 0x000000010038f5e4 miniruby`rb_vm_call_kw(ec=0x0000000100b06f40, recv=4304780496, id=2865, argc=1, argv=0x000000016fdfab00, me=0x0000000100cbfcf0, kw_splat=0) at vm_eval.c:326:12
frame #24: 0x00000001003c18e4 miniruby`call_method_entry(ec=0x0000000100b06f40, defined_class=4304927952, obj=4304780496, id=2865, cme=0x0000000100cbfcf0, argc=1, argv=0x000000016fdfab00, kw_splat=0) at vm_method.c:2720:20
frame #25: 0x00000001003c440c miniruby`check_funcall_exec(v=6171896792) at vm_eval.c:589:12
frame #26: 0x00000001000dec00 miniruby`rb_vrescue2(b_proc=(miniruby`check_funcall_exec at vm_eval.c:587), data1=6171896792, r_proc=(miniruby`check_funcall_failed at vm_eval.c:596), data2=6171896792, args="Pȗ") at eval.c:919:18
frame #27: 0x00000001000deab0 miniruby`rb_rescue2(b_proc=(miniruby`check_funcall_exec at vm_eval.c:587), data1=6171896792, r_proc=(miniruby`check_funcall_failed at vm_eval.c:596), data2=6171896792) at eval.c:900:17
frame #28: 0x000000010039008c miniruby`check_funcall_missing(ec=0x0000000100b06f40, klass=4304923536, recv=4304780496, mid=3233, argc=0, argv=0x0000000000000000, respond=-1, def=36, kw_splat=0) at vm_eval.c:666:15
frame #29: 0x000000010038fa60 miniruby`rb_check_funcall_default_kw(recv=4304780496, mid=3233, argc=0, argv=0x0000000000000000, def=36, kw_splat=0) at vm_eval.c:703:21
frame #30: 0x000000010038fb04 miniruby`rb_check_funcall(recv=4304780496, mid=3233, argc=0, argv=0x0000000000000000) at vm_eval.c:685:12
frame #31: 0x00000001001c469c miniruby`convert_type_with_id(val=4304780496, tname="String", method=3233, raise=0, index=-1) at object.c:3061:15
frame #32: 0x00000001001c4a4c miniruby`rb_check_convert_type_with_id(val=4304780496, type=5, tname="String", method=3233) at object.c:3153:9
frame #33: 0x00000001002d59f8 miniruby`rb_check_string_type(str=4304780496) at string.c:2571:11
frame #34: 0x000000010014b7b0 miniruby`io_encoding_set(fptr=0x0000000100d09ca0, v1=4304780496, v2=4, opt=4) at io.c:11655:19
frame #35: 0x0000000100139a58 miniruby`rb_io_set_encoding(argc=1, argv=0x000000016fdfb450, io=4308334032) at io.c:13497:5
frame #36: 0x00000001003c0004 miniruby`ractor_safe_call_cfunc_m1(recv=4308334032, argc=1, argv=0x000000016fdfb450, func=(miniruby`rb_io_set_encoding at io.c:13487)) at vm_insnhelper.c:3271:12
...
frame #43: 0x0000000100390b08 miniruby`rb_funcall(recv=4308334032, mid=16593, n=1) at vm_eval.c:1137:12
frame #44: 0x00000001002a43d8 miniruby`load_file_internal(argp_v=6171899936) at ruby.c:2500:5
...
```
2023-08-02 09:08:12 -04:00
Nobuyoshi Nakada
0622c78869
[DOC] Update warning categories
- Fix indentations of labeled lists.
- Mention performance category.
2023-08-01 14:54:16 +09:00
Nobuyoshi Nakada
e3385f8783
[Bug #19635] Preserve errno
The following functions are turned into macros and no longer can be
used as expressions in core.
- rb_sys_fail
- rb_sys_fail_str
- rb_sys_fail_path
2023-05-12 18:36:01 +09:00
Jean Boussier
6a5c355e4e Add RB_WARN_CATEGORY_DEFAULT_BITS
Followup: ac123f167a364c3d7a43eca78d564e41f6dbb91e

RB_WARN_CATEGORY_ALL_BITS is exposed in a public header, so it
makes sense for it to be updated to contain all valid bits.

Instead we introduce RB_WARN_CATEGORY_DEFAULT_BITS to list the
categories that are enabled by default.
2023-04-14 09:46:10 +02:00
Jean Boussier
ac123f167a Emit a performance warning when a class reached max variations
[Feature #19538]

This new `peformance` warning category is disabled by default.
It needs to be specifically enabled via `-W:performance` or `Warning[:performance] = true`
2023-04-13 16:36:17 +02:00
Nobuyoshi Nakada
de023b68aa Disable all warning categories other than RB_WARN_CATEGORY_ALL_BITS 2023-04-13 18:08:08 +09:00
Takashi Kokubun
233ddfac54 Stop exporting symbols for MJIT 2023-03-06 21:59:23 -08:00
Nobuyoshi Nakada
b326a5f3dd
Adjust indent [ci skip] 2023-02-20 10:50:49 +09:00
Yusuke Endoh
7d5794bad5 error.c: Use "undefined local variable or method `...' for main"
... for the toplevel.
2023-02-20 10:33:06 +09:00
Yusuke Endoh
1fd181b453 error.c: Update the message format for NoMethodError
* If the receiver is a Class, use "... for class <class name>".
* If the receiver is a Module, use "... for module <module name>".
* If the receiver is an extended object (i.e., has a singleton class),
  use "... for <rb_any_to_s(receiver)>".
* Otherwise, use "... for an instance of <class name>".

Examples:

```
42.time    #=> undefined method `time' for an instance of Integer (NoMethodError)

class Foo
  privatee #=> undefined local variable or method 'privatee' for class Foo (NoMethodError)
end

def (o=Object.new).foo
end
o.bar      #=> undefined method `bar' for #<Object: 0xdeadbeef(any_to_s)> (NoMethodError)
```
2023-02-20 10:33:06 +09:00
Yusuke Endoh
e7b8d32e16 Stop using receiver#inspect for "undefined method" errors
```
42.time    #=> undefined method `time' for object Integer (NoMethodError)

class Foo
  privatee #=> undefined local variable or method 'privatee' for class Foo (NoMethodError)
end

s = ""
def s.foo = nil
s.bar      #=> undefined method `bar' for extended object String (NoMethodError)
```

[Feature #18285]
2023-02-20 10:33:06 +09:00
zverok
91076b2c59 Docs: Fix rendering of SyntaxError#path 2022-12-23 18:09:49 +02:00
Nobuyoshi Nakada
2e7e153a2a [Bug #19242] Prohibit circular causes to be loaded 2022-12-20 14:12:38 +09:00
Samuel Williams
6fd5d2dc00
Introduce IO.new(..., path:) and promote File#path to IO#path. (#6867) 2022-12-08 18:19:53 +13:00
S-H-GAMELINKS
040e0c8d67 Reuse NIL_OR_UNDEF_P macro 2022-12-02 01:19:55 +09:00
Nobuyoshi Nakada
4e68b59431 [Feature #19138] Add SyntaxError#path 2022-12-01 17:05:41 +09:00
S-H-GAMELINKS
1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Sergey Fedorov
567725ed30
Fix and improve coroutines for Darwin (macOS) ppc/ppc64. (#5975) 2022-10-19 23:49:45 +13:00
Nobuyoshi Nakada
f08fcd0e80
Fix possible use of undefined macros on very old macOS [ci skip] 2022-10-17 18:36:08 +09:00
S.H
f1c89c8147
Reuse with_warning_string_from macro 2022-10-10 13:52:25 +09:00
Nobuyoshi Nakada
e294e6f417
Split with_warning_string_from for the last named parameter 2022-09-30 17:29:23 +09:00
Yusuke Endoh
a78c733cc3 Revert "Revert "error.c: Let Exception#inspect inspect its message""
This reverts commit b9f030954a8a1572032f3548b39c5b8ac35792ce.

[Bug #18170]
2022-09-23 16:40:59 +09:00
卜部昌平
104069e75a syserr_initialize: delete redundant strerror() declaration
This line issues a warning on clang.  strerror is of course a part of
ISO C since its dawn.  We practically have never needed it.
2022-09-21 11:44:09 +09:00
S-H-GAMELINKS
77fdb3a47d Introduce with_warn_vsprintf macro 2022-08-12 16:59:30 +09:00
Takashi Kokubun
5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Yusuke Endoh
c4e2973733 Fix a typo (thanks @Maumagnaguagno !) 2022-07-13 16:09:11 +09:00
Yusuke Endoh
1fe6c92603 Specify usable escape sequences in Exception#detailed_message
An error message is primarily rendered in a terminal emulator, but is
also shown in a browser by converting it to a HTML fragment.
However, the conversion would be unreasonably difficult if the message
includes any escape sequence (such as cursor move or screen clear).

This change adds a guideline about escape sequences in
`Exception#detailed_message`:

* Use widely-supported escape sequences: bold, underline, and basic
  eight foreground colors (except white and black).
* Make the message readable if all escape sequences are ignored.
2022-07-13 16:09:11 +09:00
Chris Seaton
31b2cd38c5 Include JIT information in crash reports
Since enabling YJIT or MJIT drastically changes what could go wrong at
runtime, it's good to be front and center about whether they are enabled
when dumping a crash report. Previously, `RUBY_DESCRIPTION` and the
description printed when crashing can be different when a JIT is on.

Introduce a new internal data global, `rb_dynamic_description`, and set
it to be the same as `RUBY_DESCRIPTION` during initialization; use it
when crashing.

 * version.c: Init_ruby_description(): Initialize and use
       `rb_dynamic_description`.
 * error.c: Change crash reports to use `rb_dynamic_description`.
 * ruby.c: Call `Init_ruby_description()` earlier. Slightly more work
       for when we exit right after printing the description but that
       was deemed acceptable.
 * include/ruby/version.h: Talk about how JIT info is not in
      `ruby_description`.
 * test/-ext-/bug_reporter/test_bug_reporter.rb: Remove handling for
       crash description being different from `RUBY_DESCRIPTION`.
 * test/ruby/test_rubyoptions.rb: ditto

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Alan Wu <alanwu@ruby-lang.org>
2022-06-20 17:18:29 -04:00
Nobuyoshi Nakada
a58611dfb1 Allow to just warn as bool expected, without an exception 2022-06-20 19:35:12 +09:00
Nobuyoshi Nakada
ccfbcc7302
[DOC] RDoc now accepts other than magic numbers at rb_attr 2022-06-08 11:55:21 +09:00
Yusuke Endoh
b9f030954a Revert "error.c: Let Exception#inspect inspect its message"
This reverts commit 9d927204e7b86eb00bfd07a060a6383139edf741.
2022-06-07 11:52:44 +09:00
Yusuke Endoh
9d927204e7 error.c: Let Exception#inspect inspect its message
... only when the message string has a newline.

`p StandardError.new("foo\nbar")` now prints `#<StandardError: "foo\nbar">'
instead of:

    #<StandardError:
    bar>

[Bug #18170]
2022-06-07 11:07:09 +09:00
Nobuyoshi Nakada
ed2dd17294
Use RBOOL 2022-06-05 14:21:01 +09:00
Nobuyoshi Nakada
7e52533104
No fallback to default values 2022-05-21 22:58:45 +09:00
Yusuke Endoh
25b0577c92 Factor a "highlight" symbol out 2022-02-22 11:55:40 +09:00
Yusuke Endoh
4db986431a Let Exception#full_message pass highlight keywords to #detailed_message
.. even when the argument is not explicitly passed.
2022-02-22 11:55:40 +09:00
Yusuke Endoh
98ca99cdd0 The default highlight arguments of Exception#detailed_message is false 2022-02-22 11:55:40 +09:00
Yusuke Endoh
35ff545bb6 Exception#detailed_message is added
Also, the default error printer and Exception#full_message use the
method instead of `Exception#message` to get the message string.

`Exception#detailed_message` calls `Exception#message`, decorates and
returns the result. It adds some escape sequences to highlight, and the
class name of the exception to the end of the first line of the message.

[Feature #18370]
2022-02-22 11:55:40 +09:00
Yusuke Endoh
36e31b09cd error.c: Refactoring
Factor out from rb_error_write the responsibility to check if stderr is
a tty.
2022-02-22 11:55:40 +09:00
Jeremy Evans
9e0a91d064 Don't segfault if Warning.warn is undefined
Check that there is a method entry for the method before passing
it to rb_method_entry_arity.

Fixes [Bug #18458]
2022-01-04 10:03:18 -08:00
Nobuyoshi Nakada
39bc5de833
Remove tainted and trusted features
Already these had been announced to be removed in 3.2.
2021-12-26 23:28:54 +09:00
S.H
75aae66c4f
Some codes replace to RBOOL macro (#5023)
* Some code replace and using RBOOL macro

* Fix indent

* Using RBOOL in syserr_eqq function
2021-11-09 17:09:29 +09:00
S.H
a46c220320
Add rb_mod_exc_raise function and replace duplicate code 2021-10-30 19:24:41 +09:00
S.H
dc9112cf10
Using NIL_P macro instead of == Qnil 2021-10-03 22:34:45 +09:00
S.H
b8c3a84bdd
Refactor and Using RBOOL macro 2021-09-15 08:11:05 +09:00
卜部昌平
dddc618d30 suppress GCC's -Wsuggest-attribute=format
I was not aware of this because I use clang these days.
2021-09-10 20:00:06 +09:00
卜部昌平
1b6245ccdc include/ruby/internal/error.h: add doxygen
Must not be a bad idea to improve documents.
2021-09-10 20:00:06 +09:00
Kazuki Tsujimoto
4568ba0711
Show verbose error messages when single pattern match fails
[0] => [0, *, a]
    #=> [0] length mismatch (given 1, expected 2+) (NoMatchingPatternError)

Ignore test failures of typeprof caused by this change for now.
2021-08-15 09:38:24 +09:00
Nobuyoshi Nakada
97efd48fb1
Get rid of unintented recursion when RUBY_DEBUG 2021-08-14 23:12:31 +09:00
Nobuyoshi Nakada
1bd021a789 Mark internal class names 2021-08-14 23:11:58 +09:00