* 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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2014-01-05 11:14:59 +00:00
Родитель 306c154c2d
Коммит d781caaf31
5 изменённых файлов: 27 добавлений и 28 удалений

Просмотреть файл

@ -1,3 +1,15 @@
Sun Jan 5 20:14:14 2014 Benoit Daloze <eregontp@gmail.com>
* 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@ruby-lang.org>
* struct.c (rb_struct_set): return assigned value from setter method

Просмотреть файл

@ -58,22 +58,6 @@ cmp_eq_recursive(VALUE arg1, VALUE arg2, int recursive)
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)
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;
}
/*

Просмотреть файл

@ -115,7 +115,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
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::CodeObject
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)

Просмотреть файл

@ -15,8 +15,8 @@ class TestRDocNormalClass < XrefTestCase
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
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

Просмотреть файл

@ -17,8 +17,9 @@ class TestComparable < Test::Unit::TestCase
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