aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-14 03:00:24 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-14 03:00:24 +0000
commitf2aa0fd5d4ffa77a5c4bdd8698ac774b20540c62 (patch)
tree90fbd37e3bd6022c3c77a9a95b62b5025ace6b62
parent1648e9442dd4a6824bef16f7a45e8cc927aef4f5 (diff)
downloadruby-f2aa0fd5d4ffa77a5c4bdd8698ac774b20540c62.tar.gz
* error.c (exc_equal): ignore exceptions during implicit
conversion. [ruby-core:41979] [Bug #5865] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--error.c12
-rw-r--r--test/ruby/test_exception.rb6
3 files changed, 28 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 7081133d80..3ef5b9d21f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Jan 14 12:00:20 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * error.c (exc_equal): ignore exceptions during implicit
+ conversion. [ruby-core:41979] [Bug #5865]
+
Sat Jan 14 05:58:54 2012 Eric Hodel <drbrain@segment7.net>
* io.c (rb_io_s_read): Fix formatting of open_args comment. Reported
@@ -18,6 +23,11 @@ Fri Jan 13 17:23:38 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* load.c (load_unlock): update loading table at once.
+Fri Jan 13 16:44:45 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * error.c (exc_equal): try implicit conversion for delegator.
+ [ruby-core:41979] [Bug #5865]
+
Fri Jan 13 03:46:53 2012 Akinori MUSHA <knu@iDaemons.org>
* lib/shellwords.rb (Shellwords#shellescape): shellescape() now
diff --git a/error.c b/error.c
index 6844f992a6..3b80a24bdd 100644
--- a/error.c
+++ b/error.c
@@ -713,6 +713,14 @@ exc_set_backtrace(VALUE exc, VALUE bt)
return rb_iv_set(exc, "bt", rb_check_backtrace(bt));
}
+static VALUE
+try_convert_to_exception(VALUE obj)
+{
+ ID id_exception;
+ CONST_ID(id_exception, "exception");
+ return rb_check_funcall(obj, id_exception, 0, 0);
+}
+
/*
* call-seq:
* exc == obj -> true or false
@@ -732,10 +740,14 @@ exc_equal(VALUE exc, VALUE obj)
CONST_ID(id_mesg, "mesg");
if (rb_obj_class(exc) != rb_obj_class(obj)) {
+ int status = 0;
ID id_message, id_backtrace;
CONST_ID(id_message, "message");
CONST_ID(id_backtrace, "backtrace");
+ obj = rb_protect(try_convert_to_exception, obj, &status);
+ if (status || obj == Qundef) 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;
backtrace = rb_check_funcall(obj, id_backtrace, 0, 0);
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 028391d1e6..22ac2aca1f 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -380,4 +380,10 @@ end.join
load(t.path)
end
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
end