* eval.c (rb_eval): pre-evaluate argument for unambiguous

evaluation order.  [ruby-dev:26383]

* lib/delegate.rb (Delegator::method_missing): forward unknown
  method to the destination.  suggested by
  <christophe.poucet@gmail.com>.  [ruby-talk:146776]

* process.c (detach_process_watcher): terminate process watcher
  thread right after rb_waitpid() succeed.  [ruby-talk:146430]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2005-06-30 06:20:09 +00:00
Родитель 00433666fd
Коммит 639bd5e78f
10 изменённых файлов: 104 добавлений и 72 удалений

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

@ -1,3 +1,8 @@
Thu Jun 30 15:13:16 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_eval): pre-evaluate argument for unambiguous
evaluation order. [ruby-dev:26383]
Thu Jun 30 14:48:23 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/net/http.rb (Net::HTTP#connect, Net::HTTP#request): should
@ -7,6 +12,12 @@ Thu Jun 30 14:48:23 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/net/http.rb (Net::HTTP::ProxyDelta#edit_path): should not
send HTTPS scheme URL to origine servers. [ruby-dev:25689]
Thu Jun 30 09:53:56 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/delegate.rb (Delegator::method_missing): forward unknown
method to the destination. suggested by
<christophe.poucet@gmail.com>. [ruby-talk:146776]
Wed Jun 29 00:03:20 2005 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* regparse.c (fetch_token): avoid warning of unused goto tag.
@ -27,6 +38,11 @@ Tue Jun 28 01:52:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf/nkf-utf8/nkf.c: imported Revision 1.69
* ext/nkf/nkf-utf8/utf8tbl.c: imported Revision 1.9
Sat Jun 25 23:30:51 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* process.c (detach_process_watcher): terminate process watcher
thread right after rb_waitpid() succeed. [ruby-talk:146430]
Sat Jun 25 17:12:20 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httputils.rb (WEBrick::HTTPUtils.parse_query): should
@ -201,6 +217,7 @@ Mon Jun 13 13:03:08 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* hash.c (ruby_setenv): fixed SEGV. [ruby-dev:26186]
>>>>>>> 1.4337
Mon Jun 13 01:54:20 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* signal.c (sigexit): call rb_thread_signal_exit() instead of

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

@ -65,10 +65,9 @@ rb_big_clone(x)
return z;
}
/* modify a bignum by 2's complement */
static void
get2comp(x, carry) /* get 2's complement */
VALUE x;
int carry;
get2comp(VALUE x)
{
long i = RBIGNUM(x)->len;
BDIGIT *ds = BDIGITS(x);
@ -81,11 +80,10 @@ get2comp(x, carry) /* get 2's complement */
ds[i++] = BIGLO(num);
num = BIGDN(num);
} while (i < RBIGNUM(x)->len);
if (!carry) return;
if ((ds[RBIGNUM(x)->len-1] & (1<<(BITSPERDIG-1))) == 0) {
if (num != 0) {
REALLOC_N(RBIGNUM(x)->digits, BDIGIT, ++RBIGNUM(x)->len);
ds = BDIGITS(x);
ds[RBIGNUM(x)->len-1] = RBIGNUM(x)->sign ? ~0 : 1;
ds[RBIGNUM(x)->len-1] = 1;
}
}
@ -93,7 +91,7 @@ void
rb_big_2comp(x) /* get 2's complement */
VALUE x;
{
get2comp(x, Qtrue);
get2comp(x);
}
static VALUE
@ -1038,6 +1036,8 @@ rb_big_uminus(x)
return bignorm(z);
}
static VALUE bigadd _((VALUE,VALUE,char));
/*
* call-seq:
* ~big => integer
@ -1055,15 +1055,15 @@ rb_big_neg(x)
VALUE x;
{
VALUE z = rb_big_clone(x);
long i = RBIGNUM(x)->len;
BDIGIT *ds = BDIGITS(z);
long i = RBIGNUM(x)->len;
if (!RBIGNUM(x)->sign) get2comp(z, Qtrue);
if (!RBIGNUM(x)->sign) get2comp(z);
while (i--) {
ds[i] = ~ds[i];
}
RBIGNUM(z)->sign = !RBIGNUM(z)->sign;
if (RBIGNUM(x)->sign) get2comp(z, Qtrue);
if (RBIGNUM(x)->sign) get2comp(z);
return bignorm(z);
}
@ -1655,11 +1655,11 @@ rb_big_and(xx, yy)
}
if (!RBIGNUM(y)->sign) {
y = rb_big_clone(y);
get2comp(y, Qtrue);
get2comp(y);
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
get2comp(x, Qtrue);
get2comp(x);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@ -1684,7 +1684,7 @@ rb_big_and(xx, yy)
for (; i<l2; i++) {
zds[i] = sign?0:ds2[i];
}
if (!RBIGNUM(z)->sign) get2comp(z, Qtrue);
if (!RBIGNUM(z)->sign) get2comp(z);
return bignorm(z);
}
@ -1712,11 +1712,11 @@ rb_big_or(xx, yy)
if (!RBIGNUM(y)->sign) {
y = rb_big_clone(y);
get2comp(y, Qtrue);
get2comp(y);
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
get2comp(x, Qtrue);
get2comp(x);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@ -1741,7 +1741,7 @@ rb_big_or(xx, yy)
for (; i<l2; i++) {
zds[i] = sign?ds2[i]:(BIGRAD-1);
}
if (!RBIGNUM(z)->sign) get2comp(z, Qtrue);
if (!RBIGNUM(z)->sign) get2comp(z);
return bignorm(z);
}
@ -1771,11 +1771,11 @@ rb_big_xor(xx, yy)
if (!RBIGNUM(y)->sign) {
y = rb_big_clone(y);
get2comp(y, Qtrue);
get2comp(y);
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
get2comp(x, Qtrue);
get2comp(x);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@ -1802,7 +1802,7 @@ rb_big_xor(xx, yy)
for (; i<l2; i++) {
zds[i] = sign?ds2[i]:~ds2[i];
}
if (!RBIGNUM(z)->sign) get2comp(z, Qtrue);
if (!RBIGNUM(z)->sign) get2comp(z);
return bignorm(z);
}
@ -1874,7 +1874,7 @@ rb_big_rshift(x, y)
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
get2comp(x, Qtrue);
get2comp(x);
}
xds = BDIGITS(x);
i = RBIGNUM(x)->len; j = i - s1;
@ -1889,7 +1889,7 @@ rb_big_rshift(x, y)
num = BIGUP(xds[i]);
}
if (!RBIGNUM(x)->sign) {
get2comp(z, Qfalse);
get2comp(z);
}
return bignorm(z);
}
@ -1934,7 +1934,7 @@ rb_big_aref(x, y)
if (!RBIGNUM(x)->sign) {
if (s1 >= RBIGNUM(x)->len) return INT2FIX(1);
x = rb_big_clone(x);
get2comp(x, Qtrue);
get2comp(x);
}
else {
if (s1 >= RBIGNUM(x)->len) return INT2FIX(0);

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

@ -3287,9 +3287,11 @@ rb_eval(self, n)
case NODE_DOT2:
case NODE_DOT3:
result = rb_range_new(rb_eval(self, node->nd_beg),
rb_eval(self, node->nd_end),
nd_type(node) == NODE_DOT3);
{
VALUE beg = rb_eval(self, node->nd_beg);
VALUE end = rb_eval(self, node->nd_end);
result = rb_range_new(beg, end, nd_type(node) == NODE_DOT3);
}
break;
case NODE_FLIP2: /* like AWK */

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

