summaryrefslogtreecommitdiff
path: root/compar.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-17 11:55:50 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-17 11:55:50 (GMT)
commit44c5c2a3120439af7560f9694dcb117953ee3119 (patch)
tree01373760110357e230e5aa20914bbf8479b5db4f /compar.c
parentc9283b5c5dd1253bbfa340b34e40dcd57da377db (diff)
compar.c: inversed comarison without infinite recursion
* compar.c (rb_invcmp): compare by inversed comarison, with preventing from infinite recursion. [ruby-core:52305] [Bug #7870] * string.c (rb_str_cmp_m), time.c (time_cmp): get rid of infinite recursion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compar.c')
-rw-r--r--compar.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/compar.c b/compar.c
index 6762786..c89c752 100644
--- a/compar.c
+++ b/compar.c
@@ -32,6 +32,26 @@ rb_cmperr(VALUE x, VALUE y)
}
static VALUE
+invcmp_recursive(VALUE x, VALUE y, int recursive)
+{
+ if (recursive) return Qnil;
+ return rb_check_funcall(y, cmp, 1, &x);
+}
+
+VALUE
+rb_invcmp(VALUE x, VALUE y)
+{
+ VALUE invcmp = rb_exec_recursive(invcmp_recursive, x, y);
+ if (invcmp == Qundef || NIL_P(invcmp)) {
+ return Qnil;
+ }
+ else {
+ int result = -rb_cmpint(invcmp, x, y);
+ return INT2FIX(result);
+ }
+}
+
+static VALUE
cmp_eq(VALUE *a)
{
VALUE c = rb_funcall(a[0], cmp, 1, a[1]);