ruby-changes:30377
From: nobu <ko1@a...>
Date: Fri, 9 Aug 2013 00:11:21 +0900 (JST)
Subject: [ruby-changes:30377] nobu:r42450 (trunk): enumerator.c: fix non-single argument
nobu 2013-08-09 00:10:37 +0900 (Fri, 09 Aug 2013) New Revision: 42450 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42450 Log: enumerator.c: fix non-single argument * enumerator.c (lazy_zip_func): fix non-single argument. fix out-of-bound access and pack multiple yielded values. [ruby-core:56383] [Bug #8735] Modified files: trunk/ChangeLog trunk/enumerator.c trunk/test/ruby/test_lazy_enumerator.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42449) +++ ChangeLog (revision 42450) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Aug 9 00:10:32 2013 Nobuyoshi Nakada <nobu@r...> + + * enumerator.c (lazy_zip_func): fix non-single argument. fix + out-of-bound access and pack multiple yielded values. + [ruby-core:56383] [Bug #8735] + Thu Aug 8 23:01:20 2013 Nobuyoshi Nakada <nobu@r...> * object.c (rb_mod_singleton_p): new method Module#singleton_class? to Index: enumerator.c =================================================================== --- enumerator.c (revision 42449) +++ enumerator.c (revision 42450) @@ -1700,7 +1700,12 @@ lazy_zip_func(VALUE val, VALUE zip_args, https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1700 } ary = rb_ary_new2(RARRAY_LEN(arg) + 1); - rb_ary_push(ary, argv[1]); + v = Qnil; + if (--argc > 0) { + ++argv; + v = argc > 1 ? rb_ary_new_from_values(argc, argv) : *argv; + } + rb_ary_push(ary, v); for (i = 0; i < RARRAY_LEN(arg); i++) { v = rb_rescue2(call_next, RARRAY_AREF(arg, i), next_stopped, 0, rb_eStopIteration, (VALUE)0); Index: test/ruby/test_lazy_enumerator.rb =================================================================== --- test/ruby/test_lazy_enumerator.rb (revision 42449) +++ test/ruby/test_lazy_enumerator.rb (revision 42450) @@ -298,6 +298,18 @@ class TestLazyEnumerator < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_lazy_enumerator.rb#L298 assert_equal [[1, 42], [2, :foo]], zip.force end + def test_zip_nonsingle + bug8735 = '[ruby-core:56383] [Bug #8735]' + + obj = Object.new + def obj.each + yield + yield 1, 2 + end + + assert_equal(obj.to_enum.zip(obj.to_enum), obj.to_enum.lazy.zip(obj.to_enum).force, bug8735) + end + def test_take_rewound bug7696 = '[ruby-core:51470]' e=(1..42).lazy.take(2) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/