summaryrefslogtreecommitdiff
path: root/enumerator.c
diff options
context:
space:
mode:
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/enumerator.c b/enumerator.c
index 09ef298396..bf0abf62f2 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -13,6 +13,8 @@
************************************************/
#include "ruby/ruby.h"
+#include "node.h"
+#include "internal.h"
/*
* Document-class: Enumerator
@@ -368,11 +370,9 @@ enumerator_each(VALUE obj)
static VALUE
enumerator_with_index_i(VALUE val, VALUE m, int argc, VALUE *argv)
{
- VALUE idx;
- VALUE *memo = (VALUE *)m;
-
- idx = INT2FIX(*memo);
- ++*memo;
+ NODE *memo = (NODE *)m;
+ VALUE idx = memo->u1.value;
+ memo->u1.value = rb_int_succ(idx);
if (argc <= 1)
return rb_yield_values(2, val, idx);
@@ -399,8 +399,11 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj)
rb_scan_args(argc, argv, "01", &memo);
RETURN_ENUMERATOR(obj, argc, argv);
- memo = NIL_P(memo) ? 0 : (VALUE)NUM2LONG(memo);
- return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)&memo);
+ if (NIL_P(memo))
+ memo = INT2FIX(0);
+ else
+ memo = rb_to_int(memo);
+ return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)NEW_MEMO(memo, 0, 0));
}
/*