summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-19 10:25:23 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-19 10:25:23 +0000
commit860bdc3b61dbcacecd4a2fb2c40cf222e91b8fd5 (patch)
tree280c20d9eec8f2500428b71e7beeeff064ad5314 /range.c
parentdd09dfe3f0bc975db4b84a0e563bcdf862a7063b (diff)
* io.c (read_all): block string buffer modification during
rb_io_fread() by freezing it temporarily. [ruby-dev:24479] * dir.c (rb_push_glob): block call at once the end of method. [ruby-dev:24487] * ext/enumerator/enumerator.c (enum_each_slice): remove rb_gc_force_recycle() to prevent potential SEGV. [ruby-dev:24499] * ext/zlib/zlib.c (zstream_expand_buffer): hide internal string buffer by clearing klass. [ruby-dev:24510] * ext/socket/socket.c (sock_s_getservbyaname): protocol string might be altered. [ruby-dev:24503] * string.c (rb_str_upto): check if return value from succ is a string. [ruby-dev:24504] * io.c (rb_io_popen): get mode string via rb_io_flags_mode() to avoid mode string modification. [ruby-dev:24454] * io.c (rb_io_getline_fast): should take delim as unsigned char to distinguish EOF and '\377'. [ruby-dev:24460] * io.c (rb_io_getline): add check for RS modification. [ruby-dev:24461] * enum.c (enum_sort_by): use qsort() directly instead using rb_iterate(). [ruby-dev:24462] * enum.c (enum_each_with_index): remove rb_gc_force_recycle() to prevent access to recycled object (via continuation for example). [ruby-dev:24463] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c60
1 files changed, 9 insertions, 51 deletions
diff --git a/range.c b/range.c
index 26fbb4b..6783eff 100644
--- a/range.c
+++ b/range.c
@@ -230,13 +230,10 @@ str_step(args)
return rb_str_upto(args[0], args[1], EXCL(args[2]));
}
-#define RANGE_EACH_BREAK Qfalse
-#define RANGE_EACH_CONTINUE Qtrue
-
static void
range_each_func(range, func, v, e, arg)
VALUE range;
- VALUE (*func) _((VALUE, void*));
+ void (*func) _((VALUE, void*));
VALUE v, e;
void *arg;
{
@@ -244,13 +241,13 @@ range_each_func(range, func, v, e, arg)
if (EXCL(range)) {
while (r_lt(v, e)) {
- if ((*func)(v, arg) == RANGE_EACH_BREAK) break;
+ (*func)(v, arg);
v = rb_funcall(v, id_succ, 0, 0);
}
}
else {
while (RTEST(c = r_le(v, e))) {
- if ((*func)(v, arg) == RANGE_EACH_BREAK) break;
+ (*func)(v, arg);
if (c == INT2FIX(0)) break;
v = rb_funcall(v, id_succ, 0, 0);
}
@@ -267,7 +264,7 @@ step_i(i, iter)
rb_yield(i);
iter[0] = iter[1];
}
- return RANGE_EACH_CONTINUE;
+ return Qnil;
}
/*
@@ -367,13 +364,12 @@ range_step(argc, argv, range)
return range;
}
-static VALUE
+static void
each_i(v, arg)
VALUE v;
void *arg;
{
rb_yield(v);
- return RANGE_EACH_CONTINUE;
}
/*
@@ -554,49 +550,11 @@ range_inspect(range)
return str;
}
-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;
-}
-
-/*
- * call-seq:
- * rng.member?(val) => true or false
- *
- * Return +true+ if _val_ is one of the values in _rng_ (that is if
- * <code>Range#each</code> would return _val_ at some point).
- */
-
-static VALUE
-range_member(range, val)
- VALUE range, val;
-{
- VALUE beg, end;
- VALUE args[2];
-
- beg = rb_ivar_get(range, id_beg);
- end = rb_ivar_get(range, id_end);
-
- if (!rb_respond_to(beg, id_succ)) {
- rb_raise(rb_eTypeError, "cannot iterate from %s",
- rb_obj_classname(beg));
- }
- args[0] = val;
- args[1] = Qfalse;
- range_each_func(range, member_i, beg, end, args);
- return args[1];
-}
-
/*
* call-seq:
- * rng === obj => true or false
+ * rng === obj => true or false
+ * rng.member?(val) => true or false
+ * rng.include?(val) => true or false
*
* Returns <code>true</code> if <i>obj</i> is an element of
* <i>rng</i>, <code>false</code> otherwise. Conveniently,
@@ -707,7 +665,7 @@ Init_Range()
rb_define_method(rb_cRange, "exclude_end?", range_exclude_end_p, 0);
- rb_define_method(rb_cRange, "member?", range_member, 1);
+ rb_define_method(rb_cRange, "member?", range_include, 1);
rb_define_method(rb_cRange, "include?", range_include, 1);
id_cmp = rb_intern("<=>");