summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-27 06:21:40 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-27 06:21:40 +0000
commit11c5daa698d5a6ba4003d941fb64c765b7f99c42 (patch)
treeb7c9073d95ec3ab72d9480e2e8606e8cf3cfaa86 /win32
parent98929a2dfdb9881cacaf58d1697373ecd079cd38 (diff)
* win32/win32.c (rb_w32_spawn, rb_w32_aspawn): fixed previous commit. sorry.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30665 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 824191c44d..67c7ce2461 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -1113,7 +1113,7 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
const char *shell = NULL;
WCHAR *wcmd, *wshell;
rb_pid_t ret;
- VALUE tmp = Qnil;
+ VALUE v = 0;
if (check_spawn_mode(mode)) return -1;
@@ -1131,19 +1131,17 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
int nt;
while (ISSPACE(*cmd)) cmd++;
if ((shell = getenv("RUBYSHELL")) && (redir = has_redirection(cmd))) {
- ALLOCV(tmp, strlen(shell) + strlen(cmd) + sizeof(" -c ") + 2);
- sprintf(RSTRING_PTR(tmp), "%s -c \"%s\"", shell, cmd);
- cmd = RSTRING_PTR(tmp);
+ char *tmp = ALLOCV(v, strlen(shell) + strlen(cmd) + sizeof(" -c ") + 2);
+ sprintf(tmp, "%s -c \"%s\"", shell, cmd);
+ cmd = tmp;
}
else if ((shell = getenv("COMSPEC")) &&
(nt = !is_command_com(shell),
(redir < 0 ? has_redirection(cmd) : redir) ||
is_internal_cmd(cmd, nt))) {
- ALLOCV(tmp,
- strlen(shell) + strlen(cmd) + sizeof(" /c ") + (nt ? 2 : 0));
- sprintf(RSTRING_PTR(tmp),
- nt ? "%s /c \"%s\"" : "%s /c %s", shell, cmd);
- cmd = RSTRING_PTR(tmp);
+ char *tmp = ALLOCV(v, strlen(shell) + strlen(cmd) + sizeof(" /c ") + (nt ? 2 : 0));
+ sprintf(tmp, nt ? "%s /c \"%s\"" : "%s /c %s", shell, cmd);
+ cmd = tmp;
}
else {
int len = 0, quote = (*cmd == '"') ? '"' : (*cmd == '\'') ? '\'' : 0;
@@ -1184,8 +1182,7 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
if (p) translate_char(p, '/', '\\');
if (is_batch(shell)) {
int alen = strlen(prog);
- ALLOCV(tmp, len + alen + (quote ? 2 : 0) + 1);
- cmd = p = RSTRING_PTR(tmp);
+ cmd = p = ALLOCV(v, len + alen + (quote ? 2 : 0) + 1);
if (quote) *p++ = '"';
memcpy(p, shell, len);
p += len;
@@ -1199,7 +1196,7 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
/* assume ACP */
wcmd = cmd ? acp_to_wstr(cmd, NULL) : NULL;
- if (!NIL_P(tmp)) ALLOCV_END(tmp);
+ if (v) ALLOCV_END(v);
wshell = shell ? acp_to_wstr(shell, NULL) : NULL;
ret = child_result(CreateChild(wcmd, wshell, NULL, NULL, NULL, NULL), mode);
@@ -1218,7 +1215,7 @@ rb_w32_aspawn(int mode, const char *prog, char *const *argv)
char *cmd, fbuf[MAXPATHLEN];
WCHAR *wcmd, *wprog;
rb_pid_t ret;
- VALUE tmp = Qnil;
+ VALUE v = 0;
if (check_spawn_mode(mode)) return -1;
@@ -1251,8 +1248,7 @@ rb_w32_aspawn(int mode, const char *prog, char *const *argv)
if (c_switch) len += 3;
else ++argv;
if (argv[0]) len += join_argv(NULL, argv, ntcmd);
- ALLOCV(tmp, len);
- cmd = RSTRING_PTR(tmp);
+ cmd = ALLOCV(v, len);
join_argv(cmd, progs, ntcmd);
if (c_switch) strlcat(cmd, " /c", len);
if (argv[0]) join_argv(cmd + strlcat(cmd, " ", len), argv, ntcmd);
@@ -1260,14 +1256,13 @@ rb_w32_aspawn(int mode, const char *prog, char *const *argv)
}
else {
len = join_argv(NULL, argv, FALSE);
- ALLOCV(tmp, len);
- cmd = RSTRING_PTR(tmp);
+ cmd = ALLOCV(v, len);
join_argv(cmd, argv, FALSE);
}
/* assume ACP */
wcmd = cmd ? acp_to_wstr(cmd, NULL) : NULL;
- if (!NIL_P(tmp)) ALLOCV_END(tmp);
+ if (v) ALLOCV_END(v);
wprog = prog ? acp_to_wstr(prog, NULL) : NULL;
ret = child_result(CreateChild(wcmd, wprog, NULL, NULL, NULL, NULL), mode);