Project

General

Profile

Feature #10498 ยป 0001-vm_eval.c-loop-now-yields-a-incremented-counter.patch

cesario (Franck Verrot), 11/12/2014 06:25 AM

View differences:

ChangeLog
1
Wed Nov 12 05:57:20 2014  Franck Verrot <franck@verrot.fr>
2

  
3
	* vm_eval.c (loop_i): make loop yield a counter to
4
	  keep track of the iteration count.
5

  
1 6
Wed Nov 12 00:26:37 2014  Tanaka Akira  <akr@fsij.org>
2 7

  
3 8
	* test/ruby/test_object.rb: Specify an exception class for rescue clause.
test/ruby/test_enumerator.rb
47 47
    }
48 48
  end
49 49

  
50
  def test_loop_yield
51
    max = 0
52
    loop do |i|
53
      max = i
54
      raise StopIteration if i >= 1
55
    end
56
    assert_equal 1, max
57
  end
58

  
50 59
  def test_nested_iteration
51 60
    def (o = Object.new).each
52 61
      yield :ok1
vm_eval.c
1007 1007
static VALUE
1008 1008
loop_i(void)
1009 1009
{
1010
    for (;;) {
1011
	rb_yield_0(0, 0);
1010
    for (long int i = 0; i <= FIXNUM_MAX; ++i) {
1011
        rb_yield_values(1, INT2FIX(i));
1012 1012
    }
1013 1013
    return Qnil;
1014 1014
}
1015
-