From f84f4aa6b375290386c0456ac02fe8f6cc2cdd2d Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 16 May 2001 09:05:54 +0000 Subject: * array.c (rb_ary_and): should not push frozen key string. * array.c (rb_ary_or): ditto. * eval.c (rb_thread_schedule): should save context before raising deadlock, saved context for current thread might be obsolete. * time.c (make_time_t): non DST timezone shift supported (hopefully). * time.c (make_time_t): strict range detection for negative time_t. * signal.c: SIGINFO added. * eval.c (rb_ensure): should not SEGV when prot_tag is NULL. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 23 ++++++++++++++++++++ array.c | 64 ++++++++++++++++++++++++++++++------------------------- dir.c | 3 +-- dln.c | 1 + eval.c | 17 +++++++++++++-- ext/md5/md5init.c | 1 + hash.c | 2 -- intern.h | 1 + io.c | 5 +---- lib/open3.rb | 1 + lib/thread.rb | 39 ++++++++++++++++++++------------- object.c | 1 + parse.y | 1 + process.c | 1 - re.c | 6 +----- signal.c | 3 +++ st.c | 2 +- string.c | 18 ++++++++-------- time.c | 23 +++++++++++++++----- version.h | 4 ++-- 20 files changed, 139 insertions(+), 77 deletions(-) diff --git a/ChangeLog b/ChangeLog index bef717e95a..2f8c3bae0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +Tue May 15 17:46:37 2001 Yukihiro Matsumoto + + * array.c (rb_ary_and): should not push frozen key string. + + * array.c (rb_ary_or): ditto. + +Mon May 14 13:50:22 2001 Yukihiro Matsumoto + + * eval.c (rb_thread_schedule): should save context before raising + deadlock, saved context for current thread might be obsolete. + + * time.c (make_time_t): non DST timezone shift supported (hopefully). + + * time.c (make_time_t): strict range detection for negative time_t. + +Mon May 14 11:54:20 2001 Tanaka Akira + + * signal.c: SIGINFO added. + +Mon May 14 08:57:06 2001 Yukihiro Matsumoto + + * eval.c (rb_ensure): should not SEGV when prot_tag is NULL. + Sun May 13 23:51:14 2001 Usaku Nakamura * win32/resource.rb: Modify copyright in resource script. diff --git a/array.c b/array.c index 4d6a96ef1c..1d63a9fa2b 100644 --- a/array.c +++ b/array.c @@ -739,11 +739,26 @@ inspect_join(ary, arg) return rb_ary_join(arg[0], arg[1]); } +static long +str_cpy(str, idx, str2) + VALUE str; + long idx; + VALUE str2; +{ + long len = idx + RSTRING(str2)->len; + + if (RSTRING(str)->len < len) { + rb_str_resize(str, len); + } + memcpy(RSTRING(str)->ptr+idx, RSTRING(str2)->ptr, RSTRING(str2)->len); + return len; +} + VALUE rb_ary_join(ary, sep) VALUE ary, sep; { - long i; + long len, i, j; int taint = 0; VALUE result, tmp; @@ -751,30 +766,21 @@ rb_ary_join(ary, sep) if (OBJ_TAINTED(ary)) taint = 1; if (OBJ_TAINTED(sep)) taint = 1; - tmp = RARRAY(ary)->ptr[0]; - if (OBJ_TAINTED(tmp)) taint = 1; - switch (TYPE(tmp)) { - case T_STRING: - result = rb_str_dup(tmp); - break; - case T_ARRAY: - if (rb_inspecting_p(tmp)) { - result = rb_str_new2("[...]"); + len = 1; + for (i=0; ilen; i++) { + if (TYPE(RARRAY(ary)->ptr[i]) == T_STRING) { + len += RSTRING(RARRAY(ary)->ptr[i])->len; } else { - VALUE args[2]; - - args[0] = tmp; - args[1] = sep; - result = rb_protect_inspect(inspect_join, ary, (VALUE)args); + len += 10; } - break; - default: - result = rb_str_dup(rb_obj_as_string(tmp)); - break; } + if (!NIL_P(sep) && TYPE(sep) == T_STRING) { + len += RSTRING(sep)->len * RARRAY(ary)->len - 1; + } + result = rb_str_new(0, len); - for (i=1; ilen; i++) { + for (i=0, j=0; ilen; i++) { tmp = RARRAY(ary)->ptr[i]; switch (TYPE(tmp)) { case T_STRING: @@ -794,10 +800,11 @@ rb_ary_join(ary, sep) default: tmp = rb_obj_as_string(tmp); } - if (!NIL_P(sep)) rb_str_append(result, sep); - rb_str_append(result, tmp); + if (i > 0 && !NIL_P(sep)) j = str_cpy(result, j, sep); + j = str_cpy(result, j, tmp); if (OBJ_TAINTED(tmp)) taint = 1; } + rb_str_resize(result, j); if (taint) OBJ_TAINT(result); return result; @@ -1291,8 +1298,6 @@ VALUE rb_ary_concat(x, y) VALUE x, y; { - long ylen; - y = to_ary(y); if (RARRAY(y)->len > 0) { rb_ary_update(x, RARRAY(x)->len, 0, y); @@ -1498,7 +1503,7 @@ rb_ary_and(ary1, ary2) for (i=0; ilen; i++) { VALUE v = RARRAY(ary1)->ptr[i]; if (st_delete(RHASH(hash)->tbl, &v, 0)) { - rb_ary_push(ary3, v); + rb_ary_push(ary3, RARRAY(ary1)->ptr[i]); } } @@ -1520,13 +1525,13 @@ rb_ary_or(ary1, ary2) for (i=0; ilen; i++) { v = RARRAY(ary1)->ptr[i]; if (st_delete(RHASH(hash)->tbl, &v, 0)) { - rb_ary_push(ary3, v); + rb_ary_push(ary3, RARRAY(ary1)->ptr[i]); } } for (i=0; ilen; i++) { v = RARRAY(ary2)->ptr[i]; if (st_delete(RHASH(hash)->tbl, &v, 0)) { - rb_ary_push(ary3, v); + rb_ary_push(ary3, RARRAY(ary2)->ptr[i]); } } @@ -1548,10 +1553,11 @@ rb_ary_uniq_bang(ary) p = q = RARRAY(ary)->ptr; end = p + RARRAY(ary)->len; while (p < end) { - VALUE v = *p++; + VALUE v = *p; if (st_delete(RHASH(hash)->tbl, &v, 0)) { - *q++ = v; + *q++ = *p; } + p++; } RARRAY(ary)->len = (q - RARRAY(ary)->ptr); diff --git a/dir.c b/dir.c index a49b244756..f53d7a1ca1 100644 --- a/dir.c +++ b/dir.c @@ -598,8 +598,7 @@ remove_backslashes(p) while (p < pend) { if (*p == '\\') { - *p++; - if (p == pend) break; + if (++p == pend) break; } *t++ = *p++; } diff --git a/dln.c b/dln.c index d9bacb78c4..36f416a010 100644 --- a/dln.c +++ b/dln.c @@ -1501,6 +1501,7 @@ dln_load(file) failed: rb_loaderror("%s - %s", dln_strerror(), file); #endif + return 0; /* dummy return */ } static char *dln_find_1(); diff --git a/eval.c b/eval.c index 5e6d4d0d46..383f266e7d 100644 --- a/eval.c +++ b/eval.c @@ -4004,9 +4004,9 @@ rb_ensure(b_proc, data1, e_proc, data2) result = (*b_proc)(data1); } POP_TAG(); - retval = prot_tag->retval; /* save retval */ + retval = prot_tag ? prot_tag->retval : Qnil; /* save retval */ (*e_proc)(data2); - return_value(retval); + if (prot_tag) return_value(retval); if (state) JUMP_TAG(state); return result; @@ -7551,6 +7551,7 @@ rb_thread_schedule() next->gid = 0; rb_thread_ready(next); next->status = THREAD_TO_KILL; + rb_thread_save_context(curr_thread); rb_thread_deadlock(); } next->wait_for = 0; @@ -8338,8 +8339,20 @@ rb_thread_stop_p(thread) static void rb_thread_wait_other_threads() { + rb_thread_t th; + int found; + /* wait other threads to terminate */ while (curr_thread != curr_thread->next) { + found = 0; + FOREACH_THREAD(th) { + if (th != curr_thread && th->status != THREAD_STOPPED) { + found = 1; + break; + } + } + END_FOREACH(th); + if (!found) return; rb_thread_schedule(); } } diff --git a/ext/md5/md5init.c b/ext/md5/md5init.c index 64bba9dab3..d6a4a55535 100644 --- a/ext/md5/md5init.c +++ b/ext/md5/md5init.c @@ -103,6 +103,7 @@ Init_md5() rb_define_singleton_method(cMD5, "md5", md5i_new, -1); rb_define_method(cMD5, "update", md5i_update, 1); + rb_define_method(cMD5, "<<", md5i_update, 1); rb_define_method(cMD5, "digest", md5i_digest, 0); rb_define_method(cMD5, "hexdigest", md5i_hexdigest, 0); rb_define_method(cMD5, "clone", md5i_clone, 0); diff --git a/hash.c b/hash.c index bb7cf77d11..61400c0b17 100644 --- a/hash.c +++ b/hash.c @@ -893,7 +893,6 @@ rb_f_getenv(obj, name) VALUE obj, name; { char *nam, *env; - int len; StringValue(name); nam = RSTRING(name)->ptr; @@ -1105,7 +1104,6 @@ rb_f_setenv(obj, nm, val) VALUE obj, nm, val; { char *name, *value; - int nlen, vlen; if (rb_safe_level() >= 4) { rb_raise(rb_eSecurityError, "cannot change environment variable"); diff --git a/intern.h b/intern.h index f88a8bb69a..a5e3565c41 100644 --- a/intern.h +++ b/intern.h @@ -327,6 +327,7 @@ VALUE rb_str_concat _((VALUE, VALUE)); int rb_str_hash _((VALUE)); int rb_str_cmp _((VALUE, VALUE)); VALUE rb_str_upto _((VALUE, VALUE, int)); +void rb_str_update _((VALUE, long, long, VALUE)); VALUE rb_str_inspect _((VALUE)); VALUE rb_str_split _((VALUE, const char*)); void rb_str_associate _((VALUE, VALUE)); diff --git a/io.c b/io.c index 65704591b9..bd7d91957a 100644 --- a/io.c +++ b/io.c @@ -344,8 +344,6 @@ rb_io_seek_m(argc, argv, io) { VALUE offset, ptrname; int whence; - OpenFile *fptr; - long pos; rb_scan_args(argc, argv, "11", &offset, &ptrname); if (argc == 1) whence = SEEK_SET; @@ -1959,7 +1957,6 @@ static VALUE rb_io_clone(io) VALUE io; { - VALUE klass; OpenFile *fptr, *orig; int fd; char *mode; @@ -3082,7 +3079,7 @@ rb_io_s_pipe() { #ifndef __human68k__ int pipes[2]; - VALUE r, w, ary; + VALUE r, w; #ifdef NT if (_pipe(pipes, 1024, O_BINARY) == -1) diff --git a/lib/open3.rb b/lib/open3.rb index 58de740393..33701bbfc0 100644 --- a/lib/open3.rb +++ b/lib/open3.rb @@ -32,6 +32,7 @@ module Open3 exec(*cmd) } + exit! } pw[0].close diff --git a/lib/thread.rb b/lib/thread.rb index 559cd95a8a..34db9c3d46 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -3,6 +3,7 @@ # $Date$ # by Yukihiro Matsumoto # +# Copyright (C) 2001 Yukihiro Matsumoto # Copyright (C) 2000 Network Applied Communication Laboratory, Inc. # Copyright (C) 2000 Information-technology Promotion Agency, Japan # @@ -74,7 +75,10 @@ class Mutex retry end Thread.critical = false - t.run if t + begin + t.run if t + rescue ThreadError + end self end @@ -160,17 +164,19 @@ class Queue ensure Thread.critical = false end - t.run if t - end - def enq(obj) - push(obj) + begin + t.run if t + rescue ThreadError + end end + alias << push + alias enq push def pop(non_block=false) Thread.critical = true begin loop do - if @que.length == 0 + if @que.empty? if non_block raise ThreadError, "queue empty" end @@ -184,17 +190,15 @@ class Queue Thread.critical = false end end - def shift(non_block=false) - pop(non_block) - end - alias deq shift + alias shift pop + alias deq pop def empty? - @que.length == 0 + @que.empty? end def clear - @que.replace([]) + @que.clear end def length @@ -223,7 +227,7 @@ class SizedQueue= @max + if max <= @max @max = max Thread.critical = false else @@ -251,8 +255,10 @@ class SizedQueue #include +#include VALUE rb_mKernel; VALUE rb_cObject; diff --git a/parse.y b/parse.y index 3b58fd6874..3021565888 100644 --- a/parse.y +++ b/parse.y @@ -19,6 +19,7 @@ #include "st.h" #include #include +#include #define ID_SCOPE_SHIFT 3 #define ID_SCOPE_MASK 0x07 diff --git a/process.c b/process.c index f8d715f66d..0051d358b1 100644 --- a/process.c +++ b/process.c @@ -716,7 +716,6 @@ rb_f_exec(argc, argv) VALUE *argv; { VALUE prog = 0; - int i; if (argc == 0) { rb_raise(rb_eArgError, "wrong # of arguments"); diff --git a/re.c b/re.c index aa9f1b4cdc..92e0420f50 100644 --- a/re.c +++ b/re.c @@ -11,6 +11,7 @@ #include "ruby.h" #include "re.h" +#include static VALUE rb_eRegexpError; @@ -776,9 +777,6 @@ match_aref(argc, argv, match) VALUE match; { VALUE idx, rest; - struct re_registers *regs; - char *ptr; - int i; rb_scan_args(argc, argv, "11", &idx, &rest); @@ -1103,8 +1101,6 @@ static int rb_reg_get_kcode(re) VALUE re; { - int kcode; - switch (RBASIC(re)->flags & KCODE_MASK) { case KCODE_NONE: return 16; diff --git a/signal.c b/signal.c index 0582da3b73..2b1e99a17a 100644 --- a/signal.c +++ b/signal.c @@ -162,6 +162,9 @@ static struct signals { #endif #ifdef SIGSOUND "SOUND", SIGSOUND, +#endif +#ifdef SIGINFO + "INFO", SIGINFO, #endif NULL, 0, }; diff --git a/st.c b/st.c index 86d569717b..625a4c59be 100644 --- a/st.c +++ b/st.c @@ -112,7 +112,7 @@ static int new_size(size) int size; { - int i, newsize; + int i; #if 1 for (i=3; i<31; i++) { diff --git a/string.c b/string.c index 0706318361..660fa0c509 100644 --- a/string.c +++ b/string.c @@ -428,14 +428,16 @@ rb_str_resize(str, len) VALUE str; long len; { - rb_str_modify(str); + if (len != RSTRING(str)->len) { + rb_str_modify(str); - if (len >= 0) { - if (RSTRING(str)->len < len || RSTRING(str)->len - len > 1024) { - REALLOC_N(RSTRING(str)->ptr, char, len + 1); + if (len >= 0) { + if (RSTRING(str)->len < len || RSTRING(str)->len - len > 1024) { + REALLOC_N(RSTRING(str)->ptr, char, len + 1); + } + RSTRING(str)->len = len; + RSTRING(str)->ptr[len] = '\0'; /* sentinel */ } - RSTRING(str)->len = len; - RSTRING(str)->ptr[len] = '\0'; /* sentinel */ } return str; } @@ -956,7 +958,7 @@ rb_str_aref_m(argc, argv, str) return rb_str_aref(str, argv[0]); } -static void +void rb_str_update(str, beg, len, val) VALUE str; long beg; @@ -1515,9 +1517,7 @@ VALUE rb_str_inspect(str) VALUE str; { - long len; char *p, *pend; - char *q, *qend; VALUE result = rb_str_new2("\""); char s[5]; diff --git a/time.c b/time.c index 8e79080380..dd3b6eb666 100644 --- a/time.c +++ b/time.c @@ -328,8 +328,6 @@ make_time_t(tptr, utc_p) guess += (tptr->tm_sec - tm->tm_sec); #ifndef NEGATIVE_TIME_T if (guess < 0) goto out_of_range; -#else - if (oguess > 365 * 24 * 3600 && guess < 0) goto out_of_range; #endif if (!utc_p) { /* localtime zone adjust */ @@ -362,17 +360,32 @@ make_time_t(tptr, utc_p) tm = localtime(&guess); if (!tm) goto error; if (lt.tm_isdst != tm->tm_isdst || tptr->tm_hour != tm->tm_hour) { - oguess = guess - 3600; - tm = localtime(&oguess); + time_t tmp = guess - 3600; + tm = localtime(&tmp); if (!tm) goto error; if (tptr->tm_hour == tm->tm_hour) { - guess = oguess; + guess = tmp; + } + else if (lt.tm_isdst == tm->tm_isdst) { + tmp = guess + 3600; + tm = localtime(&tmp); + if (!tm) goto error; + if (tptr->tm_hour == tm->tm_hour) { + guess = tmp; + } } } + if (tptr->tm_min != tm->tm_min) { + guess += (tptr->tm_min - tm->tm_min) * 60; + } #ifndef NEGATIVE_TIME_T if (guess < 0) goto out_of_range; #endif } +#ifdef NEGATIVE_TIME_T + if (oguess > 365 * 24 * 3600 && guess < 0) goto out_of_range; + if (guess > 365 * 24 * 3600 && oguess < 0) goto out_of_range; +#endif return guess; diff --git a/version.h b/version.h index 240ddace9f..9512376498 100644 --- a/version.h +++ b/version.h @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.7.0" -#define RUBY_RELEASE_DATE "2001-05-11" +#define RUBY_RELEASE_DATE "2001-05-16" #define RUBY_VERSION_CODE 170 -#define RUBY_RELEASE_CODE 20010511 +#define RUBY_RELEASE_CODE 20010516 -- cgit v1.2.3