diff --git a/ChangeLog b/ChangeLog index 2e1786d258..46015299f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Aug 9 00:10:32 2013 Nobuyoshi Nakada + + * 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 * object.c (rb_mod_singleton_p): new method Module#singleton_class? to diff --git a/enumerator.c b/enumerator.c index df73aef7a2..2a73d6a740 100644 --- a/enumerator.c +++ b/enumerator.c @@ -1700,7 +1700,12 @@ lazy_zip_func(VALUE val, VALUE zip_args, int argc, VALUE *argv) } 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); diff --git a/test/ruby/test_lazy_enumerator.rb b/test/ruby/test_lazy_enumerator.rb index 1108b93706..760db95f7b 100644 --- a/test/ruby/test_lazy_enumerator.rb +++ b/test/ruby/test_lazy_enumerator.rb @@ -298,6 +298,18 @@ class TestLazyEnumerator < Test::Unit::TestCase 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)