@ -1997,7 +1997,7 @@ sys_fail2(s1, s2)
len = RSTRING(s1)->len + RSTRING(s2)->len + 5;
buf = ALLOCA_N(char, len);
snprintf(buf, len, "%s or %s", RSTRING(s1)->ptr, RSTRING(s2)->ptr);
snprintf(buf, len, "(%s, %s)", RSTRING(s1)->ptr, RSTRING(s2)->ptr);
rb_sys_fail(buf);
}

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

@ -49,6 +49,14 @@ class Delegator
end
alias initialize_methods initialize
def method_missing(m, *args)
target = self.__getobj__
unless target.respond_to?(m)
super(m, *args)
end
target.__send__(m, *args)
end
def __getobj__
raise NotImplementedError, "need to define `__getobj__'"
end

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

@ -101,7 +101,6 @@ class Set
if enum.class == self.class
@hash.replace(enum.instance_eval { @hash })
else
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
clear
enum.each { |o| add(o) }
end
@ -254,7 +253,6 @@ class Set
if enum.is_a?(Set)
@hash.update(enum.instance_eval { @hash })
else
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
enum.each { |o| add(o) }
end
@ -264,7 +262,6 @@ class Set
# Deletes every element that appears in the given enumerable object
# and returns self.
def subtract(enum)
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
enum.each { |o| delete(o) }
self
end
@ -272,7 +269,6 @@ class Set
# Returns a new set built by merging the set and the elements of the
# given enumerable object.
def |(enum)
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
dup.merge(enum)
end
alias + | ##
@ -281,7 +277,6 @@ class Set
# Returns a new set built by duplicating the set, removing every
# element that appears in the given enumerable object.
def -(enum)
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
dup.subtract(enum)
end
alias difference - ##
@ -289,7 +284,6 @@ class Set
# Returns a new array containing elements common to the set and the
# given enumerable object.
def &(enum)
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
n = self.class.new
enum.each { |o| n.add(o) if include?(o) }
n
@ -300,7 +294,6 @@ class Set
# and the given enumerable object. (set ^ enum) is equivalent to
# ((set | enum) - (set & enum)).
def ^(enum)
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
n = dup
enum.each { |o| if n.include?(o) then n.delete(o) else n.add(o) end }
n
@ -519,6 +512,7 @@ end
module Enumerable
# Makes a set from the enumerable object with given arguments.
# Needs to +require "set"+ to use this method.
def to_set(klass = Set, *args, &block)
klass.new(self, *args, &block)
end
@ -573,7 +567,6 @@ end
# end
#
# def replace(enum)
# enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
# clear
# enum.each { |o| add(o) }
#
@ -581,7 +574,6 @@ end
# end
#
# def merge(enum)
# enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
# enum.each { |o| add(o) }
#
# self

