[#41916] Proposal: Bitmap Marking GC — Narihiro Nakamura <authornari@...>

Hi.

18 messages 2012/01/05

[#41941] [ruby-trunk - Bug #5851][Open] make check fails when compiling with GCC 4.7 - *** longjmp causes uninitialized stack frame *** — Vit Ondruch <v.ondruch@...>

12 messages 2012/01/06

[#41979] [ruby-trunk - Bug #5865][Open] Exception#== should return false if the classes differ — Hiro Asari <asari.ruby@...>

10 messages 2012/01/08

[#42003] [ruby-trunk - Bug #5871][Open] regexp \W matches some word characters when inside a case-insensitive character class — Gareth Adams <gareth@...>

14 messages 2012/01/09

[#42016] [ruby-trunk - Feature #5873][Open] Adopt FFI over DL — Heesob Park <phasis@...>

15 messages 2012/01/10

[#42149] [ruby-trunk - Feature #5899][Open] chaining comparsions. — Ondrej Bilka <neleai@...>

12 messages 2012/01/16

[#42164] [ruby-trunk - Feature #5903][Open] Optimize st_table (take 2) — Yura Sokolov <funny.falcon@...>

18 messages 2012/01/17

[ruby-core:42017] Re: [ruby-trunk - Bug #5865] Exception#== should return false if the classes differ

From: Nobuyoshi Nakada <nobu@...>
Date: 2012-01-10 02:34:25 UTC
List: ruby-core #42017
Hi,

(12/01/09 22:02), Nikolai Weibull wrote:
> The fix should be to also check the #class of obj against the #class
> of exc, not to simply ignore it if the rb_obj_class()es don’t match.
> I’ve attached a patch.

Fixnum#== works fine with Delegator because of implicit conversion, so
I think Exception should also use same way.


diff --git a/error.c b/error.c
index 6844f99..7185d52 100644
--- a/error.c
+++ b/error.c
@@ -732,10 +732,14 @@ exc_equal(VALUE exc, VALUE obj)
     CONST_ID(id_mesg, "mesg");
 
     if (rb_obj_class(exc) != rb_obj_class(obj)) {
-	ID id_message, id_backtrace;
+	ID id_message, id_backtrace, id_exception;
 	CONST_ID(id_message, "message");
 	CONST_ID(id_backtrace, "backtrace");
+	CONST_ID(id_exception, "exception");
 
+	obj = rb_check_funcall(obj, id_exception, 0, 0);
+	if (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 028391d..7226fe2 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -380,4 +380,9 @@ end.join
       load(t.path)
     end
   end
+
+  def test_equal
+    assert_equal(RuntimeError.new("a"), RuntimeError.new("a"))
+    assert_not_equal(RuntimeError.new("a"), StandardError.new("a"))
+  end
 end


-- 
Nobu Nakada

In This Thread