1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2000-10-25 04:48:41 +00:00
parent 52a2acbad3
commit 9b5c48abed
3 changed files with 52 additions and 31 deletions

View file

@ -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>
* eval.c (rb_eval): ARGSPUSH should not modify args array.
Wed Oct 18 03:10:20 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
* stable version 1.6.2 released.
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().

30
array.c
View file

@ -288,9 +288,10 @@ 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;
}

View file

@ -9,13 +9,15 @@
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
fork{
# grandchild
pw[1].close
STDIN.reopen(pw[0])
pw[0].close
@ -28,20 +30,21 @@ module Open3
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]]
if defined? yield
begin
return yield *pi
ensure
pi.each{|p| p.close unless p.closed?}
end
end
pi
end