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

ruby-changes:37489

From: eregon <ko1@a...>
Date: Thu, 12 Feb 2015 04:34:11 +0900 (JST)
Subject: [ruby-changes:37489] eregon:r49570 (trunk): * compar.c (cmp_equal): no more error hiding for Comparable#==.

eregon	2015-02-12 04:33:46 +0900 (Thu, 12 Feb 2015)

  New Revision: 49570

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

  Log:
    * compar.c (cmp_equal): no more error hiding for Comparable#==.
      It now behaves as other Comparable methods. See #7688.
    * test/ruby/test_comparable.rb: update related test.

  Modified files:
    trunk/ChangeLog
    trunk/compar.c
    trunk/test/ruby/test_comparable.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49569)
+++ ChangeLog	(revision 49570)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Feb 12 04:33:02 2015  Benoit Daloze  <eregontp@g...>
+
+	* compar.c (cmp_equal): no more error hiding for Comparable#==.
+	  It now behaves as other Comparable methods. See #7688.
+
+	* test/ruby/test_comparable.rb: update related test.
+
 Thu Feb 12 03:28:05 2015  Eric Wong  <e@8...>
 
 	* lib/set.rb (initialize): internal hash defaults to false
Index: compar.c
===================================================================
--- compar.c	(revision 49569)
+++ compar.c	(revision 49570)
@@ -57,24 +57,6 @@ cmp_eq_recursive(VALUE arg1, VALUE arg2, https://github.com/ruby/ruby/blob/trunk/compar.c#L57
     return rb_funcallv(arg1, cmp, 1, &arg2);
 }
 
-static VALUE
-cmp_eq(VALUE *a)
-{
-    VALUE c = rb_exec_recursive_paired_outer(cmp_eq_recursive, a[0], a[1], a[1]);
-
-    if (NIL_P(c)) return Qfalse;
-    if (rb_cmpint(c, a[0], a[1]) == 0) return Qtrue;
-    return Qfalse;
-}
-
-static VALUE
-cmp_failed(void)
-{
-    rb_warn("Comparable#== will no more rescue exceptions of #<=> in the next release.");
-    rb_warn("Return nil in #<=> if the comparison is inappropriate or avoid such comparison.");
-    return Qfalse;
-}
-
 /*
  *  call-seq:
  *     obj == other    -> true or false
@@ -90,12 +72,14 @@ cmp_failed(void) https://github.com/ruby/ruby/blob/trunk/compar.c#L72
 static VALUE
 cmp_equal(VALUE x, VALUE y)
 {
-    VALUE a[2];
-
+    VALUE c;
     if (x == y) return Qtrue;
 
-    a[0] = x; a[1] = y;
-    return rb_rescue(cmp_eq, (VALUE)a, cmp_failed, 0);
+    c = rb_exec_recursive_paired_outer(cmp_eq_recursive, x, y, y);
+
+    if (NIL_P(c)) return Qfalse;
+    if (rb_cmpint(c, x, y) == 0) return Qtrue;
+    return Qfalse;
 }
 
 /*
Index: test/ruby/test_comparable.rb
===================================================================
--- test/ruby/test_comparable.rb	(revision 49569)
+++ test/ruby/test_comparable.rb	(revision 49570)
@@ -17,12 +17,18 @@ class TestComparable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_comparable.rb#L17
     assert_equal(true, @o == nil)
     cmp->(x) do 1; end
     assert_equal(false, @o == nil)
+    cmp->(x) do nil; end
+    assert_equal(false, @o == nil)
+
     cmp->(x) do raise NotImplementedError, "Not a RuntimeError" end
     assert_raise(NotImplementedError) { @o == nil }
-    bug7688 = '[ruby-core:51389] [Bug #7688]'
-    cmp->(x) do raise StandardError, "A standard error should be rescued"; end
-    warn = /Comparable#== will no more rescue exceptions .+ in the next release/
-    assert_warn(warn, bug7688) { @o == nil }
+
+    bug7688 = 'Comparable#== should not silently rescue' \
+              'any Exception [ruby-core:51389] [Bug #7688]'
+    cmp->(x) do raise StandardError end
+    assert_raise(StandardError, bug7688) { @o == nil }
+    cmp->(x) do "bad value"; end
+    assert_raise(ArgumentError, bug7688) { @o == nil }
   end
 
   def test_gt

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

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