ruby-changes:18640
From: usa <ko1@a...>
Date: Thu, 27 Jan 2011 15:12:55 +0900 (JST)
Subject: [ruby-changes:18640] Ruby:r30664 (trunk): * win32/win32.c (rb_w32_spawn, rb_w32_aspawn): get rid of too huge
usa 2011-01-27 15:12:48 +0900 (Thu, 27 Jan 2011) New Revision: 30664 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30664 Log: * win32/win32.c (rb_w32_spawn, rb_w32_aspawn): get rid of too huge alloca(). this is the real fix of [ruby-core:34833]. Modified files: trunk/ChangeLog trunk/win32/win32.c Index: ChangeLog =================================================================== --- ChangeLog (revision 30663) +++ ChangeLog (revision 30664) @@ -1,3 +1,8 @@ +Thu Jan 27 15:11:52 2011 NAKAMURA Usaku <usa@r...> + + * win32/win32.c (rb_w32_spawn, rb_w32_aspawn): get rid of too huge + alloca(). this is the real fix of [ruby-core:34833]. + Thu Jan 27 12:46:25 2011 Nobuyoshi Nakada <nobu@r...> * process.c (ALLOC_ARGV_WITH_STR): fix void pointer arithmetic. Index: win32/win32.c =================================================================== --- win32/win32.c (revision 30663) +++ win32/win32.c (revision 30664) @@ -1113,6 +1113,7 @@ const char *shell = NULL; WCHAR *wcmd, *wshell; rb_pid_t ret; + VALUE tmp = Qnil; if (check_spawn_mode(mode)) return -1; @@ -1130,18 +1131,19 @@ int nt; while (ISSPACE(*cmd)) cmd++; if ((shell = getenv("RUBYSHELL")) && (redir = has_redirection(cmd))) { - char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) + sizeof(" -c ") + 2); - sprintf(tmp, "%s -c \"%s\"", shell, cmd); - cmd = tmp; + ALLOCV(tmp, strlen(shell) + strlen(cmd) + sizeof(" -c ") + 2); + sprintf(RSTRING_PTR(tmp), "%s -c \"%s\"", shell, cmd); + cmd = RSTRING_PTR(tmp); } else if ((shell = getenv("COMSPEC")) && (nt = !is_command_com(shell), (redir < 0 ? has_redirection(cmd) : redir) || is_internal_cmd(cmd, nt))) { - char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) + sizeof(" /c ") - + (nt ? 2 : 0)); - sprintf(tmp, nt ? "%s /c \"%s\"" : "%s /c %s", shell, cmd); - cmd = tmp; + 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); } else { int len = 0, quote = (*cmd == '"') ? '"' : (*cmd == '\'') ? '\'' : 0; @@ -1182,7 +1184,8 @@ if (p) translate_char(p, '/', '\\'); if (is_batch(shell)) { int alen = strlen(prog); - cmd = p = ALLOCA_N(char, len + alen + (quote ? 2 : 0) + 1); + ALLOCV(tmp, len + alen + (quote ? 2 : 0) + 1); + cmd = p = RSTRING_PTR(tmp); if (quote) *p++ = '"'; memcpy(p, shell, len); p += len; @@ -1196,6 +1199,7 @@ /* assume ACP */ wcmd = cmd ? acp_to_wstr(cmd, NULL) : NULL; + if (!NIL_P(tmp)) ALLOCV_END(tmp); wshell = shell ? acp_to_wstr(shell, NULL) : NULL; ret = child_result(CreateChild(wcmd, wshell, NULL, NULL, NULL, NULL), mode); @@ -1214,6 +1218,7 @@ char *cmd, fbuf[MAXPATHLEN]; WCHAR *wcmd, *wprog; rb_pid_t ret; + VALUE tmp = Qnil; if (check_spawn_mode(mode)) return -1; @@ -1246,7 +1251,8 @@ if (c_switch) len += 3; else ++argv; if (argv[0]) len += join_argv(NULL, argv, ntcmd); - cmd = ALLOCA_N(char, len); + ALLOCV(tmp, len); + cmd = RSTRING_PTR(tmp); join_argv(cmd, progs, ntcmd); if (c_switch) strlcat(cmd, " /c", len); if (argv[0]) join_argv(cmd + strlcat(cmd, " ", len), argv, ntcmd); @@ -1254,12 +1260,14 @@ } else { len = join_argv(NULL, argv, FALSE); - cmd = ALLOCA_N(char, len); + ALLOCV(tmp, len); + cmd = RSTRING_PTR(tmp); join_argv(cmd, argv, FALSE); } /* assume ACP */ wcmd = cmd ? acp_to_wstr(cmd, NULL) : NULL; + if (!NIL_P(tmp)) ALLOCV_END(tmp); wprog = prog ? acp_to_wstr(prog, NULL) : NULL; ret = child_result(CreateChild(wcmd, wprog, NULL, NULL, NULL, NULL), mode); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/