From 639bd5e78fa7d83b44c892afccb99869a886e533 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 30 Jun 2005 06:20:09 +0000 Subject: * 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 . [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 --- ChangeLog | 17 +++++++++++++++ bignum.c | 44 +++++++++++++++++++-------------------- eval.c | 8 +++++--- file.c | 2 +- lib/delegate.rb | 8 ++++++++ lib/set.rb | 10 +-------- parse.y | 16 +++++++++------ process.c | 2 +- range.c | 5 +---- signal.c | 64 ++++++++++++++++++++++++++++++++++----------------------- 10 files changed, 104 insertions(+), 72 deletions(-) diff --git a/ChangeLog b/ChangeLog index 669bcc9600..3698a88d1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Jun 30 15:13:16 2005 Yukihiro Matsumoto + + * eval.c (rb_eval): pre-evaluate argument for unambiguous + evaluation order. [ruby-dev:26383] + Thu Jun 30 14:48:23 2005 GOTOU Yuuzou * lib/net/http.rb (Net::HTTP#connect, Net::HTTP#request): should @@ -7,6 +12,12 @@ Thu Jun 30 14:48:23 2005 GOTOU Yuuzou * 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 + + * lib/delegate.rb (Delegator::method_missing): forward unknown + method to the destination. suggested by + . [ruby-talk:146776] + Wed Jun 29 00:03:20 2005 Kazuhiro NISHIYAMA * regparse.c (fetch_token): avoid warning of unused goto tag. @@ -27,6 +38,11 @@ Tue Jun 28 01:52:00 2005 NARUSE, Yui * 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 + + * 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 * lib/webrick/httputils.rb (WEBrick::HTTPUtils.parse_query): should @@ -201,6 +217,7 @@ Mon Jun 13 13:03:08 2005 Hirokazu Yamamoto * hash.c (ruby_setenv): fixed SEGV. [ruby-dev:26186] +>>>>>>> 1.4337 Mon Jun 13 01:54:20 2005 Yukihiro Matsumoto * signal.c (sigexit): call rb_thread_signal_exit() instead of diff --git a/bignum.c b/bignum.c index ce382ce8a4..f1d26ffd8a 100644 --- a/bignum.c +++ b/bignum.c @@ -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 (; isign) 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 (; isign) 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 (; isign) 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); diff --git a/eval.c b/eval.c index cf7a2be254..442b57bdb2 100644 --- a/eval.c +++ b/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 */ diff --git a/file.c b/file.c index ddaca16b6e..f5a21a2619 100644 --- a/file.c +++ b/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); } diff --git a/lib/delegate.rb b/lib/delegate.rb index 9c89a8cc1a..72b52f3d45 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -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 diff --git a/lib/set.rb b/lib/set.rb index 586a5d9f4d..9e3dac06ed 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -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 diff --git a/parse.y b/parse.y index ee0444d7da..ffd1b18323 100644 --- a/parse.y +++ b/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) */ diff --git a/process.c b/process.c index 12ae0902c3..6e10e7eb35 100644 --- a/process.c +++ b/process.c @@ -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); } } diff --git a/range.c b/range.c index f1ff5a74bb..684db357a8 100644 --- a/range.c +++ b/range.c @@ -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); icmd; - 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) { - 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) { + 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 (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; } } } -- cgit v1.2.3