--- Python-3.3.2/Modules/getpath.c.orig 2013-05-15 20:32:59.000000000 +0400 +++ Python-3.3.2/Modules/getpath.c 2013-10-21 20:41:43.579800000 +0400 @@ -10,6 +10,10 @@ #include #endif +#if defined(MS_WINDOWS) || defined(__CYGWIN__) +#include +#endif + /* Search in some common locations for the associated Python libraries. * * Two directories must be found, the platform independent directory @@ -132,7 +136,11 @@ static wchar_t prefix[MAXPATHLEN+1]; static wchar_t exec_prefix[MAXPATHLEN+1]; -static wchar_t progpath[MAXPATHLEN+1]; +static wchar_t progpath[MAXPATHLEN+1] = {'\0'}; +#if defined(MS_WINDOWS) || defined(__CYGWIN__) +static wchar_t dllpath[MAXPATHLEN+1] = {'\0'}; +extern HANDLE PyWin_DLLhModule; +#endif static wchar_t *module_search_path = NULL; static int module_search_path_malloced = 0; static wchar_t *lib_python = L"lib/python" VERSION; @@ -213,7 +221,11 @@ joinpath(wchar_t *buffer, wchar_t *stuff) { size_t n, k; +#if defined(MS_WINDOWS) || defined(__CYGWIN__) + if (stuff[0] == SEP || (wcslen(stuff)>=2 && stuff[0] != 0 && stuff[1] == ':')) +#else if (stuff[0] == SEP) +#endif n = 0; else { n = wcslen(buffer); @@ -227,6 +239,13 @@ k = MAXPATHLEN - n; wcsncpy(buffer+n, stuff, k); buffer[n+k] = '\0'; +#if defined(__CYGWIN__) + /* MSYS specific: Turn C:* into /c* */ + if (wcslen(buffer)>2 && buffer[0] != 0 && buffer[1] == ':') { + buffer[1]=buffer[0]|32; + buffer[0]='/'; + } +#endif } /* copy_absolute requires that path be allocated at least @@ -234,8 +253,21 @@ static void copy_absolute(wchar_t *path, wchar_t *p, size_t pathlen) { - if (p[0] == SEP) +#if defined(MS_WINDOWS) || defined(__CYGWIN__) + if (p[0] == SEP || (wcslen(p)>=2 && p[0] != 0 && p[1] == ':')) +#else + if (p[0] == SEP) +#endif + { wcscpy(path, p); +#if defined(__CYGWIN__) + /* MSYS specific: Turn C:* into /c* */ + if (wcslen(path)>2 && path[0] != 0 && path[1] == ':') { + path[1]=path[0]|32; + path[0]='/'; + } +#endif + } else { if (!_Py_wgetcwd(path, pathlen)) { /* unable to get the current directory */ @@ -451,6 +483,42 @@ return 0; } +#if defined(MS_WINDOWS) || defined(__CYGWIN__) +/* Calculates dllpath and progpath, replacing \\ with / */ +int GetWindowsModulePaths() +{ + int result = 0; + wchar_t* seps; + result = GetModuleFileNameW(NULL, progpath, MAXPATHLEN); + seps = wcschr(progpath, '\\'); + while(seps) { + *seps = '/'; + seps = wcschr(seps, '\\'); + } + dllpath[0] = '\0'; +#if defined(Py_ENABLE_SHARED) && !defined(__CYGWIN__) + // Hmm, cygwin/MSYS2 replacement for PyWin_DLLhModule is needed. + if (PyWin_DLLhModule) { + if((GetModuleFileNameW(PyWin_DLLhModule, dllpath, MAXPATHLEN) > 0)) { + result = 1; + seps = wcschr(dllpath, '\\'); + while(seps) { + *seps = '/'; + seps = wcschr(seps, '\\'); + } + } + } +#endif + + /* Just so that 'MSYS specific: Turn C:* into /c*' + is done. */ + absolutize(progpath); + absolutize(dllpath); + + return result; +} +#endif /* MS_WINDOWS */ + static void calculate_path(void) { @@ -527,6 +595,10 @@ } } #endif /* __APPLE__ */ +#if defined(MS_WINDOWS) || defined(__CYGWIN__) + else if(GetWindowsModulePaths()) { + } +#endif /* MS_WINDOWS */ else if (path) { while (1) { wchar_t *delim = wcschr(path, DELIM);