summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'array.c')
-rw-r--r--array.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/array.c b/array.c
index 79131901e3..0dfa3aef40 100644
--- a/array.c
+++ b/array.c
@@ -1004,12 +1004,26 @@ rb_ary_reverse_m(ary)
return rb_ary_reverse(rb_ary_dup(ary));
}
+int
+rb_cmpint(cmp)
+ VALUE cmp;
+{
+ if (FIXNUM_P(cmp)) return NUM2LONG(cmp);
+ if (TYPE(cmp) == T_BIGNUM) {
+ if (RBIGNUM(cmp)->sign) return 1;
+ return -1;
+ }
+ if (rb_funcall(cmp, '>', 1, INT2FIX(0))) return 1;
+ if (rb_funcall(cmp, '<', 1, INT2FIX(0))) return -1;
+ return 0;
+}
+
static int
sort_1(a, b)
VALUE *a, *b;
{
VALUE retval = rb_yield(rb_assoc_new(*a, *b));
- return NUM2INT(retval);
+ return rb_cmpint(retval);
}
static int
@@ -1026,7 +1040,7 @@ sort_2(a, b)
}
retval = rb_funcall(*a, cmp, 1, *b);
- return NUM2INT(retval);
+ return rb_cmpint(retval);
}
static VALUE