Skip to content
This repository

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

Merged
merged 1 commit into from almost 2 years ago

2 participants

Tomoyuki Sahara Yukihiro "Matz" Matsumoto
Tomoyuki Sahara

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>"
Tomoyuki Sahara tsahara-iij check if an Exception instance has a "mesg" attribute
fix the issue that "Exception.new.inspect" causes SIGSEGV.
7a7f267
Yukihiro "Matz" Matsumoto matz merged commit 7500229 into from
Yukihiro "Matz" Matsumoto matz closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 12, 2012
Tomoyuki Sahara tsahara-iij check if an Exception instance has a "mesg" attribute
fix the issue that "Exception.new.inspect" causes SIGSEGV.
7a7f267
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 9 additions and 3 deletions. Show diff stats Hide diff stats

  1. +6 3 src/error.c
  2. +3 0  test/t/exception.rb
9 src/error.c
@@ -134,20 +134,23 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
134 134 mrb_str_cat2(mrb, str, ":");
135 135 mrb_str_append(mrb, str, line);
136 136 mrb_str_cat2(mrb, str, ": ");
137   - if (RSTRING_LEN(mesg) > 0) {
  137 + if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
138 138 mrb_str_append(mrb, str, mesg);
139 139 mrb_str_cat2(mrb, str, " (");
140 140 }
141 141 mrb_str_cat2(mrb, str, mrb_obj_classname(mrb, exc));
142   - if (RSTRING_LEN(mesg) > 0) {
  142 + if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
143 143 mrb_str_cat2(mrb, str, ")");
144 144 }
145 145 }
146 146 else {
147 147 str = mrb_str_new2(mrb, mrb_obj_classname(mrb, exc));
148   - if (RSTRING_LEN(mesg) > 0) {
  148 + if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
149 149 mrb_str_cat2(mrb, str, ": ");
150 150 mrb_str_append(mrb, str, mesg);
  151 + } else {
  152 + mrb_str_cat2(mrb, str, ": ");
  153 + mrb_str_cat2(mrb, str, mrb_obj_classname(mrb, exc));
151 154 }
152 155 }
153 156 return str;
3  test/t/exception.rb
@@ -269,3 +269,6 @@ def exception_test14
269 269 a == :ok
270 270 end
271 271
  272 +assert('Exception#inspect without message') do
  273 + Exception.new.inspect
  274 +end

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.