summaryrefslogtreecommitdiff
path: root/compar.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-05-21 05:39:19 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-05-21 05:39:19 +0000
commitedbe98d848e4872654bb5273a6a8250492026c18 (patch)
tree9d9e68c491b333a85b01f36f74935e98f873b043 /compar.c
parent9402cbeec54f5a4de56588a1b980f53e5d50c04e (diff)
* object.c (Init_Object): should do exact match for Module#==.
* compar.c (cmp_eq): returns 'false' if <=> returns 'nil'. * compar.c (cmp_gt,cmp_ge,cmp_lt,cmp_le,cmp_between): ditto. * pack.c (pack_pack): should propagate taintedness. * pack.c (pack_unpack): ditto. * eval.c (rb_thread_schedule): need to preserve errno before calling rb_trap_exec(). * regex.c (calculate_must_string): a bug in charset/charset_not parsing. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compar.c')
-rw-r--r--compar.c51
1 files changed, 17 insertions, 34 deletions
diff --git a/compar.c b/compar.c
index 371459f348..43e31693f3 100644
--- a/compar.c
+++ b/compar.c
@@ -17,32 +17,14 @@ VALUE rb_mComparable;
static ID cmp;
static VALUE
-cmp_eq(a)
- VALUE *a;
-{
- VALUE c = rb_funcall(a[0], cmp, 1, a[1]);
- int t = NUM2INT(c);
-
- if (t == 0) return Qtrue;
- return Qfalse;
-}
-
-static VALUE
-cmp_failed()
-{
- return Qfalse;
-}
-
-static VALUE
cmp_equal(x, y)
VALUE x, y;
{
- VALUE a[2];
-
- if (x == y) return Qtrue;
+ VALUE c = rb_funcall(x, cmp, 1, y);
- a[0] = x; a[1] = y;
- return rb_rescue(cmp_eq, (VALUE)a, cmp_failed, 0);
+ if (NIL_P(c)) return Qnil;
+ if (NUM2LONG(c) == 0) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -50,9 +32,9 @@ cmp_gt(x, y)
VALUE x, y;
{
VALUE c = rb_funcall(x, cmp, 1, y);
- int t = NUM2INT(c);
- if (t > 0) return Qtrue;
+ if (NIL_P(c)) return Qfalse;
+ if (NUM2LONG(c) > 0) return Qtrue;
return Qfalse;
}
@@ -61,9 +43,9 @@ cmp_ge(x, y)
VALUE x, y;
{
VALUE c = rb_funcall(x, cmp, 1, y);
- int t = NUM2INT(c);
- if (t >= 0) return Qtrue;
+ if (NIL_P(c)) return Qfalse;
+ if (NUM2LONG(c) >= 0) return Qtrue;
return Qfalse;
}
@@ -72,9 +54,9 @@ cmp_lt(x, y)
VALUE x, y;
{
VALUE c = rb_funcall(x, cmp, 1, y);
- int t = NUM2INT(c);
- if (t < 0) return Qtrue;
+ if (NIL_P(c)) return Qfalse;
+ if (NUM2LONG(c) < 0) return Qtrue;
return Qfalse;
}
@@ -83,9 +65,9 @@ cmp_le(x, y)
VALUE x, y;
{
VALUE c = rb_funcall(x, cmp, 1, y);
- int t = NUM2INT(c);
- if (t <= 0) return Qtrue;
+ if (NIL_P(c)) return Qfalse;
+ if (NUM2LONG(c) <= 0) return Qtrue;
return Qfalse;
}
@@ -94,12 +76,13 @@ cmp_between(x, min, max)
VALUE x, min, max;
{
VALUE c = rb_funcall(x, cmp, 1, min);
- long t = NUM2LONG(c);
- if (t < 0) return Qfalse;
+
+ if (NIL_P(c)) return Qfalse;
+ if (NUM2LONG(c) < 0) return Qfalse;
c = rb_funcall(x, cmp, 1, max);
- t = NUM2LONG(c);
- if (t > 0) return Qfalse;
+ if (NIL_P(c)) return Qfalse;
+ if (NUM2LONG(c) > 0) return Qfalse;
return Qtrue;
}