16
parse.y
Просмотреть файл

@ -56,6 +56,7 @@ int ruby_sourceline; /* current line no. */
enum lex_state_e {
EXPR_BEG, /* ignore newline, +/- is a sign. */
EXPR_END, /* newline significant, +/- is a operator. */
EXPR_END2, /* newline significant, +/- is a operator. */
EXPR_ARG, /* newline significant, +/- is a operator. */
EXPR_CMDARG, /* newline significant, +/- is a operator. */
EXPR_ENDARG, /* newline significant, +/- is a operator. */
@ -5725,6 +5726,7 @@ parser_yylex(parser)
c = nextc();
if (c == '<' &&
lex_state != EXPR_END &&
lex_state != EXPR_END2 &&
lex_state != EXPR_DOT &&
lex_state != EXPR_ENDARG &&
lex_state != EXPR_CLASS &&
@ -5803,7 +5805,9 @@ parser_yylex(parser)
return tSTRING_BEG;
case '?':
if (lex_state == EXPR_END || lex_state == EXPR_ENDARG) {
if (lex_state == EXPR_END ||
lex_state == EXPR_END2 ||
lex_state == EXPR_ENDARG) {
lex_state = EXPR_VALUE;
return '?';
}
@ -6232,7 +6236,8 @@ parser_yylex(parser)
lex_state = EXPR_DOT;
return tCOLON2;
}
if (lex_state == EXPR_END || lex_state == EXPR_ENDARG || ISSPACE(c)) {
if (lex_state == EXPR_END || lex_state == EXPR_END2 ||
lex_state == EXPR_ENDARG || ISSPACE(c)) {
pushback(c);
lex_state = EXPR_BEG;
return ':';
@ -6293,11 +6298,10 @@ parser_yylex(parser)
return '^';
case ';':
if ((c = nextc()) == ';') {
lex_state = EXPR_END;
if (lex_state != EXPR_END2 && peek(';')) {
lex_state = EXPR_END2;
return kEND;
}
pushback(c);
lex_state = EXPR_BEG;
command_start = Qtrue;
return ';';
@ -6363,7 +6367,7 @@ parser_yylex(parser)
return c;
case '{':
if (IS_ARG() || lex_state == EXPR_END)
if (IS_ARG() || lex_state == EXPR_END || lex_state == EXPR_END2)
c = '{'; /* block (primary) */
else if (lex_state == EXPR_ENDARG)
c = tLBRACE_ARG; /* block (expr) */

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

@ -851,7 +851,7 @@ detach_process_watcher(pid_p)
for (;;) {
cpid = rb_waitpid(*pid_p, &status, WNOHANG);
if (cpid == -1) return rb_last_status;
if (cpid != 0) return rb_last_status;
rb_thread_sleep(1);
}
}

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

@ -314,11 +314,11 @@ range_step(argc, argv, range)
if (unit < 0) {
rb_raise(rb_eArgError, "step can't be negative");
}
if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
if (FIXNUM_P(b) && FIXNUM_P(e)) { /* fixnums are special */
long end = FIX2LONG(e);
long i;
if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
if (!EXCL(range)) end += 1;
for (i=FIX2LONG(b); i<end; i+=unit) {
rb_yield(LONG2NUM(i));
@ -332,7 +332,6 @@ range_step(argc, argv, range)
long iter[2];
b = tmp;
if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
args[0] = b; args[1] = e; args[2] = range;
iter[0] = 1; iter[1] = unit;
rb_iterate((VALUE(*)_((VALUE)))str_step, (VALUE)args, step_i,
@ -350,12 +349,10 @@ range_step(argc, argv, range)
else {
long args[2];
if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
if (!rb_respond_to(b, id_succ)) {
rb_raise(rb_eTypeError, "can't iterate from %s",
rb_obj_classname(b));
}
args[0] = 1;
args[1] = unit;
range_each_func(range, step_i, b, e, args);

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

@ -593,6 +593,14 @@ sigexit(sig)
}
#endif
if (trap_list[sig].cmd == 0 && ATOMIC_TEST(rb_trap_immediate)) {
IN_MAIN_CONTEXT(signal_exec, sig);
ATOMIC_SET(rb_trap_immediate, 1);
}
else {
ATOMIC_INC(rb_trap_pending);
ATOMIC_INC(trap_pending_list[sig]);
}
rb_thread_signal_exit();
}
@ -601,39 +609,43 @@ trap(arg)
struct trap_arg *arg;
{
sighandler_t func, oldfunc;
VALUE command, oldcmd;
VALUE command, tmp, oldcmd;
int sig = -1;
char *s;
func = sighandler;
command = arg->cmd;
if (NIL_P(command)) {
if (NIL_P(arg->cmd)) {
func = SIG_IGN;
}
else if (TYPE(command) == T_STRING) {
SafeStringValue(command); /* taint check */
if (RSTRING(command)->len == 0) {
func = SIG_IGN;
}
else if (RSTRING(command)->len == 7) {
if (strncmp(RSTRING(command)->ptr, "SIG_IGN", 7) == 0) {
else {
command = rb_check_string_type(arg->cmd);
if (!NIL_P(command)) {
SafeStringValue(command); /* taint check */
switch (RSTRING(command)->len) {
case 0:
func = SIG_IGN;
}
else if (strncmp(RSTRING(command)->ptr, "SIG_DFL", 7) == 0) {
func = SIG_DFL;
}
else if (strncmp(RSTRING(command)->ptr, "DEFAULT", 7) == 0) {
func = SIG_DFL;
}
}
else if (RSTRING(command)->len == 6) {
if (strncmp(RSTRING(command)->ptr, "IGNORE", 6) == 0) {
func = SIG_IGN;
}
}
else if (RSTRING(command)->len == 4) {
if (strncmp(RSTRING(command)->ptr, "EXIT", 4) == 0) {
func = sigexit;
break;
case 7:
if (strncmp(RSTRING(command)->ptr, "SIG_IGN", 7) == 0) {
func = SIG_IGN;
}
else if (strncmp(RSTRING(command)->ptr, "SIG_DFL", 7) == 0) {
func = SIG_DFL;
}
else if (strncmp(RSTRING(command)->ptr, "DEFAULT", 7) == 0) {
func = SIG_DFL;
}
break;
case 6:
if (strncmp(RSTRING(command)->ptr, "IGNORE", 6) == 0) {
func = SIG_IGN;
}
break;
case 4:
if (strncmp(RSTRING(command)->ptr, "EXIT", 4) == 0) {
func = sigexit;
}
break;
}
}
}