1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2004-10-19 10:25:23 +00:00
parent c0700eba8d
commit 1057902ac7
19 changed files with 126 additions and 124 deletions

View file

@ -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> 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] * 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): * lib/webrick/httprequest.rb (WEBrick::HTTPRequest#initialize):
initial value of accpet-* should be array. 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> 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 * 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. * 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> Mon Oct 11 13:48:20 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/*: untabify * 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. * io.c (rb_io_getline): should not treat char as negative value.
[ruby-dev:24460] [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> Fri Oct 8 21:36:56 2004 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb (fu_traverse): return value of Dir.entries is * lib/fileutils.rb (fu_traverse): return value of Dir.entries is

19
dir.c
View file

@ -1403,14 +1403,7 @@ push_pattern(path, ary)
const char *path; const char *path;
VALUE ary; VALUE ary;
{ {
VALUE str = rb_tainted_str_new2(path); rb_ary_push(ary, rb_tainted_str_new2(path));
if (!NIL_P(ary)) {
rb_ary_push(ary, str);
}
else {
rb_yield(str);
}
} }
static int static int
@ -1478,13 +1471,9 @@ rb_push_glob(str, flags) /* '\0' is delimiter */
const char *p, *pend; const char *p, *pend;
VALUE ary; VALUE ary;
if (rb_block_given_p())
ary = Qnil;
else
ary = rb_ary_new();
FilePathValue(str); FilePathValue(str);
ary = rb_ary_new();
p = RSTRING(str)->ptr; p = RSTRING(str)->ptr;
pend = p + RSTRING(str)->len; pend = p + RSTRING(str)->len;
@ -1497,6 +1486,10 @@ rb_push_glob(str, flags) /* '\0' is delimiter */
else p++; else p++;
} }
if (rb_block_given_p()) {
rb_ary_each(ary);
return Qnil;
}
return ary; return ary;
} }

31
enum.c
View file

