mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (pipe_open_v, pipe_open_s): separate array and string
cases. [ruby-dev:31344] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
341ae6ac3e
commit
43009063c7
3 changed files with 47 additions and 36 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sun Aug 5 04:56:25 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (pipe_open_v, pipe_open_s): separate array and string
|
||||||
|
cases. [ruby-dev:31344]
|
||||||
|
|
||||||
Fri Aug 3 11:05:54 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Aug 3 11:05:54 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ext/extmk.rb (extmake): save all CONFIG values.
|
* ext/extmk.rb (extmake): save all CONFIG values.
|
||||||
|
|
72
io.c
72
io.c
|
@ -3050,12 +3050,12 @@ popen_exec(void *pp)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
pipe_open(int argc, VALUE *argv, const char *mode)
|
pipe_open(const char *cmd, int argc, VALUE *argv, const char *mode)
|
||||||
{
|
{
|
||||||
int modef = rb_io_mode_flags(mode);
|
int modef = rb_io_mode_flags(mode);
|
||||||
int pid = 0;
|
int pid = 0;
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
VALUE port, prog;
|
VALUE port;
|
||||||
#if defined(HAVE_FORK)
|
#if defined(HAVE_FORK)
|
||||||
int status;
|
int status;
|
||||||
struct popen_arg arg;
|
struct popen_arg arg;
|
||||||
|
@ -3063,33 +3063,10 @@ pipe_open(int argc, VALUE *argv, const char *mode)
|
||||||
int openmode = rb_io_mode_modenum(mode);
|
int openmode = rb_io_mode_modenum(mode);
|
||||||
char *exename = NULL;
|
char *exename = NULL;
|
||||||
#endif
|
#endif
|
||||||
volatile int doexec;
|
|
||||||
char *cmd;
|
|
||||||
FILE *fp = 0;
|
FILE *fp = 0;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
|
|
||||||
prog = rb_check_argv(argc, argv);
|
|
||||||
if (!prog) {
|
|
||||||
if (argc == 1) argc = 0;
|
|
||||||
prog = argv[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = StringValueCStr(prog);
|
|
||||||
doexec = (strcmp("-", cmd) != 0);
|
|
||||||
|
|
||||||
#if !defined(HAVE_FORK)
|
|
||||||
if (!doexec) {
|
|
||||||
rb_raise(rb_eNotImpError,
|
|
||||||
"fork() function is unimplemented on this machine");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_FORK)
|
#if defined(HAVE_FORK)
|
||||||
if (!doexec) {
|
|
||||||
fflush(stdin); /* is it really needed? */
|
|
||||||
rb_io_flush(rb_stdout);
|
|
||||||
rb_io_flush(rb_stderr);
|
|
||||||
}
|
|
||||||
arg.modef = modef;
|
arg.modef = modef;
|
||||||
arg.pair[0] = arg.pair[1] = -1;
|
arg.pair[0] = arg.pair[1] = -1;
|
||||||
switch (modef & (FMODE_READABLE|FMODE_WRITABLE)) {
|
switch (modef & (FMODE_READABLE|FMODE_WRITABLE)) {
|
||||||
|
@ -3110,13 +3087,16 @@ pipe_open(int argc, VALUE *argv, const char *mode)
|
||||||
default:
|
default:
|
||||||
rb_sys_fail(cmd);
|
rb_sys_fail(cmd);
|
||||||
}
|
}
|
||||||
if (doexec) {
|
if (cmd) {
|
||||||
arg.exec.argc = argc;
|
arg.exec.argc = argc;
|
||||||
arg.exec.argv = argv;
|
arg.exec.argv = argv;
|
||||||
arg.exec.prog = cmd;
|
arg.exec.prog = cmd;
|
||||||
pid = rb_fork(&status, popen_exec, &arg);
|
pid = rb_fork(&status, popen_exec, &arg);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
fflush(stdin); /* is it really needed? */
|
||||||
|
rb_io_flush(rb_stdout);
|
||||||
|
rb_io_flush(rb_stderr);
|
||||||
pid = rb_fork(&status, 0, 0);
|
pid = rb_fork(&status, 0, 0);
|
||||||
if (pid == 0) { /* child */
|
if (pid == 0) { /* child */
|
||||||
popen_redirect(&arg);
|
popen_redirect(&arg);
|
||||||
|
@ -3197,6 +3177,32 @@ pipe_open(int argc, VALUE *argv, const char *mode)
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
pipe_open_v(int argc, VALUE *argv, const char *mode)
|
||||||
|
{
|
||||||
|
VALUE prog = rb_check_argv(argc, argv);
|
||||||
|
const char *cmd;
|
||||||
|
|
||||||
|
if (!RB_GC_GUARD(prog)) prog = argv[0];
|
||||||
|
cmd = RSTRING_PTR(prog);
|
||||||
|
return pipe_open(cmd, argc, argv, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
pipe_open_s(VALUE prog, const char *mode)
|
||||||
|
{
|
||||||
|
const char *cmd = (rb_check_argv(1, &prog), RSTRING_PTR(prog));
|
||||||
|
|
||||||
|
if (strcmp("-", cmd) == 0) {
|
||||||
|
#if !defined(HAVE_FORK)
|
||||||
|
rb_raise(rb_eNotImpError,
|
||||||
|
"fork() function is unimplemented on this machine");
|
||||||
|
#endif
|
||||||
|
cmd = 0;
|
||||||
|
}
|
||||||
|
return pipe_open(cmd, 0, &prog, mode);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* IO.popen(cmd, mode="r") => io
|
* IO.popen(cmd, mode="r") => io
|
||||||
|
@ -3267,15 +3273,15 @@ rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
|
||||||
}
|
}
|
||||||
tmp = rb_check_array_type(pname);
|
tmp = rb_check_array_type(pname);
|
||||||
if (!NIL_P(tmp)) {
|
if (!NIL_P(tmp)) {
|
||||||
VALUE *argv = ALLOCA_N(VALUE, RARRAY_LEN(tmp));
|
long len = RARRAY_LEN(tmp);
|
||||||
|
VALUE *args = ALLOCA_N(VALUE, len);
|
||||||
|
|
||||||
MEMCPY(argv, RARRAY_PTR(tmp), VALUE, RARRAY_LEN(tmp));
|
MEMCPY(args, RARRAY_PTR(tmp), VALUE, len);
|
||||||
port = pipe_open(RARRAY_LEN(tmp), argv, mode);
|
port = pipe_open_v(len, args, mode);
|
||||||
pname = tmp;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SafeStringValue(pname);
|
SafeStringValue(pname);
|
||||||
port = pipe_open(1, &pname, mode);
|
port = pipe_open_s(pname, mode);
|
||||||
}
|
}
|
||||||
if (NIL_P(port)) {
|
if (NIL_P(port)) {
|
||||||
/* child */
|
/* child */
|
||||||
|
@ -3500,7 +3506,7 @@ rb_io_open(const char *fname, const char *mode)
|
||||||
{
|
{
|
||||||
if (fname[0] == '|') {
|
if (fname[0] == '|') {
|
||||||
VALUE cmd = rb_str_new2(fname+1);
|
VALUE cmd = rb_str_new2(fname+1);
|
||||||
return pipe_open(1, &cmd, mode);
|
return pipe_open_s(cmd, mode);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_file_open(fname, mode);
|
return rb_file_open(fname, mode);
|
||||||
|
@ -4624,7 +4630,7 @@ rb_f_backquote(VALUE obj, VALUE str)
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
|
|
||||||
SafeStringValue(str);
|
SafeStringValue(str);
|
||||||
port = pipe_open(1, &str, "r");
|
port = pipe_open_s(str, "r");
|
||||||
if (NIL_P(port)) return rb_str_new(0,0);
|
if (NIL_P(port)) return rb_str_new(0,0);
|
||||||
|
|
||||||
GetOpenFile(port, fptr);
|
GetOpenFile(port, fptr);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define RUBY_VERSION "1.9.0"
|
#define RUBY_VERSION "1.9.0"
|
||||||
#define RUBY_RELEASE_DATE "2007-08-03"
|
#define RUBY_RELEASE_DATE "2007-08-05"
|
||||||
#define RUBY_VERSION_CODE 190
|
#define RUBY_VERSION_CODE 190
|
||||||
#define RUBY_RELEASE_CODE 20070803
|
#define RUBY_RELEASE_CODE 20070805
|
||||||
#define RUBY_PATCHLEVEL 0
|
#define RUBY_PATCHLEVEL 0
|
||||||
|
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
#define RUBY_VERSION_TEENY 0
|
#define RUBY_VERSION_TEENY 0
|
||||||
#define RUBY_RELEASE_YEAR 2007
|
#define RUBY_RELEASE_YEAR 2007
|
||||||
#define RUBY_RELEASE_MONTH 8
|
#define RUBY_RELEASE_MONTH 8
|
||||||
#define RUBY_RELEASE_DAY 3
|
#define RUBY_RELEASE_DAY 5
|
||||||
|
|
||||||
#ifdef RUBY_EXTERN
|
#ifdef RUBY_EXTERN
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
|
|
Loading…
Add table
Reference in a new issue