diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-05-07 23:56:11 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-05-07 23:56:11 +0000 |
commit | 89c25a3dd633f8cbb788be42d84f0ad06b768b51 (patch) | |
tree | 325b5c433ce06d0d59315b36193b24690acd2b45 /numeric.c | |
parent | a03dd84dbc7844f33d90aeee867de14ed4fb9a8d (diff) |
* numeric.c (int_upto, int_downto): should fail unless the
argument is comparable. (ruby-bugs-ja:PR#454)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -1654,6 +1654,28 @@ fix_size(fix) } static VALUE +int_compare(i, to, id) + VALUE i, to; + ID id; +{ + VALUE cmp = rb_funcall(i, id, 1, to); + if (NIL_P(cmp)) { + char *toclass; + + if (SPECIAL_CONST_P(to)) { + to = rb_inspect(to); + toclass = StringValuePtr(to); + } + else { + toclass = rb_obj_classname(to); + } + rb_raise(rb_eArgError, "cannot compare %s with %s", + rb_obj_classname(i), toclass); + } + return cmp; +} + +static VALUE int_upto(from, to) VALUE from, to; { @@ -1668,8 +1690,7 @@ int_upto(from, to) else { VALUE i = from; - for (;;) { - if (RTEST(rb_funcall(i, '>', 1, to))) break; + while (!int_compare(i, to, '>')) { rb_yield(i); i = rb_funcall(i, '+', 1, INT2FIX(1)); } @@ -1692,8 +1713,7 @@ int_downto(from, to) else { VALUE i = from; - for (;;) { - if (RTEST(rb_funcall(i, '<', 1, to))) break; + while (!int_compare(i, to, '<')) { rb_yield(i); i = rb_funcall(i, '-', 1, INT2FIX(1)); } |