@ -117,11 +117,8 @@ enum_find(argc, argv, obj)
rb_scan_args(argc, argv, "01", &if_none); rb_scan_args(argc, argv, "01", &if_none);
rb_iterate(rb_each, obj, find_i, (VALUE)memo); rb_iterate(rb_each, obj, find_i, (VALUE)memo);
if (memo->u2.value) { if (memo->u2.value) {
VALUE result = memo->u1.value; return memo->u1.value;
rb_gc_force_recycle((VALUE)memo);
return result;
} }
rb_gc_force_recycle((VALUE)memo);
if (!NIL_P(if_none)) { if (!NIL_P(if_none)) {
return rb_funcall(if_none, rb_intern("call"), 0, 0); 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); rb_iterate(rb_each, obj, inject_i, (VALUE)memo);
n = memo->u1.value; n = memo->u1.value;
rb_gc_force_recycle((VALUE)memo);
return n; return n;
} }
@ -401,17 +397,14 @@ sort_by_i(i, ary)
return Qnil; return Qnil;
} }
static VALUE static int
sort_by_cmp(values, ary) sort_by_cmp(aa, bb)
VALUE values, ary; NODE **aa, **bb;
{ {
NODE *a = (NODE*)RARRAY(values)->ptr[0]; VALUE a = aa[0]->u1.value;
NODE *b = (NODE*)RARRAY(values)->ptr[1]; VALUE b = bb[0]->u1.value;
/* pedantic check; they must be memo nodes */ return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b);
Check_Type(a, T_NODE);
Check_Type(b, T_NODE);
return rb_funcall(a->u1.value, id_cmp, 1, b->u1.value);
} }
/* /*
@ -499,7 +492,7 @@ enum_sort_by(obj)
RBASIC(ary)->klass = 0; RBASIC(ary)->klass = 0;
rb_iterate(rb_each, obj, sort_by_i, ary); rb_iterate(rb_each, obj, sort_by_i, ary);
if (RARRAY(ary)->len > 1) { 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++) { for (i=0; i<RARRAY(ary)->len; i++) {
RARRAY(ary)->ptr[i] = RNODE(RARRAY(ary)->ptr[i])->u2.value; RARRAY(ary)->ptr[i] = RNODE(RARRAY(ary)->ptr[i])->u2.value;
@ -559,7 +552,6 @@ enum_all(obj)
memo->u1.value = Qtrue; memo->u1.value = Qtrue;
rb_iterate(rb_each, obj, rb_block_given_p() ? all_iter_i : all_i, (VALUE)memo); rb_iterate(rb_each, obj, rb_block_given_p() ? all_iter_i : all_i, (VALUE)memo);
result = memo->u1.value; result = memo->u1.value;
rb_gc_force_recycle((VALUE)memo);
return result; return result;
} }
@ -615,7 +607,6 @@ enum_any(obj)
memo->u1.value = Qfalse; memo->u1.value = Qfalse;
rb_iterate(rb_each, obj, rb_block_given_p() ? any_iter_i : any_i, (VALUE)memo); rb_iterate(rb_each, obj, rb_block_given_p() ? any_iter_i : any_i, (VALUE)memo);
result = memo->u1.value; result = memo->u1.value;
rb_gc_force_recycle((VALUE)memo);
return result; return result;
} }
@ -681,7 +672,6 @@ enum_min(obj)
rb_iterate(rb_each, obj, rb_block_given_p() ? min_ii : min_i, (VALUE)memo); rb_iterate(rb_each, obj, rb_block_given_p() ? min_ii : min_i, (VALUE)memo);
result = memo->u1.value; result = memo->u1.value;
rb_gc_force_recycle((VALUE)memo);
return result; return result;
} }
@ -746,7 +736,6 @@ enum_max(obj)
rb_iterate(rb_each, obj, rb_block_given_p() ? max_ii : max_i, (VALUE)memo); rb_iterate(rb_each, obj, rb_block_given_p() ? max_ii : max_i, (VALUE)memo);
result = memo->u1.value; result = memo->u1.value;
rb_gc_force_recycle((VALUE)memo);
return result; return result;
} }
@ -789,7 +778,6 @@ enum_min_by(obj)
rb_iterate(rb_each, obj, min_by_i, (VALUE)memo); rb_iterate(rb_each, obj, min_by_i, (VALUE)memo);
result = memo->u2.value; result = memo->u2.value;
rb_gc_force_recycle((VALUE)memo);
return result; return result;
} }
@ -832,7 +820,6 @@ enum_max_by(obj)
rb_iterate(rb_each, obj, max_by_i, (VALUE)memo); rb_iterate(rb_each, obj, max_by_i, (VALUE)memo);
result = memo->u2.value; result = memo->u2.value;
rb_gc_force_recycle((VALUE)memo);
return result; return result;
} }
@ -870,7 +857,6 @@ enum_member(obj, val)
rb_iterate(rb_each, obj, member_i, (VALUE)memo); rb_iterate(rb_each, obj, member_i, (VALUE)memo);
result = memo->u2.value; result = memo->u2.value;
rb_gc_force_recycle((VALUE)memo);
return result; return result;
} }
@ -906,7 +892,6 @@ enum_each_with_index(obj)
NODE *memo = rb_node_newnode(NODE_MEMO, 0, 0, 0); NODE *memo = rb_node_newnode(NODE_MEMO, 0, 0, 0);
rb_iterate(rb_each, obj, each_with_index_i, (VALUE)memo); rb_iterate(rb_each, obj, each_with_index_i, (VALUE)memo);
rb_gc_force_recycle((VALUE)memo);
return obj; return obj;
} }

6
eval.c
View file

@ -8264,7 +8264,7 @@ proc_eq(self, other)
*/ */
static VALUE static VALUE
proc_hash(self, other) proc_hash(self)
VALUE self; VALUE self;
{ {
struct BLOCK *data; struct BLOCK *data;
@ -8288,8 +8288,8 @@ proc_hash(self, other)
*/ */
static VALUE static VALUE
proc_to_s(self, other) proc_to_s(self)
VALUE self, other; VALUE self;
{ {
struct BLOCK *data; struct BLOCK *data;
NODE *node; NODE *node;

View file

@ -579,7 +579,7 @@ BigDecimal_ge(VALUE self, VALUE r)
} }
static VALUE static VALUE
BigDecimal_neg(VALUE self, VALUE r) BigDecimal_neg(VALUE self)
{ {
ENTER(5); ENTER(5);
Real *c, *a; Real *c, *a;

View file

@ -734,7 +734,7 @@ Init_dbm()
rb_define_method(rb_cDBM, "[]=", fdbm_store, 2); rb_define_method(rb_cDBM, "[]=", fdbm_store, 2);
rb_define_method(rb_cDBM, "store", 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, "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, "values_at", fdbm_values_at, -1);
rb_define_method(rb_cDBM, "length", fdbm_length, 0); rb_define_method(rb_cDBM, "length", fdbm_length, 0);
rb_define_method(rb_cDBM, "size", fdbm_length, 0); rb_define_method(rb_cDBM, "size", fdbm_length, 0);

View file

@ -70,7 +70,6 @@ enum_each_slice(obj, n)
ary = memo->u1.value; ary = memo->u1.value;
if (RARRAY(ary)->len > 0) rb_yield(ary); if (RARRAY(ary)->len > 0) rb_yield(ary);
rb_gc_force_recycle((VALUE)memo);
return Qnil; return Qnil;
} }
@ -114,7 +113,6 @@ enum_each_cons(obj, n)
rb_iterate(rb_each, obj, each_cons_i, (VALUE)memo); rb_iterate(rb_each, obj, each_cons_i, (VALUE)memo);
rb_gc_force_recycle((VALUE)memo);
return Qnil; return Qnil;
} }
@ -163,7 +161,6 @@ enumerator_each(obj)
rb_to_id(rb_ivar_get(obj, id_enum_method)), rb_to_id(rb_ivar_get(obj, id_enum_method)),
rb_ivar_get(obj, id_enum_args)); rb_ivar_get(obj, id_enum_args));
val = rb_iterate((VALUE (*)_((VALUE)))enumerator_iter, obj, rb_yield, 0); val = rb_iterate((VALUE (*)_((VALUE)))enumerator_iter, obj, rb_yield, 0);
rb_gc_force_recycle(obj);
return val; return val;
} }

