[前][次][番号順一覧][スレッド一覧]

ruby-changes:17167

From: usa <ko1@a...>
Date: Thu, 2 Sep 2010 09:03:17 +0900 (JST)
Subject: [ruby-changes:17167] Ruby:r29166 (trunk): * win32/win32.c (CreateChild): unicodize.

usa	2010-09-02 09:02:52 +0900 (Thu, 02 Sep 2010)

  New Revision: 29166

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29166

  Log:
    * win32/win32.c (CreateChild): unicodize.
    
    * win32/win32.c (rb_w32_spawn, rb_w32_aspawn): convert arguments of
      CreateChild() from ACP to WideChar.

  Modified files:
    trunk/ChangeLog
    trunk/win32/win32.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29165)
+++ ChangeLog	(revision 29166)
@@ -1,3 +1,10 @@
+Thu Sep  2 09:01:13 2010  NAKAMURA Usaku  <usa@r...>
+
+	* win32/win32.c (CreateChild): unicodize.
+
+	* win32/win32.c (rb_w32_spawn, rb_w32_aspawn): convert arguments of
+	  CreateChild() from ACP to WideChar.
+
 Thu Sep  2 06:53:43 2010  Tanaka Akira  <akr@f...>
 
 	* ext/pathname/pathname.c (path_directory_p): Pathname#directory?
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 29165)
+++ win32/win32.c	(revision 29166)
@@ -63,7 +63,7 @@
 
 #define TO_SOCKET(x)	_get_osfhandle(x)
 
-static struct ChildRecord *CreateChild(const char *, const char *, SECURITY_ATTRIBUTES *, HANDLE, HANDLE, HANDLE);
+static struct ChildRecord *CreateChild(const WCHAR *, const WCHAR *, SECURITY_ATTRIBUTES *, HANDLE, HANDLE, HANDLE);
 static int has_redirection(const char *);
 int rb_w32_wait_events(HANDLE *events, int num, DWORD timeout);
 static int rb_w32_open_osfhandle(intptr_t osfhandle, int flags);
@@ -987,12 +987,12 @@
 }
 
 static struct ChildRecord *
-CreateChild(const char *cmd, const char *prog, SECURITY_ATTRIBUTES *psa,
+CreateChild(const WCHAR *cmd, const WCHAR *prog, SECURITY_ATTRIBUTES *psa,
 	    HANDLE hInput, HANDLE hOutput, HANDLE hError)
 {
     BOOL fRet;
     DWORD  dwCreationFlags;
-    STARTUPINFO aStartupInfo;
+    STARTUPINFOW aStartupInfo;
     PROCESS_INFORMATION aProcessInformation;
     SECURITY_ATTRIBUTES sa;
     struct ChildRecord *child;
@@ -1015,9 +1015,9 @@
 	psa = &sa;
     }
 
-    memset(&aStartupInfo, 0, sizeof (STARTUPINFO));
-    memset(&aProcessInformation, 0, sizeof (PROCESS_INFORMATION));
-    aStartupInfo.cb = sizeof (STARTUPINFO);
+    memset(&aStartupInfo, 0, sizeof(aStartupInfo));
+    memset(&aProcessInformation, 0, sizeof(aProcessInformation));
+    aStartupInfo.cb = sizeof(aStartupInfo);
     aStartupInfo.dwFlags = STARTF_USESTDHANDLES;
     if (hInput) {
 	aStartupInfo.hStdInput  = hInput;
@@ -1041,9 +1041,9 @@
     dwCreationFlags = (NORMAL_PRIORITY_CLASS);
 
     RUBY_CRITICAL({
-	fRet = CreateProcess(prog, (char *)cmd, psa, psa,
-			     psa->bInheritHandle, dwCreationFlags, NULL, NULL,
-			     &aStartupInfo, &aProcessInformation);
+	fRet = CreateProcessW(prog, (WCHAR *)cmd, psa, psa,
+			      psa->bInheritHandle, dwCreationFlags, NULL, NULL,
+			      &aStartupInfo, &aProcessInformation);
 	errno = map_errno(GetLastError());
     });
 
@@ -1077,12 +1077,15 @@
     return 0;
 }
 
+static WCHAR *acp_to_wstr(const char *, long *);
+
 rb_pid_t
 rb_w32_spawn(int mode, const char *cmd, const char *prog)
 {
     char fbuf[MAXPATHLEN];
     char *p = NULL;
     const char *shell = NULL;
+    const WCHAR *wcmd, *wshell;
 
     if (check_spawn_mode(mode)) return -1;
 
@@ -1164,7 +1167,11 @@
 	}
     }
 
-    return child_result(CreateChild(cmd, shell, NULL, NULL, NULL, NULL), mode);
+    /* assume ACP */
+    wcmd = cmd ? acp_to_wstr(cmd, NULL) : NULL;
+    wshell = shell ? acp_to_wstr(shell, NULL) : NULL;
+
+    return child_result(CreateChild(wcmd, wshell, NULL, NULL, NULL, NULL), mode);
 }
 
 rb_pid_t
@@ -1175,6 +1182,7 @@
     BOOL ntcmd = FALSE, tmpnt;
     const char *shell;
     char *cmd, fbuf[MAXPATHLEN];
+    const WCHAR *wcmd, *wprog;
 
     if (check_spawn_mode(mode)) return -1;
 
@@ -1219,7 +1227,11 @@
 	join_argv(cmd, argv, FALSE);
     }
 
-    return child_result(CreateChild(cmd, prog, NULL, NULL, NULL, NULL), mode);
+    /* assume ACP */
+    wcmd = cmd ? acp_to_wstr(cmd, NULL) : NULL;
+    wprog = prog ? acp_to_wstr(prog, NULL) : NULL;
+
+    return child_result(CreateChild(wcmd, wprog, NULL, NULL, NULL, NULL), mode);
 }
 
 typedef struct _NtCmdLineElement {
@@ -1696,6 +1708,17 @@
     return p;
 }
 
+static WCHAR *
+acp_to_wstr(const char *str, long *plen)
+{
+    WCHAR *ptr;
+    int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0) - 1;
+    if (!(ptr = malloc(sizeof(WCHAR) * (len + 1)))) return 0;
+    MultiByteToWideChar(CP_ACP, 0, str, -1, ptr, len + 1);
+    if (plen) *plen = len;
+    return ptr;
+}
+
 static char *
 wstr_to_filecp(const WCHAR *wstr, long *plen)
 {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]