ruby-changes:31882
From: nagachika <ko1@a...>
Date: Mon, 2 Dec 2013 23:48:59 +0900 (JST)
Subject: [ruby-changes:31882] nagachika:r43961 (ruby_2_0_0): merge revision(s) 43929: [Backport #9178]
nagachika 2013-12-02 23:48:50 +0900 (Mon, 02 Dec 2013) New Revision: 43961 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43961 Log: 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] Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/enumerator.c branches/ruby_2_0_0/test/ruby/test_enumerator.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 43960) +++ ruby_2_0_0/ChangeLog (revision 43961) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Mon Dec 2 23:31:00 2013 Nobuyoshi Nakada <nobu@r...> + + * 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] + Mon Dec 2 23:16:50 2013 Eric Hodel <drbrain@s...> * enumerator.c (enumerator_with_index): Restore handling of a nil memo Index: ruby_2_0_0/enumerator.c =================================================================== --- ruby_2_0_0/enumerator.c (revision 43960) +++ ruby_2_0_0/enumerator.c (revision 43961) @@ -460,9 +460,9 @@ enumerator_each(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/enumerator.c#L460 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 *a https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/enumerator.c#L494 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)); } /* Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 43960) +++ ruby_2_0_0/version.h (revision 43961) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2013-12-02" -#define RUBY_PATCHLEVEL 356 +#define RUBY_PATCHLEVEL 357 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 12 Index: ruby_2_0_0/test/ruby/test_enumerator.rb =================================================================== --- ruby_2_0_0/test/ruby/test_enumerator.rb (revision 43960) +++ ruby_2_0_0/test/ruby/test_enumerator.rb (revision 43961) @@ -112,6 +112,16 @@ class TestEnumerator < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_enumerator.rb#L112 assert_equal([[1,s],[2,s+1],[3,s+2]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010) end + def test_with_index_dangling_memo + bug9178 = '[ruby-core:58692] [Bug #9178]' + assert_separately([], <<-"end;") + bug = "#{bug9178}" + e = [1].to_enum(:chunk).with_index {|c,i| i == 5} + assert_kind_of(Enumerator, e) + assert_equal([false, [1]], e.to_a[0], bug) + end; + end + def test_with_object obj = [0, 1] ret = (1..10).each.with_object(obj) {|i, memo| Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r43929 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/