diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-10-19 10:25:23 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-10-19 10:25:23 +0000 |
commit | 1057902ac7bc51a9d6c852e6cd778498acbed869 (patch) | |
tree | 574247e8afe2697445b15cf509eed2a28aa8a5ad | |
parent | c0700eba8dd91c3f2c070670cc448ba704effd78 (diff) | |
download | ruby-1057902ac7bc51a9d6c852e6cd778498acbed869.tar.gz |
* 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/trunk@7071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 46 | ||||
-rw-r--r-- | dir.c | 19 | ||||
-rw-r--r-- | enum.c | 31 | ||||
-rw-r--r-- | eval.c | 6 | ||||
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 2 | ||||
-rw-r--r-- | ext/dbm/dbm.c | 2 | ||||
-rw-r--r-- | ext/enumerator/enumerator.c | 3 | ||||
-rw-r--r-- | ext/socket/socket.c | 16 | ||||
-rw-r--r-- | ext/win32ole/win32ole.c | 6 | ||||
-rw-r--r-- | ext/zlib/zlib.c | 3 | ||||
-rw-r--r-- | io.c | 27 | ||||
-rw-r--r-- | lib/cgi/session/pstore.rb | 6 | ||||
-rw-r--r-- | lib/delegate.rb | 9 | ||||
-rw-r--r-- | lib/tempfile.rb | 3 | ||||
-rw-r--r-- | lib/xsd/charset.rb | 2 | ||||
-rw-r--r-- | object.c | 4 | ||||
-rw-r--r-- | range.c | 60 | ||||
-rw-r--r-- | re.c | 4 | ||||
-rw-r--r-- | string.c | 1 |
19 files changed, 126 insertions, 124 deletions
@@ -1,3 +1,18 @@ +Tue Oct 19 17:24:11 2004 Yukihiro Matsumoto <matz@ruby-lang.org> + + * 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] + Tue Oct 19 08:47:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> * string.c (rb_str_upto): method result must be checked. [ruby-dev:24504] @@ -24,6 +39,14 @@ Mon Oct 18 01:56:03 2004 GOTOU Yuuzou <gotoyuzo@notwork.org> * lib/webrick/httprequest.rb (WEBrick::HTTPRequest#initialize): initial value of accpet-* should be array. +Mon Oct 18 00:42:45 2004 Yukihiro Matsumoto <matz@ruby-lang.org> + + * 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] + Sun Oct 17 23:03:48 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> * ext/tk/lib/tk/timer.rb: TkTimer#start and restart accept a block @@ -113,6 +136,24 @@ Tue Oct 12 15:05:32 2004 WATANABE Hirofumi <eban@ruby-lang.org> * io.c (MODE_BINMODE, MODE_BINARY): fixed reversed condition. +Mon Oct 11 17:51:34 2004 Yukihiro Matsumoto <matz@ruby-lang.org> + + * 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] + Mon Oct 11 13:48:20 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> * ext/tk/lib/tk/*: untabify @@ -144,6 +185,11 @@ Sat Oct 9 19:50:36 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> * io.c (rb_io_getline): should not treat char as negative value. [ruby-dev:24460] +Sat Oct 9 00:25:39 2004 Tanaka Akira <akr@m17n.org> + + * io.c (rb_io_fread): rb_thread_wait_fd() was lost. + [ruby-dev:24457] + Fri Oct 8 21:36:56 2004 Minero Aoki <aamine@loveruby.net> * lib/fileutils.rb (fu_traverse): return value of Dir.entries is @@ -1403,14 +1403,7 @@ push_pattern(path, ary) const char *path; VALUE ary; { - VALUE str = rb_tainted_str_new2(path); - - if (!NIL_P(ary)) { - rb_ary_push(ary, str); - } - else { - rb_yield(str); - } + rb_ary_push(ary, rb_tainted_str_new2(path)); } static int @@ -1478,13 +1471,9 @@ rb_push_glob(str, flags) /* '\0' is delimiter */ const char *p, *pend; VALUE ary; - if (rb_block_given_p()) - ary = Qnil; - else - ary = rb_ary_new(); - FilePathValue(str); + ary = rb_ary_new(); p = RSTRING(str)->ptr; pend = p + RSTRING(str)->len; @@ -1497,6 +1486,10 @@ rb_push_glob(str, flags) /* '\0' is delimiter */ else p++; } + if (rb_block_given_p()) { + rb_ary_each(ary); + return Qnil; + } return ary; } @@ -117,11 +117,8 @@ enum_find(argc, argv, obj) rb_scan_args(argc, argv, "01", &if_none); rb_iterate(rb_each, obj, find_i, (VALUE)memo); if (memo->u2.value) { - VALUE result = memo->u1.value; - rb_gc_force_recycle((VALUE)memo); - return result; + return memo->u1.value; } - rb_gc_force_recycle((VALUE)memo); if (!NIL_P(if_none)) { return rb_funcall(if_none, rb_intern("call"), 0, 0); } @@ -319,7 +316,6 @@ enum_inject(argc, argv, obj) } rb_iterate(rb_each, obj, inject_i, (VALUE)memo); n = memo->u1.value; - rb_gc_force_recycle((VALUE)memo); return n; } @@ -401,17 +397,14 @@ sort_by_i(i, ary) return Qnil; } -static VALUE -sort_by_cmp(values, ary) - VALUE values, ary; +static int +sort_by_cmp(aa, bb) + NODE **aa, **bb; { - NODE *a = (NODE*)RARRAY(values)->ptr[0]; - NODE *b = (NODE*)RARRAY(values)->ptr[1]; + VALUE a = aa[0]->u1.value; + VALUE b = bb[0]->u1.value; - /* pedantic check; they must be memo nodes */ - Check_Type(a, T_NODE); - Check_Type(b, T_NODE); - return rb_funcall(a->u1.value, id_cmp, 1, b->u1.value); + return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b); } /* @@ -499,7 +492,7 @@ enum_sort_by(obj) RBASIC(ary)->klass = 0; rb_iterate(rb_each, obj, sort_by_i, ary); if (RARRAY(ary)->len > 1) { - rb_iterate(rb_ary_sort_bang, ary, sort_by_cmp, ary); + qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), sort_by_cmp, 0); } for (i=0; i<RARRAY(ary)->len; i++) { RARRAY(ary)->ptr[i] = RNODE(RARRAY(ary)->ptr[i])->u2.value; @@ -559,7 +552,6 @@ enum_all(obj) memo->u1.value = Qtrue; rb_iterate(rb_each, obj, rb_block_given_p() ? all_iter_i : all_i, (VALUE)memo); result = memo->u1.value; - rb_gc_force_recycle((VALUE)memo); return result; } @@ -615,7 +607,6 @@ enum_any(obj) memo->u1.value = Qfalse; rb_iterate(rb_each, obj, rb_block_given_p() ? any_iter_i : any_i, (VALUE)memo); result = memo->u1.value; - rb_gc_force_recycle((VALUE)memo); return result; } @@ -681,7 +672,6 @@ enum_min(obj) rb_iterate(rb_each, obj, rb_block_given_p() ? min_ii : min_i, (VALUE)memo); result = memo->u1.value; - rb_gc_force_recycle((VALUE)memo); return result; } @@ -746,7 +736,6 @@ enum_max(obj) rb_iterate(rb_each, obj, rb_block_given_p() ? max_ii : max_i, (VALUE)memo); result = memo->u1.value; - rb_gc_force_recycle((VALUE)memo); return result; } @@ -789,7 +778,6 @@ enum_min_by(obj) rb_iterate(rb_each, obj, min_by_i, (VALUE)memo); result = memo->u2.value; - rb_gc_force_recycle((VALUE)memo); return result; } @@ -832,7 +820,6 @@ enum_max_by(obj) rb_iterate(rb_each, obj, max_by_i, (VALUE)memo); result = memo->u2.value; - rb_gc_force_recycle((VALUE)memo); return result; } @@ -870,7 +857,6 @@ enum_member(obj, val) rb_iterate(rb_each, obj, member_i, (VALUE)memo); result = memo->u2.value; - rb_gc_force_recycle((VALUE)memo); return result; } @@ -906,7 +892,6 @@ enum_each_with_index(obj) NODE *memo = rb_node_newnode(NODE_MEMO, 0, 0, 0); rb_iterate(rb_each, obj, each_with_index_i, (VALUE)memo); - rb_gc_force_recycle((VALUE)memo); return obj; } @@ -8264,7 +8264,7 @@ proc_eq(self, other) */ static VALUE -proc_hash(self, other) +proc_hash(self) VALUE self; { struct BLOCK *data; @@ -8288,8 +8288,8 @@ proc_hash(self, other) */ static VALUE -proc_to_s(self, other) - VALUE self, other; +proc_to_s(self) + VALUE self; { struct BLOCK *data; NODE *node; diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 402e13cc5c..4ccba8809a 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -579,7 +579,7 @@ BigDecimal_ge(VALUE self, VALUE r) } static VALUE -BigDecimal_neg(VALUE self, VALUE r) +BigDecimal_neg(VALUE self) { ENTER(5); Real *c, *a; diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c index 99144aa43b..e72d8ebba0 100644 --- a/ext/dbm/dbm.c +++ b/ext/dbm/dbm.c @@ -734,7 +734,7 @@ Init_dbm() rb_define_method(rb_cDBM, "[]=", fdbm_store, 2); rb_define_method(rb_cDBM, "store", fdbm_store, 2); rb_define_method(rb_cDBM, "index", fdbm_index, 1); - rb_define_method(rb_cDBM, "select", fdbm_select, -1); + rb_define_method(rb_cDBM, "select", fdbm_select, 0); rb_define_method(rb_cDBM, "values_at", fdbm_values_at, -1); rb_define_method(rb_cDBM, "length", fdbm_length, 0); rb_define_method(rb_cDBM, "size", fdbm_length, 0); diff --git a/ext/enumerator/enumerator.c b/ext/enumerator/enumerator.c index 8c3c566178..6e47330cef 100644 --- a/ext/enumerator/enumerator.c +++ b/ext/enumerator/enumerator.c @@ -70,7 +70,6 @@ enum_each_slice(obj, n) ary = memo->u1.value; if (RARRAY(ary)->len > 0) rb_yield(ary); - rb_gc_force_recycle((VALUE)memo); return Qnil; } @@ -114,7 +113,6 @@ enum_each_cons(obj, n) rb_iterate(rb_each, obj, each_cons_i, (VALUE)memo); - rb_gc_force_recycle((VALUE)memo); return Qnil; } @@ -163,7 +161,6 @@ enumerator_each(obj) rb_to_id(rb_ivar_get(obj, id_enum_method)), rb_ivar_get(obj, id_enum_args)); val = rb_iterate((VALUE (*)_((VALUE)))enumerator_iter, obj, rb_yield, 0); - rb_gc_force_recycle(obj); return val; } diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 979eaa0af3..044d411b29 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -2217,27 +2217,25 @@ sock_s_getservbyaname(argc, argv) int argc; VALUE *argv; { - VALUE service, protocol; - char *proto; + VALUE service, proto; struct servent *sp; int port; - rb_scan_args(argc, argv, "11", &service, &protocol); - if (NIL_P(protocol)) proto = "tcp"; - else proto = StringValuePtr(protocol); + rb_scan_args(argc, argv, "11", &service, &proto); + if (NIL_P(proto)) proto = rb_str_new2("tcp"); + else StringValue(proto); - StringValue(service); - sp = getservbyname((char*)RSTRING(service)->ptr, proto); + sp = getservbyname((char*)RSTRING(service)->ptr, RSTRING(proto)->ptr); if (sp) { port = ntohs(sp->s_port); } else { - char *s = RSTRING(service)->ptr; + char *s = StringValuePtr(service); char *end; port = strtoul(s, &end, 0); if (*end != '\0') { - rb_raise(rb_eSocket, "no such service %s/%s", s, proto); + rb_raise(rb_eSocket, "no such service %s/%s", s, RSTRING(proto)->ptr); } } return INT2FIX(port); diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index 60c2027690..66a00ddee7 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -2758,7 +2758,7 @@ static VALUE fole_get_methods( self ) VALUE self; { - return ole_methods( self, INVOKE_PROPERTYGET); + return ole_methods(self, INVOKE_PROPERTYGET); } /* @@ -2770,7 +2770,7 @@ static VALUE fole_put_methods( self ) VALUE self; { - return ole_methods( self, INVOKE_PROPERTYPUT); + return ole_methods(self, INVOKE_PROPERTYPUT); } /* @@ -2782,7 +2782,7 @@ static VALUE fole_func_methods( self ) VALUE self; { - return ole_methods( self, INVOKE_FUNC); + return ole_methods(self, INVOKE_FUNC); } /* diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 395eca8be2..9d1b204eb7 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -439,6 +439,7 @@ zstream_expand_buffer(z) z->buf_filled = 0; z->stream.next_out = RSTRING(z->buf)->ptr; z->stream.avail_out = ZSTREAM_INITIAL_BUFSIZE; + RBASIC(z->buf)->klass = 0; return; } @@ -3380,7 +3381,7 @@ void Init_zlib() cZStream = rb_define_class_under(mZlib, "ZStream", rb_cObject); rb_undef_alloc_func(cZStream); rb_define_method(cZStream, "avail_out", rb_zstream_avail_out, 0); - rb_define_method(cZStream, "avail_out=", rb_zstream_set_avail_out, 0); + rb_define_method(cZStream, "avail_out=", rb_zstream_set_avail_out, 1); rb_define_method(cZStream, "avail_in", rb_zstream_avail_in, 0); rb_define_method(cZStream, "total_in", rb_zstream_total_in, 0); rb_define_method(cZStream, "total_out", rb_zstream_total_out, 0); @@ -941,6 +941,7 @@ rb_io_fread(ptr, len, f) ptr += c; if ((n -= c) <= 0) break; } + rb_thread_wait_fd(fileno(f)); TRAP_BEG; c = getc(f); TRAP_END; @@ -1014,7 +1015,6 @@ read_all(fptr, siz, str) long bytes = 0; long n; - READ_CHECK(fptr->f); if (siz == 0) siz = BUFSIZ; if (NIL_P(str)) { str = rb_tainted_str_new(0, siz); @@ -1024,7 +1024,10 @@ read_all(fptr, siz, str) rb_str_resize(str, siz); } for (;;) { + FL_SET(str, FL_FREEZE); + READ_CHECK(fptr->f); n = rb_io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f); + FL_UNSET(str, FL_FREEZE); if (n == 0 && bytes == 0) { rb_str_resize(str,0); if (!fptr->f) break; @@ -1359,7 +1362,7 @@ swallow(fptr, term) static VALUE rb_io_getline_fast(fptr, delim) OpenFile *fptr; - int delim; + unsigned char delim; { VALUE str = Qnil; int c; @@ -1375,6 +1378,17 @@ rb_io_getline_fast(fptr, delim) return str; } +static int +rscheck(rsptr, rslen, rs) + char *rsptr; + long rslen; + VALUE rs; +{ + if (RSTRING(rs)->ptr != rsptr && RSTRING(rs)->len != rslen) + rb_raise(rb_eRuntimeError, "rs modified"); + return 1; +} + static VALUE rb_io_getline(rs, fptr) VALUE rs; @@ -1414,6 +1428,7 @@ rb_io_getline(rs, fptr) while ((c = appendline(fptr, newline, &str)) != EOF && (c != newline || RSTRING(str)->len < rslen || + (rspara || rscheck(rsptr,rslen,rs)) || memcmp(RSTRING(str)->ptr+RSTRING(str)->len-rslen,rsptr,rslen))); if (rspara) { @@ -2372,6 +2387,9 @@ rb_io_modenum_flags(mode) if (mode & O_APPEND) { flags |= FMODE_APPEND; } + if (mode & O_CREAT) { + flags |= FMODE_CREATE; + } #ifdef O_BINARY if (mode & O_BINARY) { flags |= FMODE_BINMODE; @@ -2883,7 +2901,7 @@ rb_io_popen(str, argc, argv, klass) mode = rb_io_modenum_mode(FIX2INT(pmode)); } else { - mode = StringValuePtr(pmode); + mode = rb_io_flags_mode(rb_io_mode_flags(StringValuePtr(pmode))); } SafeStringValue(pname); port = pipe_open(0, 0, str, mode); @@ -4232,7 +4250,7 @@ next_argv() if (binmode) rb_io_binmode(current_file); } else { - init_p = 0; + next_p = 1; return Qfalse; } } @@ -5192,7 +5210,6 @@ argf_read(argc, argv) retry: if (!next_argv()) { - if (NIL_P(str)) return rb_str_new(0,0); return str; } if (TYPE(current_file) != T_FILE) { diff --git a/lib/cgi/session/pstore.rb b/lib/cgi/session/pstore.rb index 033acc3249..e2727b5c5e 100644 --- a/lib/cgi/session/pstore.rb +++ b/lib/cgi/session/pstore.rb @@ -76,11 +76,7 @@ class CGI def restore unless @hash @p.transaction do - begin - @hash = @p['hash'] - rescue - @hash = {} - end + @hash = @p['hash'] || {} end end @hash diff --git a/lib/delegate.rb b/lib/delegate.rb index 5a97393239..c6f8f5d946 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -75,6 +75,11 @@ class SimpleDelegator<Delegator def __setobj__(obj) @_sd_obj = obj end + + def initialize_copy(obj) + super + __setobj__(obj.__getobj__.clone) + end end # backward compatibility ^_^;;; @@ -103,6 +108,10 @@ def DelegateClass(superclass) def __setobj__(obj) @_dc_obj = obj end + def initialize_copy(obj) + super + __setobj__(obj.__getobj__.clone) + end } for method in methods begin diff --git a/lib/tempfile.rb b/lib/tempfile.rb index 6eb11beb0b..828e1cf8f3 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -116,7 +116,8 @@ class Tempfile < DelegateClass(File) begin File.unlink(@tmpname) if File.exist?(@tmpname) @@cleanlist.delete(@tmpname) - @tmpname = nil + @data = @tmpname = nil + ObjectSpace.undefine_finalizer(self) rescue Errno::EACCESS # may not be able to unlink on Windows; just ignore end diff --git a/lib/xsd/charset.rb b/lib/xsd/charset.rb index 362f13edfc..e0241fdebc 100644 --- a/lib/xsd/charset.rb +++ b/lib/xsd/charset.rb @@ -103,7 +103,7 @@ public end def Charset.charset_str(label) - CharsetMap.index(label.downcase) + CharsetMap.key(label.downcase) end # us_ascii = '[\x00-\x7F]' @@ -1050,8 +1050,8 @@ rb_false(obj) */ static VALUE -rb_obj_pattern_match(obj) - VALUE obj; +rb_obj_pattern_match(obj1, obj2) + VALUE obj1, obj2; { return Qfalse; } @@ -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; } /* @@ -366,13 +363,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; } /* @@ -552,49 +548,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, @@ -705,7 +663,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("<=>"); @@ -1750,7 +1750,7 @@ rb_reg_initialize_m(argc, argv, self) s = StringValuePtr(argv[0]); len = RSTRING(argv[0])->len; } - rb_reg_initialize(self, s, len, flags); + rb_reg_initialize(self, s, len, flags, Qtrue); return self; } @@ -2025,7 +2025,7 @@ rb_reg_init_copy(copy, re) } rb_reg_check(re); rb_reg_initialize(copy, RREGEXP(re)->str, RREGEXP(re)->len, - rb_reg_options(re)); + rb_reg_options(re), Qfalse); return copy; } @@ -1420,6 +1420,7 @@ rb_str_upto(beg, end, excl) current = rb_funcall(current, succ, 0, 0); StringValue(current); if (excl && rb_str_equal(current, end)) break; + StringValue(current); if (RSTRING(current)->len > RSTRING(end)->len) break; } |