merge revision(s) 39594,39596: [Backport #8010]

* enumerator.c (enumerator_with_index_i): allow Bignum as offset, to
	  get rid of conversion exception and integer overflow.
	  [ruby-dev:47131] [Bug #8010]

	* enumerator.c (enumerator_with_index):  Restore handling of a nil memo
	  from r39594.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@43960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2013-12-02 14:29:37 +00:00
parent 83c337f29a
commit b851418bb7
6 changed files with 28 additions and 10 deletions

View file

@ -460,11 +460,9 @@ enumerator_each(int argc, VALUE *argv, VALUE obj)
static VALUE
enumerator_with_index_i(VALUE val, VALUE m, int argc, VALUE *argv)
{
VALUE idx;
VALUE *memo = (VALUE *)m;
idx = INT2FIX(*memo);
++*memo;
VALUE idx = *memo;
*memo = rb_int_succ(idx);
if (argc <= 1)
return rb_yield_values(2, val, idx);
@ -494,7 +492,8 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj)
rb_scan_args(argc, argv, "01", &memo);
RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_size);
memo = NIL_P(memo) ? 0 : (VALUE)NUM2LONG(memo);
if (NIL_P(memo))
memo = INT2NUM(0);
return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)&memo);
}