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

ruby-changes:32567

From: eregon <ko1@a...>
Date: Sun, 19 Jan 2014 06:41:04 +0900 (JST)
Subject: [ruby-changes:32567] eregon:r44646 (trunk): * compar.c (cmp_equal): warn for this release and still rescue

eregon	2014-01-19 06:40:58 +0900 (Sun, 19 Jan 2014)

  New Revision: 44646

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

  Log:
    * compar.c (cmp_equal): warn for this release and still rescue
      standard exceptions for a nicer transition. See #7688.
      Partly reverts r44502.
    * test/ruby/test_comparable.rb: adapt assertion to match new behavior.

  Modified files:
    trunk/ChangeLog
    trunk/compar.c
    trunk/test/ruby/test_comparable.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44645)
+++ ChangeLog	(revision 44646)
@@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jan 19 06:38:48 2014  Benoit Daloze  <eregontp@g...>
+
+	* compar.c (cmp_equal): warn for this release and still rescue
+	  standard exceptions for a nicer transition. See #7688.
+	  Partly reverts r44502.
+
+	* test/ruby/test_comparable.rb: adapt assertion to match new behavior.
+
+Sun Jan 19 06:27:18 2014  Benoit Daloze  <eregontp@g...>
+
+	* test/ruby/test_comparable.rb: specify behavior for the different
+	  kind of exceptions rescued (or not) by Comparable#==.
+
 Sat Jan 18 23:12:19 2014  Tanaka Akira  <akr@f...>
 
 	* ext/socket: Avoid unnecessary ppoll/select on Linux.
Index: compar.c
===================================================================
--- compar.c	(revision 44645)
+++ compar.c	(revision 44646)
@@ -58,6 +58,24 @@ cmp_eq_recursive(VALUE arg1, VALUE arg2, https://github.com/ruby/ruby/blob/trunk/compar.c#L58
     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
@@ -73,14 +91,12 @@ cmp_eq_recursive(VALUE arg1, VALUE arg2, https://github.com/ruby/ruby/blob/trunk/compar.c#L91
 static VALUE
 cmp_equal(VALUE x, VALUE y)
 {
-    VALUE c;
-    if (x == y) return Qtrue;
+    VALUE a[2];
 
-    c = rb_exec_recursive_paired_outer(cmp_eq_recursive, x, y, y);
+    if (x == y) return Qtrue;
 
-    if (NIL_P(c)) return Qfalse;
-    if (rb_cmpint(c, x, y) == 0) return Qtrue;
-    return Qfalse;
+    a[0] = x; a[1] = y;
+    return rb_rescue(cmp_eq, (VALUE)a, cmp_failed, 0);
 }
 
 /*
Index: test/ruby/test_comparable.rb
===================================================================
--- test/ruby/test_comparable.rb	(revision 44645)
+++ test/ruby/test_comparable.rb	(revision 44646)
@@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_comparable.rb#L1
 require 'test/unit'
+require_relative 'envutil'
 
 class TestComparable < Test::Unit::TestCase
   def setup
@@ -20,8 +21,9 @@ class TestComparable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_comparable.rb#L21
     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, "Even a standard error should not be rescued"; end
-    assert_raise(StandardError, bug7688) { @o == nil }
+    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 }
   end
 
   def test_gt

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

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