diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-02 07:15:28 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-02 07:15:28 +0000 |
commit | 3fe1bb29ae4411dea836c21000ca540172dd086d (patch) | |
tree | c00cce58ac836377a41d29e82491555c8a47600a | |
parent | baa9f8d73673e64de645da6fe04e0cc07e2e79b2 (diff) | |
download | ruby-3fe1bb29ae4411dea836c21000ca540172dd086d.tar.gz ruby-3fe1bb29ae4411dea836c21000ca540172dd086d.tar.xz ruby-3fe1bb29ae4411dea836c21000ca540172dd086d.zip |
* range.c (range_step): do not forcefully convert steps into
integers. [ruby-dev:34571]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | range.c | 24 |
2 files changed, 10 insertions, 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> * misc/ruby-mode.el: move fontifying code from hook. a patch from @@ -296,7 +296,6 @@ static VALUE range_step(int argc, VALUE *argv, VALUE range) { VALUE b, e, step, tmp; - long unit; RETURN_ENUMERATOR(range, argc, argv); @@ -304,33 +303,20 @@ range_step(int argc, VALUE *argv, VALUE range) e = RANGE_END(range); if (argc == 0) { step = INT2FIX(1); - unit = 1; } else { rb_scan_args(argc, argv, "01", &step); - tmp = rb_check_to_integer(step, "to_int"); - if (!NIL_P(tmp)) { - if (FIXNUM_P(tmp)) - unit = FIX2LONG(tmp); - else - unit = rb_cmpint(tmp, step, INT2FIX(0)); - step = tmp; + if (rb_funcall(step, '<', 1, INT2FIX(0))) { + rb_raise(rb_eArgError, "step can't be negative"); } - else { - tmp = rb_funcall(rb_funcall(b, '+', 1, step), '-', 1, b); - unit = rb_cmpint(tmp, step, INT2FIX(0)); + else if (!rb_funcall(step, '>', 1, INT2FIX(0))) { + rb_raise(rb_eArgError, "step can't be 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 */ long end = FIX2LONG(e); - long i; + long i, unit = FIX2LONG(step); if (!EXCL(range)) end += 1; |