[前][次][番号順一覧][スレッド一覧]

ruby-changes:22250

From: nobu <ko1@a...>
Date: Sat, 14 Jan 2012 12:00:38 +0900 (JST)
Subject: [ruby-changes:22250] nobu:r34299 (trunk): * error.c (exc_equal): ignore exceptions during implicit

nobu	2012-01-14 12:00:24 +0900 (Sat, 14 Jan 2012)

  New Revision: 34299

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34299

  Log:
    * error.c (exc_equal): ignore exceptions during implicit
      conversion.  [ruby-core:41979] [Bug #5865]

  Modified files:
    trunk/ChangeLog
    trunk/error.c
    trunk/test/ruby/test_exception.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34298)
+++ ChangeLog	(revision 34299)
@@ -1,3 +1,8 @@
+Sat Jan 14 12:00:20 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* error.c (exc_equal): ignore exceptions during implicit
+	  conversion.  [ruby-core:41979] [Bug #5865]
+
 Sat Jan 14 05:58:54 2012  Eric Hodel  <drbrain@s...>
 
 	* io.c (rb_io_s_read):  Fix formatting of open_args comment.  Reported
@@ -18,6 +23,11 @@
 
 	* load.c (load_unlock): update loading table at once.
 
+Fri Jan 13 16:44:45 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* error.c (exc_equal): try implicit conversion for delegator.
+	  [ruby-core:41979] [Bug #5865]
+
 Fri Jan 13 03:46:53 2012  Akinori MUSHA  <knu@i...>
 
 	* lib/shellwords.rb (Shellwords#shellescape): shellescape() now
Index: error.c
===================================================================
--- error.c	(revision 34298)
+++ error.c	(revision 34299)
@@ -713,6 +713,14 @@
     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 @@
     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);
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 34298)
+++ test/ruby/test_exception.rb	(revision 34299)
@@ -380,4 +380,10 @@
       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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]