* process.c (check_exec_redirect_fd, check_exec_redirect): raise
ArgumentError if fd >= 3 on Windows because the feature is not supported. * test/ruby/test_process.rb (test_execopts_redirect): remove meaningless argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0ebf520671
commit
4f8f4a9ee4
@ -1,3 +1,12 @@
|
|||||||
|
Thu Mar 3 22:10:26 2011 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* process.c (check_exec_redirect_fd, check_exec_redirect): raise
|
||||||
|
ArgumentError if fd >= 3 on Windows because the feature is not
|
||||||
|
supported.
|
||||||
|
|
||||||
|
* test/ruby/test_process.rb (test_execopts_redirect): remove meaningless
|
||||||
|
argument.
|
||||||
|
|
||||||
Thu Mar 3 21:21:42 2011 NAKAMURA Usaku <usa@ruby-lang.org>
|
Thu Mar 3 21:21:42 2011 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* test/ruby/test_process.rb (test_execopts_redirect): redirecting fd
|
* test/ruby/test_process.rb (test_execopts_redirect): redirecting fd
|
||||||
|
17
process.c
17
process.c
@ -1294,7 +1294,7 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
check_exec_redirect_fd(VALUE v)
|
check_exec_redirect_fd(VALUE v, int iskey)
|
||||||
{
|
{
|
||||||
VALUE tmp;
|
VALUE tmp;
|
||||||
int fd;
|
int fd;
|
||||||
@ -1326,6 +1326,11 @@ check_exec_redirect_fd(VALUE v)
|
|||||||
wrong:
|
wrong:
|
||||||
rb_raise(rb_eArgError, "negative file descriptor");
|
rb_raise(rb_eArgError, "negative file descriptor");
|
||||||
}
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
else if (fd >= 3 && iskey) {
|
||||||
|
rb_raise(rb_eArgError, "wrong file descriptor (%d)", fd);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return INT2FIX(fd);
|
return INT2FIX(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1363,7 +1368,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case T_FILE:
|
case T_FILE:
|
||||||
val = check_exec_redirect_fd(val);
|
val = check_exec_redirect_fd(val, 0);
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case T_FIXNUM:
|
case T_FIXNUM:
|
||||||
index = EXEC_OPTION_DUP2;
|
index = EXEC_OPTION_DUP2;
|
||||||
@ -1375,7 +1380,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
|
|||||||
if (RARRAY_LEN(val) == 2 && SYMBOL_P(path) &&
|
if (RARRAY_LEN(val) == 2 && SYMBOL_P(path) &&
|
||||||
SYM2ID(path) == rb_intern("child")) {
|
SYM2ID(path) == rb_intern("child")) {
|
||||||
index = EXEC_OPTION_DUP2_CHILD;
|
index = EXEC_OPTION_DUP2_CHILD;
|
||||||
param = check_exec_redirect_fd(rb_ary_entry(val, 1));
|
param = check_exec_redirect_fd(rb_ary_entry(val, 1), 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
index = EXEC_OPTION_OPEN;
|
index = EXEC_OPTION_OPEN;
|
||||||
@ -1399,7 +1404,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
|
|||||||
path = val;
|
path = val;
|
||||||
FilePathValue(path);
|
FilePathValue(path);
|
||||||
if (TYPE(key) == T_FILE)
|
if (TYPE(key) == T_FILE)
|
||||||
key = check_exec_redirect_fd(key);
|
key = check_exec_redirect_fd(key, 1);
|
||||||
if (FIXNUM_P(key) && (FIX2INT(key) == 1 || FIX2INT(key) == 2))
|
if (FIXNUM_P(key) && (FIX2INT(key) == 1 || FIX2INT(key) == 2))
|
||||||
flags = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC);
|
flags = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC);
|
||||||
else
|
else
|
||||||
@ -1419,14 +1424,14 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
|
|||||||
rb_ary_store(options, index, ary);
|
rb_ary_store(options, index, ary);
|
||||||
}
|
}
|
||||||
if (TYPE(key) != T_ARRAY) {
|
if (TYPE(key) != T_ARRAY) {
|
||||||
VALUE fd = check_exec_redirect_fd(key);
|
VALUE fd = check_exec_redirect_fd(key, !NIL_P(param));
|
||||||
rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
|
rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int i, n=0;
|
int i, n=0;
|
||||||
for (i = 0 ; i < RARRAY_LEN(key); i++) {
|
for (i = 0 ; i < RARRAY_LEN(key); i++) {
|
||||||
VALUE v = RARRAY_PTR(key)[i];
|
VALUE v = RARRAY_PTR(key)[i];
|
||||||
VALUE fd = check_exec_redirect_fd(v);
|
VALUE fd = check_exec_redirect_fd(v, !NIL_P(param));
|
||||||
rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
|
rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
@ -384,7 +384,7 @@ class TestProcess < Test::Unit::TestCase
|
|||||||
Process.wait Process.spawn(*ECHO["c"], STDERR=>STDOUT, STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
|
Process.wait Process.spawn(*ECHO["c"], STDERR=>STDOUT, STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
|
||||||
assert_equal("c", File.read("out").chomp)
|
assert_equal("c", File.read("out").chomp)
|
||||||
File.open("out", "w") {|f|
|
File.open("out", "w") {|f|
|
||||||
Process.wait Process.spawn(*ECHO["d"], f=>STDOUT, STDOUT=>f)
|
Process.wait Process.spawn(*ECHO["d"], STDOUT=>f)
|
||||||
assert_equal("d", File.read("out").chomp)
|
assert_equal("d", File.read("out").chomp)
|
||||||
}
|
}
|
||||||
opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]}
|
opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user