ruby-changes:26869
From: marcandre <ko1@a...>
Date: Thu, 24 Jan 2013 15:23:16 +0900 (JST)
Subject: [ruby-changes:26869] marcandRe: r38921 (trunk): * enumerator.c: Fix state handling for Lazy#drop_while
marcandre 2013-01-24 15:23:07 +0900 (Thu, 24 Jan 2013) New Revision: 38921 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38921 Log: * enumerator.c: Fix state handling for Lazy#drop_while [bug #7696] [bug #7691] * test/ruby/test_lazy_enumerator.rb: test for above Modified files: trunk/enumerator.c trunk/test/ruby/test_lazy_enumerator.rb Index: enumerator.c =================================================================== --- enumerator.c (revision 38920) +++ enumerator.c (revision 38921) @@ -1754,12 +1754,11 @@ lazy_drop(VALUE obj, VALUE n) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1754 static VALUE lazy_drop_while_func(VALUE val, VALUE args, int argc, VALUE *argv) { - NODE *memo = RNODE(args); - - if (!memo->u3.state && !RTEST(rb_yield_values2(argc - 1, &argv[1]))) { - memo->u3.state = TRUE; + VALUE memo = rb_ivar_get(argv[0], id_memo); + if (NIL_P(memo) && !RTEST(rb_yield_values2(argc - 1, &argv[1]))) { + rb_ivar_set(argv[0], id_memo, memo = Qtrue); } - if (memo->u3.state) { + if (memo == Qtrue) { rb_funcall2(argv[0], id_yield, argc - 1, argv + 1); } return Qnil; @@ -1768,14 +1767,11 @@ lazy_drop_while_func(VALUE val, VALUE ar https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1767 static VALUE lazy_drop_while(VALUE obj) { - NODE *memo; - if (!rb_block_given_p()) { rb_raise(rb_eArgError, "tried to call lazy drop_while without a block"); } - memo = NEW_MEMO(0, 0, FALSE); return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj, - lazy_drop_while_func, (VALUE) memo), + lazy_drop_while_func, 0), Qnil, 0); } Index: test/ruby/test_lazy_enumerator.rb =================================================================== --- test/ruby/test_lazy_enumerator.rb (revision 38920) +++ test/ruby/test_lazy_enumerator.rb (revision 38921) @@ -250,6 +250,13 @@ class TestLazyEnumerator < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_lazy_enumerator.rb#L250 assert_equal([*(1..5)]*5, take5.flat_map{take5}.force, bug7696) end + def test_drop_while_nested + bug7696 = '[ruby-core:51470]' + a = Step.new(1..10) + drop5 = a.lazy.drop_while{|x| x < 6} + assert_equal([*(6..10)]*5, drop5.flat_map{drop5}.force, bug7696) + 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/