* 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
This commit is contained in:
matz 2001-05-16 09:05:54 +00:00
Родитель 59d82a928a
Коммит f84f4aa6b3
20 изменённых файлов: 139 добавлений и 77 удалений

Просмотреть файл

@ -1,3 +1,26 @@
Tue May 15 17:46:37 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* 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 <akr@m17n.org>
* signal.c: SIGINFO added.
Mon May 14 08:57:06 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_ensure): should not SEGV when prot_tag is NULL.
Sun May 13 23:51:14 2001 Usaku Nakamura <usa@osb.att.ne.jp> Sun May 13 23:51:14 2001 Usaku Nakamura <usa@osb.att.ne.jp>
* win32/resource.rb: Modify copyright in resource script. * win32/resource.rb: Modify copyright in resource script.

64
array.c
Просмотреть файл

@ -739,11 +739,26 @@ inspect_join(ary, arg)
return rb_ary_join(arg[0], arg[1]); 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 VALUE
rb_ary_join(ary, sep) rb_ary_join(ary, sep)
VALUE ary, sep; VALUE ary, sep;
{ {
long i; long len, i, j;
int taint = 0; int taint = 0;
VALUE result, tmp; VALUE result, tmp;
@ -751,30 +766,21 @@ rb_ary_join(ary, sep)
if (OBJ_TAINTED(ary)) taint = 1; if (OBJ_TAINTED(ary)) taint = 1;
if (OBJ_TAINTED(sep)) taint = 1; if (OBJ_TAINTED(sep)) taint = 1;
tmp = RARRAY(ary)->ptr[0]; len = 1;
if (OBJ_TAINTED(tmp)) taint = 1; for (i=0; i<RARRAY(ary)->len; i++) {
switch (TYPE(tmp)) { if (TYPE(RARRAY(ary)->ptr[i]) == T_STRING) {
case T_STRING: len += RSTRING(RARRAY(ary)->ptr[i])->len;
result = rb_str_dup(tmp);
break;
case T_ARRAY:
if (rb_inspecting_p(tmp)) {
result = rb_str_new2("[...]");
} }
else { else {
VALUE args[2]; len += 10;
args[0] = tmp;
args[1] = sep;
result = rb_protect_inspect(inspect_join, ary, (VALUE)args);
} }
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; i<RARRAY(ary)->len; i++) { for (i=0, j=0; i<RARRAY(ary)->len; i++) {
tmp = RARRAY(ary)->ptr[i]; tmp = RARRAY(ary)->ptr[i];
switch (TYPE(tmp)) { switch (TYPE(tmp)) {
case T_STRING: case T_STRING:
@ -794,10 +800,11 @@ rb_ary_join(ary, sep)
default: default:
tmp = rb_obj_as_string(tmp); tmp = rb_obj_as_string(tmp);
} }
if (!NIL_P(sep)) rb_str_append(result, sep); if (i > 0 && !NIL_P(sep)) j = str_cpy(result, j, sep);
rb_str_append(result, tmp); j = str_cpy(result, j, tmp);
if (OBJ_TAINTED(tmp)) taint = 1; if (OBJ_TAINTED(tmp)) taint = 1;
} }
rb_str_resize(result, j);
if (taint) OBJ_TAINT(result); if (taint) OBJ_TAINT(result);
return result; return result;
@ -1291,8 +1298,6 @@ VALUE
rb_ary_concat(x, y) rb_ary_concat(x, y)
VALUE x, y; VALUE x, y;
{ {
long ylen;
y = to_ary(y); y = to_ary(y);
if (RARRAY(y)->len > 0) { if (RARRAY(y)->len > 0) {
rb_ary_update(x, RARRAY(x)->len, 0, y); rb_ary_update(x, RARRAY(x)->len, 0, y);
@ -1498,7 +1503,7 @@ rb_ary_and(ary1, ary2)
for (i=0; i<RARRAY(ary1)->len; i++) { for (i=0; i<RARRAY(ary1)->len; i++) {
VALUE v = RARRAY(ary1)->ptr[i]; VALUE v = RARRAY(ary1)->ptr[i];
if (st_delete(RHASH(hash)->tbl, &v, 0)) { 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; i<RARRAY(ary1)->len; i++) { for (i=0; i<RARRAY(ary1)->len; i++) {
v = RARRAY(ary1)->ptr[i]; v = RARRAY(ary1)->ptr[i];
if (st_delete(RHASH(hash)->tbl, &v, 0)) { if (st_delete(RHASH(hash)->tbl, &v, 0)) {
rb_ary_push(ary3, v); rb_ary_push(ary3, RARRAY(ary1)->ptr[i]);
} }
} }
for (i=0; i<RARRAY(ary2)->len; i++) { for (i=0; i<RARRAY(ary2)->len; i++) {
v = RARRAY(ary2)->ptr[i]; v = RARRAY(ary2)->ptr[i];
if (st_delete(RHASH(hash)->tbl, &v, 0)) { 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; p = q = RARRAY(ary)->ptr;
end = p + RARRAY(ary)->len; end = p + RARRAY(ary)->len;
while (p < end) { while (p < end) {
VALUE v = *p++; VALUE v = *p;
if (st_delete(RHASH(hash)->tbl, &v, 0)) { if (st_delete(RHASH(hash)->tbl, &v, 0)) {
*q++ = v; *q++ = *p;
} }
p++;
} }
RARRAY(ary)->len = (q - RARRAY(ary)->ptr); RARRAY(ary)->len = (q - RARRAY(ary)->ptr);

3
dir.c
Просмотреть файл

@ -598,8 +598,7 @@ remove_backslashes(p)
while (p < pend) { while (p < pend) {
if (*p == '\\') { if (*p == '\\') {
*p++; if (++p == pend) break;
if (p == pend) break;
} }
*t++ = *p++; *t++ = *p++;
} }

1
dln.c
Просмотреть файл

@ -1501,6 +1501,7 @@ dln_load(file)
failed: failed:
rb_loaderror("%s - %s", dln_strerror(), file); rb_loaderror("%s - %s", dln_strerror(), file);
#endif #endif
return 0; /* dummy return */
} }
static char *dln_find_1(); static char *dln_find_1();

17
eval.c
Просмотреть файл

@ -4004,9 +4004,9 @@ rb_ensure(b_proc, data1, e_proc, data2)
result = (*b_proc)(data1); result = (*b_proc)(data1);
} }
POP_TAG(); POP_TAG();
retval = prot_tag->retval; /* save retval */ retval = prot_tag ? prot_tag->retval : Qnil; /* save retval */
(*e_proc)(data2); (*e_proc)(data2);
return_value(retval); if (prot_tag) return_value(retval);
if (state) JUMP_TAG(state); if (state) JUMP_TAG(state);
return result; return result;
@ -7551,6 +7551,7 @@ rb_thread_schedule()
next->gid = 0; next->gid = 0;
rb_thread_ready(next); rb_thread_ready(next);
next->status = THREAD_TO_KILL; next->status = THREAD_TO_KILL;
rb_thread_save_context(curr_thread);
rb_thread_deadlock(); rb_thread_deadlock();
} }
next->wait_for = 0; next->wait_for = 0;
@ -8338,8 +8339,20 @@ rb_thread_stop_p(thread)
static void static void
rb_thread_wait_other_threads() rb_thread_wait_other_threads()
{ {
rb_thread_t th;
int found;
/* wait other threads to terminate */ /* wait other threads to terminate */
while (curr_thread != curr_thread->next) { 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(); rb_thread_schedule();
} }
} }

Просмотреть файл

@ -103,6 +103,7 @@ Init_md5()
rb_define_singleton_method(cMD5, "md5", md5i_new, -1); rb_define_singleton_method(cMD5, "md5", md5i_new, -1);
rb_define_method(cMD5, "update", md5i_update, 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, "digest", md5i_digest, 0);
rb_define_method(cMD5, "hexdigest", md5i_hexdigest, 0); rb_define_method(cMD5, "hexdigest", md5i_hexdigest, 0);
rb_define_method(cMD5, "clone", md5i_clone, 0); rb_define_method(cMD5, "clone", md5i_clone, 0);

2
hash.c
Просмотреть файл

@ -893,7 +893,6 @@ rb_f_getenv(obj, name)
VALUE obj, name; VALUE obj, name;
{ {
char *nam, *env; char *nam, *env;
int len;
StringValue(name); StringValue(name);
nam = RSTRING(name)->ptr; nam = RSTRING(name)->ptr;
@ -1105,7 +1104,6 @@ rb_f_setenv(obj, nm, val)
VALUE obj, nm, val; VALUE obj, nm, val;
{ {
char *name, *value; char *name, *value;
int nlen, vlen;
if (rb_safe_level() >= 4) { if (rb_safe_level() >= 4) {
rb_raise(rb_eSecurityError, "cannot change environment variable"); rb_raise(rb_eSecurityError, "cannot change environment variable");

Просмотреть файл

@ -327,6 +327,7 @@ VALUE rb_str_concat _((VALUE, VALUE));
int rb_str_hash _((VALUE)); int rb_str_hash _((VALUE));
int rb_str_cmp _((VALUE, VALUE)); int rb_str_cmp _((VALUE, VALUE));
VALUE rb_str_upto _((VALUE, VALUE, int)); VALUE rb_str_upto _((VALUE, VALUE, int));
void rb_str_update _((VALUE, long, long, VALUE));
VALUE rb_str_inspect _((VALUE)); VALUE rb_str_inspect _((VALUE));
VALUE rb_str_split _((VALUE, const char*)); VALUE rb_str_split _((VALUE, const char*));
void rb_str_associate _((VALUE, VALUE)); void rb_str_associate _((VALUE, VALUE));

5
io.c
Просмотреть файл

@ -344,8 +344,6 @@ rb_io_seek_m(argc, argv, io)
{ {
VALUE offset, ptrname; VALUE offset, ptrname;
int whence; int whence;
OpenFile *fptr;
long pos;
rb_scan_args(argc, argv, "11", &offset, &ptrname); rb_scan_args(argc, argv, "11", &offset, &ptrname);
if (argc == 1) whence = SEEK_SET; if (argc == 1) whence = SEEK_SET;
@ -1959,7 +1957,6 @@ static VALUE
rb_io_clone(io) rb_io_clone(io)
VALUE io; VALUE io;
{ {
VALUE klass;
OpenFile *fptr, *orig; OpenFile *fptr, *orig;
int fd; int fd;
char *mode; char *mode;
@ -3082,7 +3079,7 @@ rb_io_s_pipe()
{ {
#ifndef __human68k__ #ifndef __human68k__
int pipes[2]; int pipes[2];
VALUE r, w, ary; VALUE r, w;
#ifdef NT #ifdef NT
if (_pipe(pipes, 1024, O_BINARY) == -1) if (_pipe(pipes, 1024, O_BINARY) == -1)

Просмотреть файл

@ -32,6 +32,7 @@ module Open3
exec(*cmd) exec(*cmd)
} }
exit!
} }
pw[0].close pw[0].close

Просмотреть файл

@ -3,6 +3,7 @@
# $Date$ # $Date$
# by Yukihiro Matsumoto <matz@netlab.co.jp> # by Yukihiro Matsumoto <matz@netlab.co.jp>
# #
# Copyright (C) 2001 Yukihiro Matsumoto
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc. # Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
# Copyright (C) 2000 Information-technology Promotion Agency, Japan # Copyright (C) 2000 Information-technology Promotion Agency, Japan
# #
@ -74,7 +75,10 @@ class Mutex
retry retry
end end
Thread.critical = false Thread.critical = false
t.run if t begin
t.run if t
rescue ThreadError
end
self self
end end
@ -160,17 +164,19 @@ class Queue
ensure ensure
Thread.critical = false Thread.critical = false
end end
t.run if t begin
end t.run if t
def enq(obj) rescue ThreadError
push(obj) end
end end
alias << push
alias enq push
def pop(non_block=false) def pop(non_block=false)
Thread.critical = true Thread.critical = true
begin begin
loop do loop do
if @que.length == 0 if @que.empty?
if non_block if non_block
raise ThreadError, "queue empty" raise ThreadError, "queue empty"
end end
@ -184,17 +190,15 @@ class Queue
Thread.critical = false Thread.critical = false
end end
end end
def shift(non_block=false) alias shift pop
pop(non_block) alias deq pop
end
alias deq shift
def empty? def empty?
@que.length == 0 @que.empty?
end end
def clear def clear
@que.replace([]) @que.clear
end end
def length def length
@ -223,7 +227,7 @@ class SizedQueue<Queue
def max=(max) def max=(max)
Thread.critical = true Thread.critical = true
if max >= @max if max <= @max
@max = max @max = max
Thread.critical = false Thread.critical = false
else else
@ -251,8 +255,10 @@ class SizedQueue<Queue
end end
super super
end end
alias << push
def pop(*args) def pop(*args)
retval = super
Thread.critical = true Thread.critical = true
if @que.length < @max if @que.length < @max
begin begin
@ -263,9 +269,12 @@ class SizedQueue<Queue
ensure ensure
Thread.critical = false Thread.critical = false
end end
t.run if t begin
t.run if t
rescue ThreadError
end
end end
super retval
end end
def num_waiting def num_waiting

Просмотреть файл

@ -16,6 +16,7 @@
#include "st.h" #include "st.h"
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <ctype.h>
VALUE rb_mKernel; VALUE rb_mKernel;
VALUE rb_cObject; VALUE rb_cObject;

Просмотреть файл

@ -19,6 +19,7 @@
#include "st.h" #include "st.h"
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <ctype.h>
#define ID_SCOPE_SHIFT 3 #define ID_SCOPE_SHIFT 3
#define ID_SCOPE_MASK 0x07 #define ID_SCOPE_MASK 0x07

Просмотреть файл

@ -716,7 +716,6 @@ rb_f_exec(argc, argv)
VALUE *argv; VALUE *argv;
{ {
VALUE prog = 0; VALUE prog = 0;
int i;
if (argc == 0) { if (argc == 0) {
rb_raise(rb_eArgError, "wrong # of arguments"); rb_raise(rb_eArgError, "wrong # of arguments");

6
re.c
Просмотреть файл

@ -11,6 +11,7 @@
#include "ruby.h" #include "ruby.h"
#include "re.h" #include "re.h"
#include <ctype.h>
static VALUE rb_eRegexpError; static VALUE rb_eRegexpError;
@ -776,9 +777,6 @@ match_aref(argc, argv, match)
VALUE match; VALUE match;
{ {
VALUE idx, rest; VALUE idx, rest;
struct re_registers *regs;
char *ptr;
int i;
rb_scan_args(argc, argv, "11", &idx, &rest); rb_scan_args(argc, argv, "11", &idx, &rest);
@ -1103,8 +1101,6 @@ static int
rb_reg_get_kcode(re) rb_reg_get_kcode(re)
VALUE re; VALUE re;
{ {
int kcode;
switch (RBASIC(re)->flags & KCODE_MASK) { switch (RBASIC(re)->flags & KCODE_MASK) {
case KCODE_NONE: case KCODE_NONE:
return 16; return 16;

Просмотреть файл

@ -162,6 +162,9 @@ static struct signals {
#endif #endif
#ifdef SIGSOUND #ifdef SIGSOUND
"SOUND", SIGSOUND, "SOUND", SIGSOUND,
#endif
#ifdef SIGINFO
"INFO", SIGINFO,
#endif #endif
NULL, 0, NULL, 0,
}; };

2
st.c
Просмотреть файл

@ -112,7 +112,7 @@ static int
new_size(size) new_size(size)
int size; int size;
{ {
int i, newsize; int i;
#if 1 #if 1
for (i=3; i<31; i++) { for (i=3; i<31; i++) {

Просмотреть файл

@ -428,14 +428,16 @@ rb_str_resize(str, len)
VALUE str; VALUE str;
long len; long len;
{ {
rb_str_modify(str); if (len != RSTRING(str)->len) {
rb_str_modify(str);
if (len >= 0) { if (len >= 0) {
if (RSTRING(str)->len < len || RSTRING(str)->len - len > 1024) { if (RSTRING(str)->len < len || RSTRING(str)->len - len > 1024) {
REALLOC_N(RSTRING(str)->ptr, char, len + 1); 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; return str;
} }
@ -956,7 +958,7 @@ rb_str_aref_m(argc, argv, str)
return rb_str_aref(str, argv[0]); return rb_str_aref(str, argv[0]);
} }
static void void
rb_str_update(str, beg, len, val) rb_str_update(str, beg, len, val)
VALUE str; VALUE str;
long beg; long beg;
@ -1515,9 +1517,7 @@ VALUE
rb_str_inspect(str) rb_str_inspect(str)
VALUE str; VALUE str;
{ {
long len;
char *p, *pend; char *p, *pend;
char *q, *qend;
VALUE result = rb_str_new2("\""); VALUE result = rb_str_new2("\"");
char s[5]; char s[5];

23
time.c
Просмотреть файл

@ -328,8 +328,6 @@ make_time_t(tptr, utc_p)
guess += (tptr->tm_sec - tm->tm_sec); guess += (tptr->tm_sec - tm->tm_sec);
#ifndef NEGATIVE_TIME_T #ifndef NEGATIVE_TIME_T
if (guess < 0) goto out_of_range; if (guess < 0) goto out_of_range;
#else
if (oguess > 365 * 24 * 3600 && guess < 0) goto out_of_range;
#endif #endif
if (!utc_p) { /* localtime zone adjust */ if (!utc_p) { /* localtime zone adjust */
@ -362,17 +360,32 @@ make_time_t(tptr, utc_p)
tm = localtime(&guess); tm = localtime(&guess);
if (!tm) goto error; if (!tm) goto error;
if (lt.tm_isdst != tm->tm_isdst || tptr->tm_hour != tm->tm_hour) { if (lt.tm_isdst != tm->tm_isdst || tptr->tm_hour != tm->tm_hour) {
oguess = guess - 3600; time_t tmp = guess - 3600;
tm = localtime(&oguess); tm = localtime(&tmp);
if (!tm) goto error; if (!tm) goto error;
if (tptr->tm_hour == tm->tm_hour) { 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 #ifndef NEGATIVE_TIME_T
if (guess < 0) goto out_of_range; if (guess < 0) goto out_of_range;
#endif #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; return guess;

Просмотреть файл

@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.0" #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_VERSION_CODE 170
#define RUBY_RELEASE_CODE 20010511 #define RUBY_RELEASE_CODE 20010516