こんばんは、sheepman です。

callcc と Enumerable#each_with_index をいっしょに使うと
index がおかしくなります。

$ cat t.rb
vv = 0
[1, 2, 3].each_with_index{|i, idx|
  callcc {|k| $k = k} if i == 2
  vv += 1
  p [vv, idx]
}
$k.call if vv < 7

$ ruby-1.9 t.rb
[1, 0]
[2, 1]
[3, 2]
[4, 1]
[5, 4]
[6, 1]
[7, 6]

以下はパッチです。

$ svn diff enum.c
Index: enum.c
===================================================================
--- enum.c      (revision 12415)
+++ enum.c      (working copy)
@@ -1167,11 +1167,10 @@
 each_with_index_i(VALUE val, VALUE memo)
 {
     long n;
-
+    VALUE idx = RARRAY_PTR(memo)[1];
     RARRAY_PTR(memo)[0] = val;
     rb_yield(memo);
-    val = RARRAY_PTR(memo)[1];
-    n = NUM2LONG(val);
+    n = NUM2LONG(idx);
     n++;
     RARRAY_PTR(memo)[1] = INT2NUM(n);
     return Qnil;

-- 
sheepman / TAMURA Takashi
sheepman / sheepman.sakura.ne.jp