]> granicus.if.org Git - python/commitdiff
Fix issue5076: bdist_wininst fails on py3k
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 29 Jan 2009 13:08:01 +0000 (13:08 +0000)
committerMark Hammond <mhammond@skippinet.com.au>
Thu, 29 Jan 2009 13:08:01 +0000 (13:08 +0000)
Lib/distutils/command/wininst-9.0-amd64.exe
Lib/distutils/command/wininst-9.0.exe
PC/bdist_wininst/install.c

index 11d8011c717c3a1c54afbe00e002fab6d37766c6..94fbd4341b2a140fb0aa38ed1e10ff69600d4911 100644 (file)
Binary files a/Lib/distutils/command/wininst-9.0-amd64.exe and b/Lib/distutils/command/wininst-9.0-amd64.exe differ
index dadb31d8938b9b147830382495eee2453c171648..2ec261f9fdcd034cff9602af0c81fb7953ce2e2b 100644 (file)
Binary files a/Lib/distutils/command/wininst-9.0.exe and b/Lib/distutils/command/wininst-9.0.exe differ
index 9be410071586e8596c6d85f356c41256c82bad70..53e6a514f5882d6742af7adabc42e768b6040083 100644 (file)
 FILE *logfile;
 
 char modulename[MAX_PATH];
+wchar_t wmodulename[MAX_PATH];
 
 HWND hwndMain;
 HWND hDialog;
@@ -299,6 +300,27 @@ static int do_compile_files(int (__cdecl * PyRun_SimpleString)(char *),
 
 typedef void PyObject;
 
+// Convert a "char *" string to "whcar_t *", or NULL on error.
+// Result string must be free'd
+wchar_t *widen_string(char *src)
+{
+       wchar_t *result;
+       DWORD dest_cch;
+       int src_len = strlen(src) + 1; // include NULL term in all ops
+       /* use MultiByteToWideChar() to see how much we need. */
+       /* NOTE: this will include the null-term in the length */
+       dest_cch = MultiByteToWideChar(CP_ACP, 0, src, src_len, NULL, 0);
+       // alloc the buffer
+       result = (wchar_t *)malloc(dest_cch * sizeof(wchar_t));
+       if (result==NULL)
+               return NULL;
+       /* do the conversion */
+       if (0==MultiByteToWideChar(CP_ACP, 0, src, src_len, result, dest_cch)) {
+               free(result);
+               return NULL;
+       }
+       return result;
+}
 
 /*
  * Returns number of files which failed to compile,
@@ -307,7 +329,7 @@ typedef void PyObject;
 static int compile_filelist(HINSTANCE hPython, BOOL optimize_flag)
 {
        DECLPROC(hPython, void, Py_Initialize, (void));
-       DECLPROC(hPython, void, Py_SetProgramName, (char *));
+       DECLPROC(hPython, void, Py_SetProgramName, (wchar_t *));
        DECLPROC(hPython, void, Py_Finalize, (void));
        DECLPROC(hPython, int, PyRun_SimpleString, (char *));
        DECLPROC(hPython, PyObject *, PySys_GetObject, (char *));
@@ -326,7 +348,7 @@ static int compile_filelist(HINSTANCE hPython, BOOL optimize_flag)
                return -1;
 
        *Py_OptimizeFlag = optimize_flag ? 1 : 0;
-       Py_SetProgramName(modulename);
+       Py_SetProgramName(wmodulename);
        Py_Initialize();
 
        errors += do_compile_files(PyRun_SimpleString, optimize_flag);
@@ -696,9 +718,10 @@ static int prepare_script_environment(HINSTANCE hPython)
 static int
 do_run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv)
 {
-       int fh, result;
+       int fh, result, i;
+       static wchar_t *wargv[256];
        DECLPROC(hPython, void, Py_Initialize, (void));
-       DECLPROC(hPython, int, PySys_SetArgv, (int, char **));
+       DECLPROC(hPython, int, PySys_SetArgv, (int, wchar_t **));
        DECLPROC(hPython, int, PyRun_SimpleString, (char *));
        DECLPROC(hPython, void, Py_Finalize, (void));
        DECLPROC(hPython, PyObject *, Py_BuildValue, (char *, ...));
@@ -732,7 +755,16 @@ do_run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv)
        Py_Initialize();
 
        prepare_script_environment(hPython);
-       PySys_SetArgv(argc, argv);
+       // widen the argv array for py3k.
+       memset(wargv, 0, sizeof(wargv));
+       for (i=0;i<argc;i++)
+               wargv[i] = argv[i] ? widen_string(argv[i]) : NULL;
+       PySys_SetArgv(argc, wargv);
+       // free the strings we just widened.
+       for (i=0;i<argc;i++)
+               if (wargv[i])
+                       free(wargv[i]);
+
        result = 3;
        {
                struct _stat statbuf;
@@ -807,7 +839,7 @@ static int do_run_simple_script(HINSTANCE hPython, char *script)
 {
        int rc;
        DECLPROC(hPython, void, Py_Initialize, (void));
-       DECLPROC(hPython, void, Py_SetProgramName, (char *));
+       DECLPROC(hPython, void, Py_SetProgramName, (wchar_t *));
        DECLPROC(hPython, void, Py_Finalize, (void));
        DECLPROC(hPython, int, PyRun_SimpleString, (char *));
        DECLPROC(hPython, void, PyErr_Print, (void));
@@ -816,7 +848,7 @@ static int do_run_simple_script(HINSTANCE hPython, char *script)
            !PyRun_SimpleString || !PyErr_Print)
                return -1;
 
-       Py_SetProgramName(modulename);
+       Py_SetProgramName(wmodulename);
        Py_Initialize();
        prepare_script_environment(hPython);
        rc = PyRun_SimpleString(script);
@@ -2618,6 +2650,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
        char *basename;
 
        GetModuleFileName(NULL, modulename, sizeof(modulename));
+       GetModuleFileNameW(NULL, wmodulename, sizeof(wmodulename)/sizeof(wmodulename[0]));
 
        /* Map the executable file to memory */
        arc_data = MapExistingFile(modulename, &arc_size);