Skip to content

Commit 75371b8

Browse files
committed
Reimplement Exception#message in Ruby
Suppresses the possibility of `mrb_vm_exec()` being called recursively.
1 parent a2e9005 commit 75371b8

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

mrblib/10error.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
class Exception
2+
##
3+
# call-seq:
4+
# exception.message -> string
5+
#
6+
# Returns the result of invoking <code>exception.to_s</code>.
7+
# Normally this returns the exception's message or name.
8+
#
9+
def message
10+
to_s
11+
end
12+
end
13+
114
# ISO 15.2.24
215
class ArgumentError < StandardError
316
end

src/error.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,6 @@ exc_to_s(mrb_state *mrb, mrb_value exc)
136136
return mesg;
137137
}
138138

139-
/*
140-
* call-seq:
141-
* exception.message -> string
142-
*
143-
* Returns the result of invoking <code>exception.to_s</code>.
144-
* Normally this returns the exception's message or name.
145-
*/
146-
147-
static mrb_value
148-
exc_message(mrb_state *mrb, mrb_value exc)
149-
{
150-
return mrb_funcall_id(mrb, exc, MRB_SYM(to_s), 0);
151-
}
152-
153139
/*
154140
* call-seq:
155141
* exception.inspect -> string
@@ -667,7 +653,6 @@ mrb_init_exception(mrb_state *mrb)
667653
mrb_define_method(mrb, exception, "exception", exc_exception, MRB_ARGS_OPT(1));
668654
mrb_define_method(mrb, exception, "initialize", exc_initialize, MRB_ARGS_OPT(1));
669655
mrb_define_method(mrb, exception, "to_s", exc_to_s, MRB_ARGS_NONE());
670-
mrb_define_method(mrb, exception, "message", exc_message, MRB_ARGS_NONE());
671656
mrb_define_method(mrb, exception, "inspect", mrb_exc_inspect, MRB_ARGS_NONE());
672657
mrb_define_method(mrb, exception, "backtrace", mrb_exc_backtrace, MRB_ARGS_NONE());
673658
mrb_define_method(mrb, exception, "set_backtrace", exc_set_backtrace, MRB_ARGS_REQ(1));

0 commit comments

Comments
 (0)