From 36c39fabe33a9dfa7f6e1a79eb4e85f239cd9b47 Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Wed, 12 Nov 2014 05:57:20 +0100 Subject: [PATCH] vm_eval.c: loop now yields a incremented counter * vm_eval.c (loop_i): make loop yield a counter to keep track of the iteration count. --- ChangeLog | 5 +++++ test/ruby/test_enumerator.rb | 9 +++++++++ vm_eval.c | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 10036a4..af111f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Nov 12 05:57:20 2014 Franck Verrot + + * vm_eval.c (loop_i): make loop yield a counter to + keep track of the iteration count. + Wed Nov 12 00:26:37 2014 Tanaka Akira * test/ruby/test_object.rb: Specify an exception class for rescue clause. diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index f2a7afa..e86803b 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -47,6 +47,15 @@ class TestEnumerator < Test::Unit::TestCase } end + def test_loop_yield + max = 0 + loop do |i| + max = i + raise StopIteration if i >= 1 + end + assert_equal 1, max + end + def test_nested_iteration def (o = Object.new).each yield :ok1 diff --git a/vm_eval.c b/vm_eval.c index a057ece..a261109 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1007,8 +1007,8 @@ rb_yield_block(VALUE val, VALUE arg, int argc, const VALUE *argv, VALUE blockarg static VALUE loop_i(void) { - for (;;) { - rb_yield_0(0, 0); + for (long int i = 0; i <= FIXNUM_MAX; ++i) { + rb_yield_values(1, INT2FIX(i)); } return Qnil; } -- 1.8.5.2 (Apple Git-48)