MinGW-w64: Switch to using the Posix getpath code

..in Modules/getpathp.c rather than the Windows version
in PC/getpath.c. This is because we want the Posix
file layout.
diff --git a/Python-2.7.5/Modules/getpath.c b/Python-2.7.5/Modules/getpath.c
index 92d5e6b..3c22375 100644
--- a/Python-2.7.5/Modules/getpath.c
+++ b/Python-2.7.5/Modules/getpath.c
@@ -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
@@ -128,6 +132,10 @@
 static char prefix[MAXPATHLEN+1];
 static char exec_prefix[MAXPATHLEN+1];
 static char progpath[MAXPATHLEN+1];
+#ifdef MS_WINDOWS
+static char dllpath[MAXPATHLEN+1];
+extern HANDLE PyWin_DLLhModule;
+#endif
 static char *module_search_path = NULL;
 static char lib_python[] = "lib/python" VERSION;
 
@@ -208,7 +216,11 @@
 joinpath(char *buffer, char *stuff)
 {
     size_t n, k;
+#ifdef MS_WINDOWS
+    if (stuff[0] == SEP || (stuff[0] != 0 && stuff[1] == L':'))
+#else
     if (stuff[0] == SEP)
+#endif
         n = 0;
     else {
         n = strlen(buffer);
@@ -229,7 +241,11 @@
 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)) {
@@ -249,7 +265,11 @@
 {
     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);
@@ -382,6 +402,35 @@
 }
 
 
+#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)
 {
@@ -433,6 +482,10 @@
      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);
@@ -460,7 +513,11 @@
         }
         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 --git a/Python-2.7.5/Modules/posixmodule.c b/Python-2.7.5/Modules/posixmodule.c
index 7ca0298..3b43a55 100644
--- a/Python-2.7.5/Modules/posixmodule.c
+++ b/Python-2.7.5/Modules/posixmodule.c
@@ -2322,7 +2322,7 @@
             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);
@@ -2390,7 +2390,7 @@
         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);
diff --git a/Python-2.7.5/Parser/metagrammar.c b/Python-2.7.5/Parser/metagrammar.c
index 53810b8..8343b87 100644
--- a/Python-2.7.5/Parser/metagrammar.c
+++ b/Python-2.7.5/Parser/metagrammar.c
@@ -139,7 +139,7 @@
     {7, 0},
     {8, 0},
 };
-static grammar _PyParser_Grammar = {
+static grammar _PyParser_MetaGrammar = {
     6,
     dfas,
     {19, labels},
@@ -149,7 +149,7 @@
 grammar *
 meta_grammar(void)
 {
-    return &_PyParser_Grammar;
+    return &_PyParser_MetaGrammar;
 }
 
 grammar *
diff --git a/Python-2.7.5/Python/pythonrun.c b/Python-2.7.5/Python/pythonrun.c
index a2e1e74..b6fbd15 100644
--- a/Python-2.7.5/Python/pythonrun.c
+++ b/Python-2.7.5/Python/pythonrun.c
@@ -18,6 +18,7 @@
 #include "eval.h"
 #include "marshal.h"
 #include "abstract.h"
+#include "osdefs.h"
 
 #ifdef HAVE_SIGNAL_H
 #include <signal.h>
@@ -666,6 +667,13 @@
 void
 Py_SetProgramName(char *pn)
 {
+#ifdef __MINGW32__
+    char* seps = strchr(pn, ALTSEP);
+    while(seps) {
+        *seps = SEP;
+        seps = strchr(seps, ALTSEP);
+    }
+#endif
     if (pn && *pn)
         progname = pn;
 }
diff --git a/Python-2.7.5/configure.ac b/Python-2.7.5/configure.ac
index 5b9d3d0..f5a4e59 100644
--- a/Python-2.7.5/configure.ac
+++ b/Python-2.7.5/configure.ac
@@ -3039,7 +3039,7 @@
 AC_MSG_CHECKING(MACHDEP_OBJS)
 case $host in
   *-*-mingw*)
-    extra_machdep_objs="PC/dl_nt.o PC/getpathp.o PC/import_nt.o"
+    extra_machdep_objs="PC/dl_nt.o Modules/getpath.o PC/import_nt.o"
     ;;
 esac
 if test -z "$MACHDEP_OBJS"
@@ -4794,7 +4794,7 @@
     # FIXME: why windows builds don't use PC/frozen_dllmain.o ?
     PYTHON_OBJS_FROZENMAIN=""
     # default sys.path calculations for windows platforms
-    MODULE_GETPATH=PC/getpathp.o
+    MODULE_GETPATH=Modules/getpath.o
     ;;
 esac