Skip to content
Browse files

* 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
  • Loading branch information...
1 parent 77e98ee commit f1a5c1cf0e0bb3544ee8bbfc8b1a780577cc4629 matz committed May 2, 2003
Showing with 18 additions and 5 deletions.
  1. +5 −0 ChangeLog
  2. +13 −5 compar.c
View
5 ChangeLog
@@ -1,3 +1,8 @@
+Fri May 2 18:17:37 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * compar.c (cmp_gt): raises ArgumentError when "<=>" give nil.
+ inspired by discussion on comp.lang.python.
+
Fri May 2 17:37:01 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/cgi/session.rb (CGI::Session::initialize): updated to
View
18 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;
}

0 comments on commit f1a5c1c

Please sign in to comment.
Something went wrong with that request. Please try again.