diff -rupN Python-2.7.13/configure.ac Python-2.7.13-new/configure.ac
--- Python-2.7.13/configure.ac 2017-01-21 01:46:10.027569963 +0100
+++ Python-2.7.13-new/configure.ac 2017-01-21 01:46:10.172568415 +0100
@@ -5036,7 +5036,9 @@ MODULE_GETPATH=Modules/getpath.o
case $host in
*-*-mingw*)
dnl default sys.path calculations for windows platforms
- MODULE_GETPATH=PC/getpathp.o
+ MODULE_GETPATH=Modules/getpath.o
+ dnl "PC" is project sub-directory and we has to prepend user defined flags
+ CPPFLAGS="-I\$(srcdir)/Python -I\$(srcdir)/PC $CPPFLAGS"
;;
esac
diff -rupN Python-2.7.13/Modules/getpath.c Python-2.7.13-new/Modules/getpath.c
--- Python-2.7.13/Modules/getpath.c 2016-12-17 21:05:07.000000000 +0100
+++ Python-2.7.13-new/Modules/getpath.c 2017-01-21 01:46:10.173568405 +0100
@@ -10,6 +10,10 @@
#include <mach-o/dyld.h>
#endif
+#ifdef MS_WINDOWS
+#include <windows.h>
+#endif
+
/* Search in some common locations for the associated Python libraries.
*
* Two directories must be found, the platform independent directory
@@ -106,7 +110,11 @@
static char prefix[MAXPATHLEN+1];
static char exec_prefix[MAXPATHLEN+1];
-static char progpath[MAXPATHLEN+1];
+static char progpath[MAXPATHLEN+1] = {'\0'};
+#ifdef MS_WINDOWS
+static char dllpath[MAXPATHLEN+1] = {'\0'};
+extern HANDLE PyWin_DLLhModule;
+#endif
static char *module_search_path = NULL;
static char lib_python[] = "lib/python" VERSION;
@@ -116,7 +124,7 @@ reduce(char *dir)
size_t i = strlen(dir);
while (i > 0 && dir[i] != SEP)
--i;
- dir[i] = '\0';
+ dir[i] = 0;
}
@@ -187,7 +195,11 @@ static void
joinpath(char *buffer, char *stuff)
{
size_t n, k;
+#ifdef MS_WINDOWS
+ if (stuff[0] == SEP || (stuff[0] != 0 && stuff[1] == ':'))
+#else
if (stuff[0] == SEP)
+#endif
n = 0;
else {
n = strlen(buffer);
@@ -208,7 +220,11 @@ joinpath(char *buffer, char *stuff)
static void
copy_absolute(char *path, char *p)
{
+#ifdef MS_WINDOWS
+ if (p[0] == SEP || (p[0] != 0 && p[1] == ':'))
+#else
if (p[0] == SEP)
+#endif
strcpy(path, p);
else {
if (!getcwd(path, MAXPATHLEN)) {
@@ -228,7 +244,11 @@ absolutize(char *path)
{
char buffer[MAXPATHLEN + 1];
+#ifdef MS_WINDOWS
+ if (path[0] == SEP || (path[0] != 0 && path[1] == ':'))
+#else
if (path[0] == SEP)
+#endif
return;
copy_absolute(buffer, path);
strcpy(path, buffer);
@@ -359,6 +379,35 @@ search_for_exec_prefix(char *argv0_path,
}
+#ifdef MS_WINDOWS
+/* Calculates dllpath and progpath, replacing \\ with / */
+int GetWindowsModulePaths()
+{
+ int result = 0;
+ char* seps;
+ result = GetModuleFileNameA(NULL, progpath, MAXPATHLEN);
+ seps = strchr(progpath, '\\');
+ while(seps) {
+ *seps = '/';
+ seps = strchr(seps, '\\');
+ }
+ dllpath[0] = '\0';
+#ifdef Py_ENABLE_SHARED
+ if (PyWin_DLLhModule) {
+ if((GetModuleFileNameA(PyWin_DLLhModule, dllpath, MAXPATHLEN) > 0)) {
+ result = 1;
+ seps = strchr(dllpath, '\\');
+ while(seps) {
+ *seps = '/';
+ seps = strchr(seps, '\\');
+ }
+ }
+ }
+#endif
+ return result;
+}
+#endif /* MS_WINDOWS */
+
static void
calculate_path(void)
{
@@ -410,6 +459,10 @@ calculate_path(void)
else if(0 == _NSGetExecutablePath(progpath, &nsexeclength) && progpath[0] == SEP)
;
#endif /* __APPLE__ */
+#ifdef MS_WINDOWS
+ else if(GetWindowsModulePaths()) {
+ }
+#endif /* MS_WINDOWS */
else if (path) {
while (1) {
char *delim = strchr(path, DELIM);
@@ -437,7 +490,11 @@ calculate_path(void)
}
else
progpath[0] = '\0';
+#ifdef MS_WINDOWS
+ if (progpath[0] != '\0' && progpath[0] != SEP && progpath[1] != ':')
+#else
if (progpath[0] != SEP && progpath[0] != '\0')
+#endif
absolutize(progpath);
strncpy(argv0_path, progpath, MAXPATHLEN);
argv0_path[MAXPATHLEN] = '\0';
diff -rupN Python-2.7.13/Modules/posixmodule.c Python-2.7.13-new/Modules/posixmodule.c
--- Python-2.7.13/Modules/posixmodule.c 2017-01-21 01:46:05.392619449 +0100
+++ Python-2.7.13-new/Modules/posixmodule.c 2017-01-21 01:46:10.174568394 +0100
@@ -2371,7 +2371,7 @@ posix_listdir(PyObject *self, PyObject *
Py_END_ALLOW_THREADS
/* FindNextFile sets error to ERROR_NO_MORE_FILES if
it got to the end of the directory. */
- if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
+ if (!result && GetLastError() != 0 && GetLastError() != ERROR_NO_MORE_FILES) {
Py_DECREF(d);
win32_error_unicode("FindNextFileW", wnamebuf);
FindClose(hFindFile);
@@ -2439,7 +2439,7 @@ posix_listdir(PyObject *self, PyObject *
Py_END_ALLOW_THREADS
/* FindNextFile sets error to ERROR_NO_MORE_FILES if
it got to the end of the directory. */
- if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
+ if (!result && GetLastError() != 0 && GetLastError() != ERROR_NO_MORE_FILES) {
Py_DECREF(d);
win32_error("FindNextFile", namebuf);
FindClose(hFindFile);