Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

check if an Exception instance has a "mesg" attribute #468

Merged
merged 1 commit into from

2 participants

@tsahara-iij

fix the issue that "Exception.new.inspect" causes SIGSEGV.

Applying the patch, "Exception#inspect" returns the name of the class if an instance was initialized with no "message" argument. This behavior is compatible with CRuby.

% bin/mruby -e 'p Exception.new.inspect'
"Exception: Exception"
% bin/mruby -e 'p Exception.new("a").inspect'
"Exception: a"
% bin/mruby -e 'p RuntimeError.new.inspect'
"RuntimeError: RuntimeError"

% ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-openbsd]
% ruby -e 'p Exception.new.inspect'
"#<Exception: Exception>"
@tsahara-iij tsahara-iij check if an Exception instance has a "mesg" attribute
fix the issue that "Exception.new.inspect" causes SIGSEGV.
7a7f267
@matz matz merged commit 7500229 into mruby:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 12, 2012
  1. @tsahara-iij

    check if an Exception instance has a "mesg" attribute

    tsahara-iij authored
    fix the issue that "Exception.new.inspect" causes SIGSEGV.
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 3 deletions.
  1. +6 −3 src/error.c
  2. +3 −0  test/t/exception.rb
View
9 src/error.c
@@ -134,20 +134,23 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
mrb_str_cat2(mrb, str, ":");
mrb_str_append(mrb, str, line);
mrb_str_cat2(mrb, str, ": ");
- if (RSTRING_LEN(mesg) > 0) {
+ if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
mrb_str_append(mrb, str, mesg);
mrb_str_cat2(mrb, str, " (");
}
mrb_str_cat2(mrb, str, mrb_obj_classname(mrb, exc));
- if (RSTRING_LEN(mesg) > 0) {
+ if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
mrb_str_cat2(mrb, str, ")");
}
}
else {
str = mrb_str_new2(mrb, mrb_obj_classname(mrb, exc));
- if (RSTRING_LEN(mesg) > 0) {
+ if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
mrb_str_cat2(mrb, str, ": ");
mrb_str_append(mrb, str, mesg);
+ } else {
+ mrb_str_cat2(mrb, str, ": ");
+ mrb_str_cat2(mrb, str, mrb_obj_classname(mrb, exc));
}
}
return str;
View
3  test/t/exception.rb
@@ -269,3 +269,6 @@ def exception_test14
a == :ok
end
+assert('Exception#inspect without message') do
+ Exception.new.inspect
+end
Something went wrong with that request. Please try again.