merge revision(s) 39722,43929: [Backport #9178]

* enumerator.c (enumerator_with_index): try to convert given offset to
	  integer. fix bug introduced in r39594.

	* enumerator.c (enumerator_with_index): should not store local variable
	  address to memoise the arguments.  it is invalidated after the return.
	  [ruby-core:58692] [Bug #9178]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@44745 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2014-01-29 05:38:58 +00:00
parent f984d0782b
commit 0678e02501
6 changed files with 42 additions and 6 deletions

View file

@ -13,6 +13,7 @@
************************************************/
#include "ruby/ruby.h"
#include "node.h"
/*
* Document-class: Enumerator
@ -368,9 +369,9 @@ enumerator_each(VALUE obj)
static VALUE
enumerator_with_index_i(VALUE val, VALUE m, int argc, VALUE *argv)
{
VALUE *memo = (VALUE *)m;
VALUE idx = *memo;
*memo = rb_int_succ(idx);
NODE *memo = (NODE *)m;
VALUE idx = memo->u1.value;
memo->u1.value = rb_int_succ(idx);
if (argc <= 1)
return rb_yield_values(2, val, idx);
@ -401,7 +402,7 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj)
memo = INT2FIX(0);
else
memo = rb_to_int(memo);
return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)&memo);
return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)NEW_MEMO(memo, 0, 0));
}
/*