mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
306c154c2d
commit
d781caaf31
5 changed files with 27 additions and 28 deletions
12
ChangeLog
12
ChangeLog
|
@ -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>
|
Sat Jan 4 22:44:00 2014 Charlie Somerville <charliesome@ruby-lang.org>
|
||||||
|
|
||||||
* struct.c (rb_struct_set): return assigned value from setter method
|
* struct.c (rb_struct_set): return assigned value from setter method
|
||||||
|
|
26
compar.c
26
compar.c
|
@ -58,22 +58,6 @@ cmp_eq_recursive(VALUE arg1, VALUE arg2, int recursive)
|
||||||
return rb_funcallv(arg1, cmp, 1, &arg2);
|
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:
|
* call-seq:
|
||||||
* obj == other -> true or false
|
* obj == other -> true or false
|
||||||
|
@ -89,12 +73,14 @@ cmp_failed(void)
|
||||||
static VALUE
|
static VALUE
|
||||||
cmp_equal(VALUE x, VALUE y)
|
cmp_equal(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
VALUE a[2];
|
VALUE c;
|
||||||
|
|
||||||
if (x == y) return Qtrue;
|
if (x == y) return Qtrue;
|
||||||
|
|
||||||
a[0] = x; a[1] = y;
|
c = rb_exec_recursive_paired_outer(cmp_eq_recursive, x, y, y);
|
||||||
return rb_rescue(cmp_eq, (VALUE)a, cmp_failed, 0);
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
def == other # :nodoc:
|
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
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -181,8 +181,8 @@ class RDoc::MethodAttr < RDoc::CodeObject
|
||||||
parent != kernel && !searched.include?(kernel)
|
parent != kernel && !searched.include?(kernel)
|
||||||
|
|
||||||
searched.each do |ancestor|
|
searched.each do |ancestor|
|
||||||
next if parent == ancestor
|
|
||||||
next if String === ancestor
|
next if String === ancestor
|
||||||
|
next if parent == ancestor
|
||||||
|
|
||||||
other = ancestor.find_method_named('#' << name) ||
|
other = ancestor.find_method_named('#' << name) ||
|
||||||
ancestor.find_attribute_named(name)
|
ancestor.find_attribute_named(name)
|
||||||
|
|
|
@ -15,8 +15,8 @@ class TestRDocNormalClass < XrefTestCase
|
||||||
|
|
||||||
def test_ancestors_multilevel
|
def test_ancestors_multilevel
|
||||||
c1 = @top_level.add_class RDoc::NormalClass, 'Outer'
|
c1 = @top_level.add_class RDoc::NormalClass, 'Outer'
|
||||||
c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1
|
c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1.full_name
|
||||||
c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2
|
c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2.full_name
|
||||||
|
|
||||||
assert_equal [c2, c1, 'Object'], c3.ancestors
|
assert_equal [c2, c1, 'Object'], c3.ancestors
|
||||||
end
|
end
|
||||||
|
@ -30,8 +30,8 @@ class TestRDocNormalClass < XrefTestCase
|
||||||
incl = RDoc::Include.new 'Incl', ''
|
incl = RDoc::Include.new 'Incl', ''
|
||||||
|
|
||||||
c1 = @top_level.add_class RDoc::NormalClass, 'Outer'
|
c1 = @top_level.add_class RDoc::NormalClass, 'Outer'
|
||||||
c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1
|
c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1.full_name
|
||||||
c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2
|
c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2.full_name
|
||||||
c3.add_include incl
|
c3.add_include incl
|
||||||
|
|
||||||
assert_equal [incl.name, c2], c3.direct_ancestors
|
assert_equal [incl.name, c2], c3.direct_ancestors
|
||||||
|
|
|
@ -17,8 +17,9 @@ class TestComparable < Test::Unit::TestCase
|
||||||
assert_equal(true, @o == nil)
|
assert_equal(true, @o == nil)
|
||||||
cmp->(x) do 1; end
|
cmp->(x) do 1; end
|
||||||
assert_equal(false, @o == nil)
|
assert_equal(false, @o == nil)
|
||||||
cmp->(x) do raise; end
|
bug7688 = '[ruby-core:51389] [Bug #7688]'
|
||||||
assert_equal(false, @o == nil)
|
cmp->(x) do raise NotImplementedError; end
|
||||||
|
assert_raise(NotImplementedError, bug7688) { @o == nil }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_gt
|
def test_gt
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue