1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-08-08 15:10:37 +00:00
parent a25d02b144
commit 8d644d6a6e
3 changed files with 24 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Fri Aug 9 00:10:32 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org>
* object.c (rb_mod_singleton_p): new method Module#singleton_class? to

View file

@ -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);

View file

@ -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)