Skip to content

Commit

Permalink
* error.c (exc_equal): clear rb_thread_t::errinfo when ignore
Browse files Browse the repository at this point in the history
  an exception under rb_protect(). [ruby-core:41979] [Bug ruby#5865]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nagachika committed Jan 14, 2012
1 parent c53470f commit 15e1ff7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Sat Jan 14 18:24:13 2012 CHIKANAGA Tomoyuki <[email protected]>

* error.c (exc_equal): clear rb_thread_t::errinfo when ignore
an exception under rb_protect(). [ruby-core:41979] [Bug #5865]

Sat Jan 14 12:02:55 2012 Nobuyoshi Nakada <[email protected]>

* sprintf.c (rb_enc_vsprintf): relaxed the restriction. since the
Expand Down
5 changes: 4 additions & 1 deletion error.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,10 @@ exc_equal(VALUE exc, VALUE obj)
CONST_ID(id_backtrace, "backtrace");

obj = rb_protect(try_convert_to_exception, obj, &status);
if (status || obj == Qundef) return Qfalse;
if (status || obj == Qundef) {
rb_set_errinfo(Qnil);
return Qfalse;
}
if (rb_obj_class(exc) != rb_obj_class(obj)) return Qfalse;
mesg = rb_check_funcall(obj, id_message, 0, 0);
if (mesg == Qundef) return Qfalse;
Expand Down
19 changes: 19 additions & 0 deletions test/ruby/test_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,30 @@ def test_exception_in_name_error_to_str
assert_nothing_raised(NameError, bug5575) do
load(t.path)
end
ensure
t.close(true) if t
end

def test_equal
bug5865 = '[ruby-core:41979]'
assert_equal(RuntimeError.new("a"), RuntimeError.new("a"), bug5865)
assert_not_equal(RuntimeError.new("a"), StandardError.new("a"), bug5865)
end

def test_exception_in_exception_equal
bug5865 = '[ruby-core:41979]'
t = Tempfile.new(["test_exception_in_exception_equal", ".rb"])
t.puts <<-EOC
o = Object.new
def o.exception(arg)
end
RuntimeError.new("a") == o
EOC
t.close
assert_nothing_raised(ArgumentError, bug5865) do
load(t.path)
end
ensure
t.close(true) if t
end
end

0 comments on commit 15e1ff7

Please sign in to comment.