From 079de9aec4545fd298cd96ea5d63db10229d5a0f Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 31 Jan 2007 05:59:23 +0000 Subject: * eval.c (rb_iterate): need to PUSH_ITER in proper order. [ruby-core:10125] * test/ruby/test_iterator.rb (TestIterator::test_block_given_within_iterator): add new test. [ruby-core:10125] git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@11606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ eval.c | 4 ++-- test/ruby/test_iterator.rb | 12 ++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e356c15b5..af12e1f75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Jan 31 14:52:09 2007 Yukihiro Matsumoto + + * eval.c (rb_iterate): need to PUSH_ITER in proper order. + [ruby-core:10125] + + * test/ruby/test_iterator.rb (TestIterator::test_block_given_within_iterator): + add new test. [ruby-core:10125] + Tue Jan 30 14:58:51 2007 NAKAMURA Usaku * string.c (rb_str_sub_bang): calling rb_str_modify() should be just diff --git a/eval.c b/eval.c index a1ca15958..19d3b0489 100644 --- a/eval.c +++ b/eval.c @@ -5284,9 +5284,9 @@ rb_iterate(it_proc, data1, bl_proc, data2) NODE *node = NEW_IFUNC(bl_proc, data2); VALUE self = ruby_top_self; - PUSH_ITER(ITER_PRE); PUSH_TAG(PROT_LOOP); PUSH_BLOCK(0, node); + PUSH_ITER(ITER_PRE); state = EXEC_TAG(); if (state == 0) { iter_retry: @@ -5300,9 +5300,9 @@ rb_iterate(it_proc, data1, bl_proc, data2) state = 0; goto iter_retry; } + POP_ITER(); POP_BLOCK(); POP_TAG(); - POP_ITER(); switch (state) { case 0: diff --git a/test/ruby/test_iterator.rb b/test/ruby/test_iterator.rb index 638916309..2cd48b29a 100644 --- a/test/ruby/test_iterator.rb +++ b/test/ruby/test_iterator.rb @@ -462,4 +462,16 @@ class TestIterator < Test::Unit::TestCase assert_equal(ok, result) return end + + class IterString < ::String + def ===(other) + super if !block_given? + end + end + + # Check that the block passed to an iterator + # does not get propagated inappropriately + def test_block_given_within_iterator + assert_equal(["b"], ["a", "b", "c"].grep(IterString.new("b")) {|s| s}) + end end -- cgit