diff --git a/ChangeLog b/ChangeLog index 0e03811a04..e26bd51541 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Tue Oct 19 17:24:11 2004 Yukihiro Matsumoto + + * 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 * 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 * lib/webrick/httprequest.rb (WEBrick::HTTPRequest#initialize): initial value of accpet-* should be array. +Mon Oct 18 00:42:45 2004 Yukihiro Matsumoto + + * 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 * 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 * io.c (MODE_BINMODE, MODE_BINARY): fixed reversed condition. +Mon Oct 11 17:51:34 2004 Yukihiro Matsumoto + + * 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 * ext/tk/lib/tk/*: untabify @@ -144,6 +185,11 @@ Sat Oct 9 19:50:36 2004 Nobuyoshi Nakada * io.c (rb_io_getline): should not treat char as negative value. [ruby-dev:24460] +Sat Oct 9 00:25:39 2004 Tanaka Akira + + * io.c (rb_io_fread): rb_thread_wait_fd() was lost. + [ruby-dev:24457] + Fri Oct 8 21:36:56 2004 Minero Aoki * lib/fileutils.rb (fu_traverse): return value of Dir.entries is diff --git a/dir.c b/dir.c index 76f61ab222..4e3eb256fe 100644 --- a/dir.c +++ b/dir.c @@ -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; } diff --git a/enum.c b/enum.c index 66b9263c85..bcb62c418a 100644 --- a/enum.c +++ b/enum.c @@ -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; ilen; 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; } diff --git a/eval.c b/eval.c index 64e06c8830..c044f7d8a3 100644 --- a/eval.c +++ b/eval.c @@ -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); diff --git a/io.c b/io.c index e1acaca1a8..f01aa01498 100644 --- a/io.c +++ b/io.c @@ -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 true or false - * - * Return +true+ if _val_ is one of the values in _rng_ (that is if - * Range#each 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 true if obj is an element of * rng, false 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("<=>"); diff --git a/re.c b/re.c index ee5433015f..8427535be4 100644 --- a/re.c +++ b/re.c @@ -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; } diff --git a/string.c b/string.c index 3d3573a554..af2354708e 100644 --- a/string.c +++ b/string.c @@ -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; }