View file

@ -2217,27 +2217,25 @@ sock_s_getservbyaname(argc, argv)
int argc; int argc;
VALUE *argv; VALUE *argv;
{ {
VALUE service, protocol; VALUE service, proto;
char *proto;
struct servent *sp; struct servent *sp;
int port; int port;
rb_scan_args(argc, argv, "11", &service, &protocol); rb_scan_args(argc, argv, "11", &service, &proto);
if (NIL_P(protocol)) proto = "tcp"; if (NIL_P(proto)) proto = rb_str_new2("tcp");
else proto = StringValuePtr(protocol); else StringValue(proto);
StringValue(service); sp = getservbyname((char*)RSTRING(service)->ptr, RSTRING(proto)->ptr);
sp = getservbyname((char*)RSTRING(service)->ptr, proto);
if (sp) { if (sp) {
port = ntohs(sp->s_port); port = ntohs(sp->s_port);
} }
else { else {
char *s = RSTRING(service)->ptr; char *s = StringValuePtr(service);
char *end; char *end;
port = strtoul(s, &end, 0); port = strtoul(s, &end, 0);
if (*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); return INT2FIX(port);

View file

@ -2758,7 +2758,7 @@ static VALUE
fole_get_methods( self ) fole_get_methods( self )
VALUE 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 ) fole_put_methods( self )
VALUE 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 ) fole_func_methods( self )
VALUE self; VALUE self;
{ {
return ole_methods( self, INVOKE_FUNC); return ole_methods(self, INVOKE_FUNC);
} }
/* /*

View file

@ -439,6 +439,7 @@ zstream_expand_buffer(z)
z->buf_filled = 0; z->buf_filled = 0;
z->stream.next_out = RSTRING(z->buf)->ptr; z->stream.next_out = RSTRING(z->buf)->ptr;
z->stream.avail_out = ZSTREAM_INITIAL_BUFSIZE; z->stream.avail_out = ZSTREAM_INITIAL_BUFSIZE;
RBASIC(z->buf)->klass = 0;
return; return;
} }
@ -3380,7 +3381,7 @@ void Init_zlib()
cZStream = rb_define_class_under(mZlib, "ZStream", rb_cObject); cZStream = rb_define_class_under(mZlib, "ZStream", rb_cObject);
rb_undef_alloc_func(cZStream); rb_undef_alloc_func(cZStream);
rb_define_method(cZStream, "avail_out", rb_zstream_avail_out, 0); 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, "avail_in", rb_zstream_avail_in, 0);
rb_define_method(cZStream, "total_in", rb_zstream_total_in, 0); rb_define_method(cZStream, "total_in", rb_zstream_total_in, 0);
rb_define_method(cZStream, "total_out", rb_zstream_total_out, 0); rb_define_method(cZStream, "total_out", rb_zstream_total_out, 0);

27
io.c
View file

@ -941,6 +941,7 @@ rb_io_fread(ptr, len, f)
ptr += c; ptr += c;
if ((n -= c) <= 0) break; if ((n -= c) <= 0) break;
} }
rb_thread_wait_fd(fileno(f));
TRAP_BEG; TRAP_BEG;
c = getc(f); c = getc(f);
TRAP_END; TRAP_END;
@ -1014,7 +1015,6 @@ read_all(fptr, siz, str)
long bytes = 0; long bytes = 0;
long n; long n;
READ_CHECK(fptr->f);
if (siz == 0) siz = BUFSIZ; if (siz == 0) siz = BUFSIZ;
if (NIL_P(str)) { if (NIL_P(str)) {
str = rb_tainted_str_new(0, siz); str = rb_tainted_str_new(0, siz);
@ -1024,7 +1024,10 @@ read_all(fptr, siz, str)
rb_str_resize(str, siz); rb_str_resize(str, siz);
} }
for (;;) { for (;;) {
FL_SET(str, FL_FREEZE);
READ_CHECK(fptr->f);
n = rb_io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f); n = rb_io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f);
FL_UNSET(str, FL_FREEZE);
if (n == 0 && bytes == 0) { if (n == 0 && bytes == 0) {
rb_str_resize(str,0); rb_str_resize(str,0);
if (!fptr->f) break; if (!fptr->f) break;
@ -1359,7 +1362,7 @@ swallow(fptr, term)
static VALUE static VALUE
rb_io_getline_fast(fptr, delim) rb_io_getline_fast(fptr, delim)
OpenFile *fptr; OpenFile *fptr;
int delim; unsigned char delim;
{ {
VALUE str = Qnil; VALUE str = Qnil;
int c; int c;
@ -1375,6 +1378,17 @@ rb_io_getline_fast(fptr, delim)
return str; 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 static VALUE
rb_io_getline(rs, fptr) rb_io_getline(rs, fptr)
VALUE rs; VALUE rs;
@ -1414,6 +1428,7 @@ rb_io_getline(rs, fptr)
while ((c = appendline(fptr, newline, &str)) != EOF && while ((c = appendline(fptr, newline, &str)) != EOF &&
(c != newline || RSTRING(str)->len < rslen || (c != newline || RSTRING(str)->len < rslen ||
(rspara || rscheck(rsptr,rslen,rs)) ||
memcmp(RSTRING(str)->ptr+RSTRING(str)->len-rslen,rsptr,rslen))); memcmp(RSTRING(str)->ptr+RSTRING(str)->len-rslen,rsptr,rslen)));
if (rspara) { if (rspara) {
@ -2372,6 +2387,9 @@ rb_io_modenum_flags(mode)
if (mode & O_APPEND) { if (mode & O_APPEND) {
flags |= FMODE_APPEND; flags |= FMODE_APPEND;
} }
if (mode & O_CREAT) {
flags |= FMODE_CREATE;
}
#ifdef O_BINARY #ifdef O_BINARY
if (mode & O_BINARY) { if (mode & O_BINARY) {
flags |= FMODE_BINMODE; flags |= FMODE_BINMODE;
@ -2883,7 +2901,7 @@ rb_io_popen(str, argc, argv, klass)
mode = rb_io_modenum_mode(FIX2INT(pmode)); mode = rb_io_modenum_mode(FIX2INT(pmode));
} }
else { else {
mode = StringValuePtr(pmode); mode = rb_io_flags_mode(rb_io_mode_flags(StringValuePtr(pmode)));
} }
SafeStringValue(pname); SafeStringValue(pname);
port = pipe_open(0, 0, str, mode); port = pipe_open(0, 0, str, mode);
@ -4232,7 +4250,7 @@ next_argv()
if (binmode) rb_io_binmode(current_file); if (binmode) rb_io_binmode(current_file);
} }
else { else {
init_p = 0; next_p = 1;
return Qfalse; return Qfalse;
} }
} }
@ -5192,7 +5210,6 @@ argf_read(argc, argv)
retry: retry:
if (!next_argv()) { if (!next_argv()) {
if (NIL_P(str)) return rb_str_new(0,0);
return str; return str;
} }
if (TYPE(current_file) != T_FILE) { if (TYPE(current_file) != T_FILE) {

View file

@ -76,11 +76,7 @@ class CGI
def restore def restore
unless @hash unless @hash
@p.transaction do @p.transaction do
begin @hash = @p['hash'] || {}
@hash = @p['hash']
rescue
@hash = {}
end
end end
end end
@hash @hash

View file

@ -75,6 +75,11 @@ class SimpleDelegator<Delegator
def __setobj__(obj) def __setobj__(obj)
@_sd_obj = obj @_sd_obj = obj
end end
def initialize_copy(obj)
super
__setobj__(obj.__getobj__.clone)
end
end end
# backward compatibility ^_^;;; # backward compatibility ^_^;;;
@ -103,6 +108,10 @@ def DelegateClass(superclass)
def __setobj__(obj) def __setobj__(obj)
@_dc_obj = obj @_dc_obj = obj
end end
def initialize_copy(obj)
super
__setobj__(obj.__getobj__.clone)
end
} }
for method in methods for method in methods
begin begin

View file

@ -116,7 +116,8 @@ class Tempfile < DelegateClass(File)
begin begin
File.unlink(@tmpname) if File.exist?(@tmpname) File.unlink(@tmpname) if File.exist?(@tmpname)
@@cleanlist.delete(@tmpname) @@cleanlist.delete(@tmpname)
@tmpname = nil @data = @tmpname = nil
ObjectSpace.undefine_finalizer(self)
rescue Errno::EACCESS rescue Errno::EACCESS
# may not be able to unlink on Windows; just ignore # may not be able to unlink on Windows; just ignore
end end

View file

@ -103,7 +103,7 @@ public
end end
def Charset.charset_str(label) def Charset.charset_str(label)
CharsetMap.index(label.downcase) CharsetMap.key(label.downcase)
end end
# us_ascii = '[\x00-\x7F]' # us_ascii = '[\x00-\x7F]'

View file

@ -1050,8 +1050,8 @@ rb_false(obj)
*/ */
static VALUE static VALUE
rb_obj_pattern_match(obj) rb_obj_pattern_match(obj1, obj2)
VALUE obj; VALUE obj1, obj2;
{ {
return Qfalse; return Qfalse;
} }

60
range.c
View file

@ -230,13 +230,10 @@ str_step(args)
return rb_str_upto(args[0], args[1], EXCL(args[2])); return rb_str_upto(args[0], args[1], EXCL(args[2]));
} }
#define RANGE_EACH_BREAK Qfalse
#define RANGE_EACH_CONTINUE Qtrue
static void static void
range_each_func(range, func, v, e, arg) range_each_func(range, func, v, e, arg)
VALUE range; VALUE range;
VALUE (*func) _((VALUE, void*)); void (*func) _((VALUE, void*));
VALUE v, e; VALUE v, e;
void *arg; void *arg;
{ {
@ -244,13 +241,13 @@ range_each_func(range, func, v, e, arg)
if (EXCL(range)) { if (EXCL(range)) {
while (r_lt(v, e)) { while (r_lt(v, e)) {
if ((*func)(v, arg) == RANGE_EACH_BREAK) break; (*func)(v, arg);
v = rb_funcall(v, id_succ, 0, 0); v = rb_funcall(v, id_succ, 0, 0);
} }
} }
else { else {
while (RTEST(c = r_le(v, e))) { while (RTEST(c = r_le(v, e))) {
if ((*func)(v, arg) == RANGE_EACH_BREAK) break; (*func)(v, arg);
if (c == INT2FIX(0)) break; if (c == INT2FIX(0)) break;
v = rb_funcall(v, id_succ, 0, 0); v = rb_funcall(v, id_succ, 0, 0);
} }
@ -267,7 +264,7 @@ step_i(i, iter)
rb_yield(i); rb_yield(i);
iter[0] = iter[1]; iter[0] = iter[1];
} }
return RANGE_EACH_CONTINUE; return Qnil;
} }
/* /*
@ -366,13 +363,12 @@ range_step(argc, argv, range)
return range; return range;
} }
static VALUE static void
each_i(v, arg) each_i(v, arg)
VALUE v; VALUE v;
void *arg; void *arg;
{ {
rb_yield(v); rb_yield(v);
return RANGE_EACH_CONTINUE;
} }
/* /*
@ -552,49 +548,11 @@ range_inspect(range)
return str; 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: * 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 * Returns <code>true</code> if <i>obj</i> is an element of
* <i>rng</i>, <code>false</code> otherwise. Conveniently, * <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, "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); rb_define_method(rb_cRange, "include?", range_include, 1);
id_cmp = rb_intern("<=>"); id_cmp = rb_intern("<=>");

4
re.c
View file

@ -1750,7 +1750,7 @@ rb_reg_initialize_m(argc, argv, self)
s = StringValuePtr(argv[0]); s = StringValuePtr(argv[0]);
len = RSTRING(argv[0])->len; len = RSTRING(argv[0])->len;
} }
rb_reg_initialize(self, s, len, flags); rb_reg_initialize(self, s, len, flags, Qtrue);
return self; return self;
} }
@ -2025,7 +2025,7 @@ rb_reg_init_copy(copy, re)
} }
rb_reg_check(re); rb_reg_check(re);
rb_reg_initialize(copy, RREGEXP(re)->str, RREGEXP(re)->len, rb_reg_initialize(copy, RREGEXP(re)->str, RREGEXP(re)->len,
rb_reg_options(re)); rb_reg_options(re), Qfalse);
return copy; return copy;
} }

View file

@ -1420,6 +1420,7 @@ rb_str_upto(beg, end, excl)
current = rb_funcall(current, succ, 0, 0); current = rb_funcall(current, succ, 0, 0);
StringValue(current); StringValue(current);
if (excl && rb_str_equal(current, end)) break; if (excl && rb_str_equal(current, end)) break;
StringValue(current);
if (RSTRING(current)->len > RSTRING(end)->len) if (RSTRING(current)->len > RSTRING(end)->len)
break; break;
} }