ruby-changes:47248
From: nagachika <ko1@a...>
Date: Tue, 18 Jul 2017 21:42:44 +0900 (JST)
Subject: [ruby-changes:47248] nagachika:r59363 (ruby_2_4): merge revision(s) 59056: [Backport #13648] [Backport #13699]
nagachika 2017-07-18 21:42:38 +0900 (Tue, 18 Jul 2017) New Revision: 59363 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59363 Log: merge revision(s) 59056: [Backport #13648] [Backport #13699] enumerator.c: fix nested maps * enumerator.c (lazy_map_proc, lazy_grep_iter_proc): marks values returned by blocks are not packed in the case of nested maps, so that the result will be same as non-lazy version. based on the patch by akihikodaki (Akihiko Odaki) at [ruby-core:81638], without GCC extension. [Bug#13648] Modified directories: branches/ruby_2_4/ Modified files: branches/ruby_2_4/enumerator.c branches/ruby_2_4/test/ruby/test_lazy_enumerator.rb branches/ruby_2_4/version.h Index: ruby_2_4/enumerator.c =================================================================== --- ruby_2_4/enumerator.c (revision 59362) +++ ruby_2_4/enumerator.c (revision 59363) @@ -1448,6 +1448,8 @@ lazy_init_block_i(RB_BLOCK_CALL_FUNC_ARG https://github.com/ruby/ruby/blob/trunk/ruby_2_4/enumerator.c#L1448 #define LAZY_MEMO_PACKED_P(memo) ((memo)->memo_flags & LAZY_MEMO_PACKED) #define LAZY_MEMO_SET_BREAK(memo) ((memo)->memo_flags |= LAZY_MEMO_BREAK) #define LAZY_MEMO_SET_VALUE(memo, value) MEMO_V2_SET(memo, value) +#define LAZY_MEMO_SET_PACKED(memo) ((memo)->memo_flags |= LAZY_MEMO_PACKED) +#define LAZY_MEMO_RESET_PACKED(memo) ((memo)->memo_flags &= ~LAZY_MEMO_PACKED) static VALUE lazy_init_yielder(VALUE val, VALUE m, int argc, VALUE *argv) @@ -1743,6 +1745,7 @@ lazy_map_proc(VALUE proc_entry, struct M https://github.com/ruby/ruby/blob/trunk/ruby_2_4/enumerator.c#L1745 { VALUE value = lazyenum_yield_values(proc_entry, result); LAZY_MEMO_SET_VALUE(result, value); + LAZY_MEMO_RESET_PACKED(result); return result; } @@ -1913,6 +1916,7 @@ lazy_grep_iter_proc(VALUE proc_entry, st https://github.com/ruby/ruby/blob/trunk/ruby_2_4/enumerator.c#L1916 if (!RTEST(chain)) return 0; value = rb_proc_call_with_block(entry->proc, 1, &(result->memo_value), Qnil); LAZY_MEMO_SET_VALUE(result, value); + LAZY_MEMO_RESET_PACKED(result); return result; } Index: ruby_2_4/version.h =================================================================== --- ruby_2_4/version.h (revision 59362) +++ ruby_2_4/version.h (revision 59363) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1 #define RUBY_VERSION "2.4.2" -#define RUBY_RELEASE_DATE "2017-07-12" -#define RUBY_PATCHLEVEL 145 +#define RUBY_RELEASE_DATE "2017-07-18" +#define RUBY_PATCHLEVEL 146 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 7 -#define RUBY_RELEASE_DAY 12 +#define RUBY_RELEASE_DAY 18 #include "ruby/version.h" Index: ruby_2_4/test/ruby/test_lazy_enumerator.rb =================================================================== --- ruby_2_4/test/ruby/test_lazy_enumerator.rb (revision 59362) +++ ruby_2_4/test/ruby/test_lazy_enumerator.rb (revision 59363) @@ -14,7 +14,14 @@ class TestLazyEnumerator < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_lazy_enumerator.rb#L14 def each(*args) @args = args - @enum.each {|i| @current = i; yield i} + @enum.each do |v| + @current = v + if v.is_a? Enumerable + yield *v + else + yield v + end + end end end @@ -100,6 +107,15 @@ class TestLazyEnumerator < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_lazy_enumerator.rb#L107 assert_equal(1, a.current) end + def test_map_packed_nested + bug = '[ruby-core:81638] [Bug#13648]' + + a = Step.new([[1, 2]]) + expected = [[[1, 2]]] + assert_equal(expected, a.map {|*args| args}.map {|*args| args}.to_a) + assert_equal(expected, a.lazy.map {|*args| args}.map {|*args| args}.to_a, bug) + end + def test_flat_map a = Step.new(1..3) assert_equal(2, a.flat_map {|x| [x * 2]}.first) Index: ruby_2_4 =================================================================== --- ruby_2_4 (revision 59362) +++ ruby_2_4 (revision 59363) Property changes on: ruby_2_4 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r59056 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/