diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | array.c | 30 | ||||
-rw-r--r-- | lib/open3.rb | 39 |
3 files changed, 52 insertions, 31 deletions
@@ -1,12 +1,16 @@ -Fri Oct 20 07:56:23 2000 Yukihiro Matsumoto <matz@ruby-lang.org> +Wed Oct 25 12:30:19 2000 Yukihiro Matsumoto <matz@ruby-lang.org> - * eval.c (rb_eval): ARGSPUSH should not modify args array. + * array.c (rb_ary_concat): replacing array might be the receiver + itself. do not call rb_ary_push_m. -Wed Oct 18 03:10:20 2000 Yukihiro Matsumoto <matz@ruby-lang.org> + * array.c (rb_ary_replace): replacing array might be the receiver + itself. use memmove. - * stable version 1.6.2 released. +Fri Oct 20 07:56:23 2000 Yukihiro Matsumoto <matz@ruby-lang.org> + + * eval.c (rb_eval): ARGSPUSH should not modify args array. -Thu Oct 19 16:51:46 2000 Yukihiro Matsumoto <matz@ruby-lang.org> +Thu Oct 19 14:58:17 2000 WATANABE Tetsuya <tetsu@jpn.hp.com> * pack.c (NUM2U32): should use NUM2ULONG(). @@ -288,8 +288,9 @@ rb_ary_push_m(argc, argv, ary) /* make rooms by copying the last item */ rb_ary_store(ary, len + argc, argv[argc]); - if (argc) /* if any rest */ + if (argc) { /* if any rest */ MEMCPY(RARRAY(ary)->ptr + len, argv, VALUE, argc); + } } return ary; } @@ -531,6 +532,8 @@ rb_ary_replace(ary, beg, len, rpl) VALUE ary, rpl; long beg, len; { + int rlen; + if (len < 0) rb_raise(rb_eIndexError, "negative length %d", len); if (beg < 0) { beg += RARRAY(ary)->len; @@ -549,16 +552,17 @@ rb_ary_replace(ary, beg, len, rpl) else if (TYPE(rpl) != T_ARRAY) { rpl = rb_ary_new3(1, rpl); } + rlen = RARRAY(rpl)->len; rb_ary_modify(ary); if (beg >= RARRAY(ary)->len) { - len = beg + RARRAY(rpl)->len; + len = beg + rlen; if (len >= RARRAY(ary)->capa) { RARRAY(ary)->capa=len; REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa); } rb_mem_clear(RARRAY(ary)->ptr+RARRAY(ary)->len, beg-RARRAY(ary)->len); - MEMCPY(RARRAY(ary)->ptr+beg, RARRAY(rpl)->ptr, VALUE, RARRAY(rpl)->len); + MEMCPY(RARRAY(ary)->ptr+beg, RARRAY(rpl)->ptr, VALUE, rlen); RARRAY(ary)->len = len; } else { @@ -568,18 +572,18 @@ rb_ary_replace(ary, beg, len, rpl) len = RARRAY(ary)->len - beg; } - alen = RARRAY(ary)->len + RARRAY(rpl)->len - len; + alen = RARRAY(ary)->len + rlen - len; if (alen >= RARRAY(ary)->capa) { RARRAY(ary)->capa=alen; REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa); } if (len != RARRAY(rpl)->len) { - MEMMOVE(RARRAY(ary)->ptr+beg+RARRAY(rpl)->len, RARRAY(ary)->ptr+beg+len, + MEMMOVE(RARRAY(ary)->ptr+beg+rlen, RARRAY(ary)->ptr+beg+len, VALUE, RARRAY(ary)->len-(beg+len)); RARRAY(ary)->len = alen; } - MEMCPY(RARRAY(ary)->ptr+beg, RARRAY(rpl)->ptr, VALUE, RARRAY(rpl)->len); + MEMMOVE(RARRAY(ary)->ptr+beg, RARRAY(rpl)->ptr, VALUE, rlen); } } @@ -1250,9 +1254,19 @@ VALUE rb_ary_concat(x, y) VALUE x, y; { + int xlen = RARRAY(x)->len; + int ylen; + y = to_ary(y); - if (RARRAY(y)->len > 0) { - rb_ary_push_m(RARRAY(y)->len, RARRAY(y)->ptr, x); + ylen = RARRAY(y)->len; + if (ylen > 0) { + rb_ary_modify(x); + if (xlen + ylen > RARRAY(x)->capa) { + RARRAY(x)->capa = xlen + ylen; + REALLOC_N(RARRAY(x)->ptr, VALUE, RARRAY(x)->capa); + } + MEMCPY(RARRAY(x)->ptr+xlen, RARRAY(y)->ptr, VALUE, ylen); + RARRAY(x)->len = xlen + ylen; } return x; } diff --git a/lib/open3.rb b/lib/open3.rb index 11b9813bee..18984f5726 100644 --- a/lib/open3.rb +++ b/lib/open3.rb @@ -9,39 +9,42 @@ module Open3 #[stdin, stdout, stderr] = popen3(command); - def popen3(cmd) + def popen3(*cmd) pw = IO::pipe # pipe[0] for read, pipe[1] for write pr = IO::pipe pe = IO::pipe pid = fork{ # child - pw[1].close - STDIN.reopen(pw[0]) - pw[0].close + fork{ + # grandchild + pw[1].close + STDIN.reopen(pw[0]) + pw[0].close - pr[0].close - STDOUT.reopen(pr[1]) - pr[1].close + pr[0].close + STDOUT.reopen(pr[1]) + pr[1].close - pe[0].close - STDERR.reopen(pe[1]) - pe[1].close + pe[0].close + STDERR.reopen(pe[1]) + pe[1].close - exec(cmd) - _exit 127 + exec(*cmd) + } } pw[0].close pr[1].close pe[1].close - Thread.start do - sleep 1 - Process.waitpid(pid) - end - pi = [ pw[1], pr[0], pe[0] ] + Process.waitpid(pid) + pi = [pw[1], pr[0], pe[0]] if defined? yield - return yield *pi + begin + return yield *pi + ensure + pi.each{|p| p.close unless p.closed?} + end end pi end |