summaryrefslogtreecommitdiff
path: root/PC/bdist_wininst
diff options
context:
space:
mode:
authorMark Hammond <mhammond@skippinet.com.au>2009-01-29 13:08:01 +0000
committerMark Hammond <mhammond@skippinet.com.au>2009-01-29 13:08:01 +0000
commit891f2631f576dfc515627074cccb07e0ffdff156 (patch)
tree5bd442b4806976040da54ec3bc6cbb7e6fe9cfb6 /PC/bdist_wininst
parent6d0e9757d1f00402c736bc289bd5f4fd7e626afa (diff)
downloadcpython-git-891f2631f576dfc515627074cccb07e0ffdff156.tar.gz
Fix issue5076: bdist_wininst fails on py3k
Diffstat (limited to 'PC/bdist_wininst')
-rw-r--r--PC/bdist_wininst/install.c47
1 files changed, 40 insertions, 7 deletions
diff --git a/PC/bdist_wininst/install.c b/PC/bdist_wininst/install.c
index 9be4100715..53e6a514f5 100644
--- a/PC/bdist_wininst/install.c
+++ b/PC/bdist_wininst/install.c
@@ -114,6 +114,7 @@
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);