summaryrefslogtreecommitdiff
path: root/compar.c
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-18 21:40:58 (GMT)
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-18 21:40:58 (GMT)
commitd1d7f12c89cf683947740727fa37b6ce7fe512d4 (patch)
tree2dca2eef347df8ff5c407d0dfea39b42e8e8b166 /compar.c
parent35bf7276d9f699f039619cd3da14fefb15522e59 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compar.c')
-rw-r--r--compar.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/compar.c b/compar.c
index 8ce5c54..893cde7 100644
--- a/compar.c
+++ b/compar.c
@@ -58,6 +58,24 @@ 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)
+{
+ 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, int recursive)
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);
}
/*