From c27bd84806454f4627d8957a87b6186da1aab089 Mon Sep 17 00:00:00 2001 From: nagachika Date: Mon, 2 Dec 2013 14:48:50 +0000 Subject: merge revision(s) 43929: [Backport #9178] * 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_2_0_0@43961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- enumerator.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'enumerator.c') diff --git a/enumerator.c b/enumerator.c index dc8c9d3504..e20a612358 100644 --- a/enumerator.c +++ b/enumerator.c @@ -460,9 +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 *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); @@ -494,7 +494,7 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj) RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_size); if (NIL_P(memo)) memo = INT2NUM(0); - 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)); } /* -- cgit v1.2.3