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

ruby-changes:32423

From: eregon <ko1@a...>
Date: Sun, 5 Jan 2014 20:15:09 +0900 (JST)
Subject: [ruby-changes:32423] eregon:r44502 (trunk): * compar.c (cmp_equal): remove error hiding in Comparable#==.

eregon	2014-01-05 20:14:59 +0900 (Sun, 05 Jan 2014)

  New Revision: 44502

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

  Log:
    * compar.c (cmp_equal): remove error hiding in Comparable#==.
      Comparable#== no longer rescues exceptions silently.
      This was the cause of quite a couple bugs. See #7688. [EXPERIMENTAL]
    * test/ruby/test_comparable.rb: adapt assertion to match new behavior.
    * lib/rdoc/method_attr.rb: fix bugs discovered by this change.
    * test/rdoc/test_rdoc_normal_class.rb: fix bugs in tests.

  Modified files:
    trunk/ChangeLog
    trunk/compar.c
    trunk/lib/rdoc/method_attr.rb
    trunk/test/rdoc/test_rdoc_normal_class.rb
    trunk/test/ruby/test_comparable.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44501)
+++ ChangeLog	(revision 44502)
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jan  5 20:14:14 2014  Benoit Daloze  <eregontp@g...>
+
+	* compar.c (cmp_equal): remove error hiding in Comparable#==.
+	  Comparable#== no longer rescues exceptions silently.
+	  This was the cause of quite a couple bugs. See #7688. [EXPERIMENTAL]
+
+	* test/ruby/test_comparable.rb: adapt assertion to match new behavior.
+
+	* lib/rdoc/method_attr.rb: fix bugs discovered by this change.
+
+	* test/rdoc/test_rdoc_normal_class.rb: fix bugs in tests.
+
 Sat Jan  4 22:44:00 2014  Charlie Somerville  <charliesome@r...>
 
 	* struct.c (rb_struct_set): return assigned value from setter method
Index: lib/rdoc/method_attr.rb
===================================================================
--- lib/rdoc/method_attr.rb	(revision 44501)
+++ lib/rdoc/method_attr.rb	(revision 44502)
@@ -115,7 +115,7 @@ class RDoc::MethodAttr < RDoc::CodeObjec https://github.com/ruby/ruby/blob/trunk/lib/rdoc/method_attr.rb#L115
   end
 
   def == other # :nodoc:
-    super or self.class == other.class and full_name == other.full_name
+    equal?(other) or self.class == other.class and full_name == other.full_name
   end
 
   ##
@@ -181,8 +181,8 @@ class RDoc::MethodAttr < RDoc::CodeObjec https://github.com/ruby/ruby/blob/trunk/lib/rdoc/method_attr.rb#L181
       parent != kernel && !searched.include?(kernel)
 
     searched.each do |ancestor|
-      next if parent == ancestor
       next if String === ancestor
+      next if parent == ancestor
 
       other = ancestor.find_method_named('#' << name) ||
               ancestor.find_attribute_named(name)
Index: compar.c
===================================================================
--- compar.c	(revision 44501)
+++ compar.c	(revision 44502)
@@ -58,22 +58,6 @@ 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)
-{
-    return Qfalse;
-}
-
 /*
  *  call-seq:
  *     obj == other    -> true or false
@@ -89,12 +73,14 @@ cmp_failed(void) https://github.com/ruby/ruby/blob/trunk/compar.c#L73
 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 44501)
+++ test/ruby/test_comparable.rb	(revision 44502)
@@ -17,8 +17,9 @@ 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 raise; end
-    assert_equal(false, @o == nil)
+    bug7688 = '[ruby-core:51389] [Bug #7688]'
+    cmp->(x) do raise NotImplementedError; end
+    assert_raise(NotImplementedError, bug7688) { @o == nil }
   end
 
   def test_gt
Index: test/rdoc/test_rdoc_normal_class.rb
===================================================================
--- test/rdoc/test_rdoc_normal_class.rb	(revision 44501)
+++ test/rdoc/test_rdoc_normal_class.rb	(revision 44502)
@@ -15,8 +15,8 @@ class TestRDocNormalClass < XrefTestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_normal_class.rb#L15
 
   def test_ancestors_multilevel
     c1 = @top_level.add_class RDoc::NormalClass, 'Outer'
-    c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1
-    c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2
+    c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1.full_name
+    c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2.full_name
 
     assert_equal [c2, c1, 'Object'], c3.ancestors
   end
@@ -30,8 +30,8 @@ class TestRDocNormalClass < XrefTestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_normal_class.rb#L30
     incl = RDoc::Include.new 'Incl', ''
 
     c1 = @top_level.add_class RDoc::NormalClass, 'Outer'
-    c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1
-    c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2
+    c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1.full_name
+    c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2.full_name
     c3.add_include incl
 
     assert_equal [incl.name, c2], c3.direct_ancestors

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

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