Project

General

Profile

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

Updated patch (no more limited to FIXNUM_MAX iterations) - cesario (Franck Verrot), 11/14/2014 10:27 PM

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);
1012
    }
1013
    return Qnil;
1010
  VALUE counter   = INT2FIX(0);
1011
  VALUE increment = INT2FIX(1);
1012
  for (;;) {
1013
    rb_yield_values(1, counter);
1014
    counter = rb_funcall(counter, '+', 1, increment);
1015
  }
1016
  return Qnil;
1014 1017
}
1015 1018

  
1016 1019
static VALUE
1017
-