mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* range.c (range_step): do not forcefully convert steps into
integers. [ruby-dev:34571] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
546d98b7e8
commit
7f31465bb5
2 changed files with 10 additions and 19 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Fri May 2 16:10:57 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* range.c (range_step): do not forcefully convert steps into
|
||||||
|
integers. [ruby-dev:34571]
|
||||||
|
|
||||||
Fri May 2 14:52:33 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Fri May 2 14:52:33 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* misc/ruby-mode.el: move fontifying code from hook. a patch from
|
* misc/ruby-mode.el: move fontifying code from hook. a patch from
|
||||||
|
|
24
range.c
24
range.c
|
@ -296,7 +296,6 @@ static VALUE
|
||||||
range_step(int argc, VALUE *argv, VALUE range)
|
range_step(int argc, VALUE *argv, VALUE range)
|
||||||
{
|
{
|
||||||
VALUE b, e, step, tmp;
|
VALUE b, e, step, tmp;
|
||||||
long unit;
|
|
||||||
|
|
||||||
RETURN_ENUMERATOR(range, argc, argv);
|
RETURN_ENUMERATOR(range, argc, argv);
|
||||||
|
|
||||||
|
@ -304,33 +303,20 @@ range_step(int argc, VALUE *argv, VALUE range)
|
||||||
e = RANGE_END(range);
|
e = RANGE_END(range);
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
step = INT2FIX(1);
|
step = INT2FIX(1);
|
||||||
unit = 1;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_scan_args(argc, argv, "01", &step);
|
rb_scan_args(argc, argv, "01", &step);
|
||||||
tmp = rb_check_to_integer(step, "to_int");
|
if (rb_funcall(step, '<', 1, INT2FIX(0))) {
|
||||||
if (!NIL_P(tmp)) {
|
rb_raise(rb_eArgError, "step can't be negative");
|
||||||
if (FIXNUM_P(tmp))
|
|
||||||
unit = FIX2LONG(tmp);
|
|
||||||
else
|
|
||||||
unit = rb_cmpint(tmp, step, INT2FIX(0));
|
|
||||||
step = tmp;
|
|
||||||
}
|
}
|
||||||
else {
|
else if (!rb_funcall(step, '>', 1, INT2FIX(0))) {
|
||||||
tmp = rb_funcall(rb_funcall(b, '+', 1, step), '-', 1, b);
|
rb_raise(rb_eArgError, "step can't be 0");
|
||||||
unit = rb_cmpint(tmp, step, INT2FIX(0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unit < 0) {
|
|
||||||
rb_raise(rb_eArgError, "step can't be negative");
|
|
||||||
}
|
|
||||||
if (unit == 0) {
|
|
||||||
rb_raise(rb_eArgError, "step can't be 0");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FIXNUM_P(b) && FIXNUM_P(e) && FIXNUM_P(step)) { /* fixnums are special */
|
if (FIXNUM_P(b) && FIXNUM_P(e) && FIXNUM_P(step)) { /* fixnums are special */
|
||||||
long end = FIX2LONG(e);
|
long end = FIX2LONG(e);
|
||||||
long i;
|
long i, unit = FIX2LONG(step);
|
||||||
|
|
||||||
if (!EXCL(range))
|
if (!EXCL(range))
|
||||||
end += 1;
|
end += 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue