mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
52a2acbad3
commit
9b5c48abed
3 changed files with 52 additions and 31 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,12 +1,16 @@
|
||||||
|
Wed Oct 25 12:30:19 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* array.c (rb_ary_concat): replacing array might be the receiver
|
||||||
|
itself. do not call rb_ary_push_m.
|
||||||
|
|
||||||
|
* array.c (rb_ary_replace): replacing array might be the receiver
|
||||||
|
itself. use memmove.
|
||||||
|
|
||||||
Fri Oct 20 07:56:23 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Fri Oct 20 07:56:23 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (rb_eval): ARGSPUSH should not modify args array.
|
* eval.c (rb_eval): ARGSPUSH should not modify args array.
|
||||||
|
|
||||||
Wed Oct 18 03:10:20 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Thu Oct 19 14:58:17 2000 WATANABE Tetsuya <tetsu@jpn.hp.com>
|
||||||
|
|
||||||
* stable version 1.6.2 released.
|
|
||||||
|
|
||||||
Thu Oct 19 16:51:46 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
|
|
||||||
|
|
||||||
* pack.c (NUM2U32): should use NUM2ULONG().
|
* pack.c (NUM2U32): should use NUM2ULONG().
|
||||||
|
|
||||||
|
|
30
array.c
30
array.c
|
@ -288,8 +288,9 @@ rb_ary_push_m(argc, argv, ary)
|
||||||
/* make rooms by copying the last item */
|
/* make rooms by copying the last item */
|
||||||
rb_ary_store(ary, len + argc, argv[argc]);
|
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);
|
MEMCPY(RARRAY(ary)->ptr + len, argv, VALUE, argc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
@ -531,6 +532,8 @@ rb_ary_replace(ary, beg, len, rpl)
|
||||||
VALUE ary, rpl;
|
VALUE ary, rpl;
|
||||||
long beg, len;
|
long beg, len;
|
||||||
{
|
{
|
||||||
|
int rlen;
|
||||||
|
|
||||||
if (len < 0) rb_raise(rb_eIndexError, "negative length %d", len);
|
if (len < 0) rb_raise(rb_eIndexError, "negative length %d", len);
|
||||||
if (beg < 0) {
|
if (beg < 0) {
|
||||||
beg += RARRAY(ary)->len;
|
beg += RARRAY(ary)->len;
|
||||||
|
@ -549,16 +552,17 @@ rb_ary_replace(ary, beg, len, rpl)
|
||||||
else if (TYPE(rpl) != T_ARRAY) {
|
else if (TYPE(rpl) != T_ARRAY) {
|
||||||
rpl = rb_ary_new3(1, rpl);
|
rpl = rb_ary_new3(1, rpl);
|
||||||
}
|
}
|
||||||
|
rlen = RARRAY(rpl)->len;
|
||||||
|
|
||||||
rb_ary_modify(ary);
|
rb_ary_modify(ary);
|
||||||
if (beg >= RARRAY(ary)->len) {
|
if (beg >= RARRAY(ary)->len) {
|
||||||
len = beg + RARRAY(rpl)->len;
|
len = beg + rlen;
|
||||||
if (len >= RARRAY(ary)->capa) {
|
if (len >= RARRAY(ary)->capa) {
|
||||||
RARRAY(ary)->capa=len;
|
RARRAY(ary)->capa=len;
|
||||||
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
|
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
|
||||||
}
|
}
|
||||||
rb_mem_clear(RARRAY(ary)->ptr+RARRAY(ary)->len, beg-RARRAY(ary)->len);
|
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;
|
RARRAY(ary)->len = len;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -568,18 +572,18 @@ rb_ary_replace(ary, beg, len, rpl)
|
||||||
len = RARRAY(ary)->len - beg;
|
len = RARRAY(ary)->len - beg;
|
||||||
}
|
}
|
||||||
|
|
||||||
alen = RARRAY(ary)->len + RARRAY(rpl)->len - len;
|
alen = RARRAY(ary)->len + rlen - len;
|
||||||
if (alen >= RARRAY(ary)->capa) {
|
if (alen >= RARRAY(ary)->capa) {
|
||||||
RARRAY(ary)->capa=alen;
|
RARRAY(ary)->capa=alen;
|
||||||
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
|
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len != RARRAY(rpl)->len) {
|
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));
|
VALUE, RARRAY(ary)->len-(beg+len));
|
||||||
RARRAY(ary)->len = alen;
|
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)
|
rb_ary_concat(x, y)
|
||||||
VALUE x, y;
|
VALUE x, y;
|
||||||
{
|
{
|
||||||
|
int xlen = RARRAY(x)->len;
|
||||||
|
int ylen;
|
||||||
|
|
||||||
y = to_ary(y);
|
y = to_ary(y);
|
||||||
if (RARRAY(y)->len > 0) {
|
ylen = RARRAY(y)->len;
|
||||||
rb_ary_push_m(RARRAY(y)->len, RARRAY(y)->ptr, x);
|
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;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
39
lib/open3.rb
39
lib/open3.rb
|
@ -9,39 +9,42 @@
|
||||||
|
|
||||||
module Open3
|
module Open3
|
||||||
#[stdin, stdout, stderr] = popen3(command);
|
#[stdin, stdout, stderr] = popen3(command);
|
||||||
def popen3(cmd)
|
def popen3(*cmd)
|
||||||
pw = IO::pipe # pipe[0] for read, pipe[1] for write
|
pw = IO::pipe # pipe[0] for read, pipe[1] for write
|
||||||
pr = IO::pipe
|
pr = IO::pipe
|
||||||
pe = IO::pipe
|
pe = IO::pipe
|
||||||
|
|
||||||
pid = fork{
|
pid = fork{
|
||||||
# child
|
# child
|
||||||
pw[1].close
|
fork{
|
||||||
STDIN.reopen(pw[0])
|
# grandchild
|
||||||
pw[0].close
|
pw[1].close
|
||||||
|
STDIN.reopen(pw[0])
|
||||||
|
pw[0].close
|
||||||
|
|
||||||
pr[0].close
|
pr[0].close
|
||||||
STDOUT.reopen(pr[1])
|
STDOUT.reopen(pr[1])
|
||||||
pr[1].close
|
pr[1].close
|
||||||
|
|
||||||
pe[0].close
|
pe[0].close
|
||||||
STDERR.reopen(pe[1])
|
STDERR.reopen(pe[1])
|
||||||
pe[1].close
|
pe[1].close
|
||||||
|
|
||||||
exec(cmd)
|
exec(*cmd)
|
||||||
_exit 127
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pw[0].close
|
pw[0].close
|
||||||
pr[1].close
|
pr[1].close
|
||||||
pe[1].close
|
pe[1].close
|
||||||
Thread.start do
|
Process.waitpid(pid)
|
||||||
sleep 1
|
pi = [pw[1], pr[0], pe[0]]
|
||||||
Process.waitpid(pid)
|
|
||||||
end
|
|
||||||
pi = [ pw[1], pr[0], pe[0] ]
|
|
||||||
if defined? yield
|
if defined? yield
|
||||||
return yield *pi
|
begin
|
||||||
|
return yield *pi
|
||||||
|
ensure
|
||||||
|
pi.each{|p| p.close unless p.closed?}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
pi
|
pi
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue