summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-06 15:15:12 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-06 15:15:12 +0000
commitf433be6d9c9ca7010d2c4368030a09a76bb3b98b (patch)
treed01fd00f2f8484478658bab588709901875da88d /range.c
parent16d052477b987fbe2db8ca68be2d4a5fb405514b (diff)
* io.c (rb_io_s_sysopen): preserve path in the buffer allocated by
ALLOCA_N() to prevent modification. [ruby-dev:24438] * io.c (rb_io_mode_flags): preserve append mode flag. [ruby-dev:24436] * io.c (rb_io_modenum_mode): do not use external output buffer. * string.c (rb_str_justify): differ pointer retrieval to prevent padding string modification. [ruby-dev:24434] * range.c (range_each_func): allow func to terminate loop by returning RANGE_EACH_BREAK. * range.c (member_i): use RANGE_EACH_BREAK. [ruby-talk:114959] * marshal.c (r_byte): retrieve pointer from string value for each time. [ruby-dev:24404] * marshal.c (r_bytes0): ditto. * enum.c (sort_by_i): re-entrance check added. [ruby-dev:24399] * io.c (io_read): should freeze all reading buffer. [ruby-dev:24400] * string.c (rb_str_sum): should use bignums when bits is greater than or equals to sizeof(long)*CHAR_BITS. [ruby-dev:24395] * eval.c (specific_eval): defer pointer retrieval to prevent unsafe sourcefile string modification. [ruby-dev:24382] * eval.c (specific_eval): defer pointer retrieval to prevent unsafe sourcefile string modification. [ruby-dev:24382] * string.c (rb_str_sum): wrong cast caused wrong result. [ruby-dev:24385] * enum.c (enum_sort_by): hide temporary array from ObjectSpace.each_object. [ruby-dev:24386] * string.c (rb_str_sum): check was done with false pointer. [ruby-dev:24383] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/range.c b/range.c
index be0896b..a48ee73 100644
--- a/range.c
+++ b/range.c
@@ -230,18 +230,8 @@ str_step(args)
return rb_str_upto(args[0], args[1], EXCL(args[2]));
}
-static VALUE
-step_i(i, iter)
- VALUE i;
- long *iter;
-{
- iter[0]--;
- if (iter[0] == 0) {
- rb_yield(i);
- iter[0] = iter[1];
- }
- return Qnil;
-}
+#define RANGE_EACH_BREAK Qfalse
+#define RANGE_EACH_CONTINUE Qtrue
static void
range_each_func(range, func, v, e, arg)
@@ -254,19 +244,32 @@ range_each_func(range, func, v, e, arg)
if (EXCL(range)) {
while (r_lt(v, e)) {
- (*func)(v, arg);
+ if ((*func)(v, arg) == RANGE_EACH_BREAK) break;
v = rb_funcall(v, id_succ, 0, 0);
}
}
else {
while (RTEST(c = r_le(v, e))) {
- (*func)(v, arg);
+ if ((*func)(v, arg) == RANGE_EACH_BREAK) break;
if (c == INT2FIX(0)) break;
v = rb_funcall(v, id_succ, 0, 0);
}
}
}
+static VALUE
+step_i(i, iter)
+ VALUE i;
+ long *iter;
+{
+ iter[0]--;
+ if (iter[0] == 0) {
+ rb_yield(i);
+ iter[0] = iter[1];
+ }
+ return RANGE_EACH_CONTINUE;
+}
+
/*
* call-seq:
* rng.step(n=1) {| obj | block } => rng
@@ -335,7 +338,7 @@ range_step(argc, argv, range)
if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
args[0] = b; args[1] = e; args[2] = range;
iter[0] = 1; iter[1] = unit;
- rb_iterate((VALUE(*)_((VALUE)))str_step, (VALUE)args, step_i, (VALUE)iter);
+ rb_iterate(str_step, (VALUE)args, step_i, (VALUE)iter);
}
else if (rb_obj_is_kind_of(b, rb_cNumeric)) {
ID c = rb_intern(EXCL(range) ? "<" : "<=");
@@ -368,7 +371,8 @@ each_i(v, arg)
VALUE v;
void *arg;
{
- return rb_yield(v);
+ rb_yield(v);
+ return RANGE_EACH_CONTINUE;
}
/*
@@ -417,7 +421,7 @@ range_each(range)
args[0] = beg; args[1] = end; args[2] = range;
iter[0] = 1; iter[1] = 1;
- rb_iterate((VALUE(*)_((VALUE)))str_step, (VALUE)args, step_i, (VALUE)iter);
+ rb_iterate(str_step, (VALUE)args, step_i, (VALUE)iter);
}
else {
range_each_func(range, each_i, beg, end, NULL);
@@ -548,14 +552,16 @@ range_inspect(range)
return str;
}
-static void
+static VALUE
member_i(v, args)
VALUE v;
VALUE *args;
{
if (rb_equal(v, args[0])) {
args[1] = Qtrue;
+ return RANGE_EACH_BREAK;
}
+ return RANGE_EACH_CONTINUE;
}
/*