Blame 0560-mingw-use-posix-getpath.patch

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