summaryrefslogtreecommitdiffstats
path: root/compar.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-02 09:20:21 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-02 09:20:21 +0000
commitf1a5c1cf0e0bb3544ee8bbfc8b1a780577cc4629 (patch)
tree80595ae9f08a71d682531a40722d9c3152f9e4e0 /compar.c
parent77e98ee776ad6ac4d805711a8e244a8fb8633784 (diff)
downloadruby-f1a5c1cf0e0bb3544ee8bbfc8b1a780577cc4629.tar.gz
ruby-f1a5c1cf0e0bb3544ee8bbfc8b1a780577cc4629.tar.xz
ruby-f1a5c1cf0e0bb3544ee8bbfc8b1a780577cc4629.zip
* compar.c (cmp_gt): raises ArgumentError when "<=>" give nil.
inspired by discussion on comp.lang.python. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3746 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compar.c')
-rw-r--r--compar.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/compar.c b/compar.c
index 42258d59c..0a5a10ee2 100644
--- a/compar.c
+++ b/compar.c
@@ -31,14 +31,22 @@ rb_cmpint(val)
}
static VALUE
+cmperr()
+{
+ rb_raise(rb_eArgError, "comparison failed");
+ return Qnil; /* not reached */
+}
+
+static VALUE
cmp_equal(x, y)
VALUE x, y;
{
int c;
if (x == y) return Qtrue;
+
c = rb_funcall(x, cmp, 1, y);
- if (NIL_P(c)) return Qfalse;
+ if (NIL_P(c)) return Qnil;
if (c == INT2FIX(0)) return Qtrue;
if (rb_cmpint(c) == 0) return Qtrue;
return Qfalse;
@@ -50,7 +58,7 @@ cmp_gt(x, y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
- if (NIL_P(c)) return Qnil;
+ if (NIL_P(c)) return cmperr();
if (rb_cmpint(c) > 0) return Qtrue;
return Qfalse;
}
@@ -61,7 +69,7 @@ cmp_ge(x, y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
- if (NIL_P(c)) return Qnil;
+ if (NIL_P(c)) return cmperr();
if (rb_cmpint(c) >= 0) return Qtrue;
return Qfalse;
}
@@ -72,7 +80,7 @@ cmp_lt(x, y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
- if (NIL_P(c)) return Qnil;
+ if (NIL_P(c)) return cmperr();
if (rb_cmpint(c) < 0) return Qtrue;
return Qfalse;
}
@@ -83,7 +91,7 @@ cmp_le(x, y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
- if (NIL_P(c)) return Qnil;
+ if (NIL_P(c)) return cmperr();
if (rb_cmpint(c) <= 0) return Qtrue;
return Qfalse;
}