1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* compar.c (cmp_gt): raises ArgumentError when "<=>" give nil.

inspired by discussion on comp.lang.python.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3746 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-05-02 09:20:21 +00:00
parent c9356d82bc
commit fd5f913f33
2 changed files with 18 additions and 5 deletions

View file

@ -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 file

@ -30,6 +30,13 @@ rb_cmpint(val)
return 0;
}
static VALUE
cmperr()
{
rb_raise(rb_eArgError, "comparison failed");
return Qnil; /* not reached */
}
static VALUE
cmp_equal(x, y)
VALUE x, y;
@ -37,8 +44,9 @@ cmp_equal(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;
}