Files
MINGW-packages/mingw-w64-python3/0560-mingw-use-posix-getpath.patch
2015-09-21 15:47:39 +03:00

159 lines
4.6 KiB
Diff

diff -Naur Python-3.5.0-orig/configure.ac Python-3.5.0/configure.ac
--- Python-3.5.0-orig/configure.ac 2015-09-21 13:42:01.382941600 +0300
+++ Python-3.5.0/configure.ac 2015-09-21 13:42:04.711772800 +0300
@@ -5243,7 +5243,7 @@
case $host in
*-*-mingw*)
dnl default sys.path calculations for windows platforms
- MODULE_GETPATH=PC/getpathp.o
+ MODULE_GETPATH=Modules/getpath.o
;;
esac
diff -Naur Python-3.5.0-orig/Modules/getpath.c Python-3.5.0/Modules/getpath.c
--- Python-3.5.0-orig/Modules/getpath.c 2015-09-21 13:42:04.532293600 +0300
+++ Python-3.5.0/Modules/getpath.c 2015-09-21 13:42:04.737735200 +0300
@@ -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
@@ -126,9 +130,17 @@
#define LANDMARK L"os.py"
#endif
+#ifdef __MINGW32__
+#define wcstok(line, delim, pointer) wcstok(line, delim)
+#endif
+
static wchar_t prefix[MAXPATHLEN+1];
static wchar_t exec_prefix[MAXPATHLEN+1];
static wchar_t progpath[MAXPATHLEN+1];
+#ifdef MS_WINDOWS
+static wchar_t dllpath[MAXPATHLEN+1];
+extern HANDLE PyWin_DLLhModule;
+#endif
static wchar_t *module_search_path = NULL;
/* Get file status. Encode the path to the locale encoding. */
@@ -154,7 +166,7 @@
size_t i = wcslen(dir);
while (i > 0 && dir[i] != Py_GetSepW(dir))
--i;
- dir[i] = '\0';
+ dir[i] = 0;
}
static int
@@ -472,6 +484,26 @@
return 0;
}
+#ifdef MS_WINDOWS
+/* Calculates dllpath and progpath, replacing \\ with / */
+int GetWindowsModulePaths()
+{
+ int result = 0;
+ result = GetModuleFileNameW(NULL, progpath, MAXPATHLEN);
+ Py_NormalizeSepsW(progpath);
+ dllpath[0] = 0;
+#ifdef Py_ENABLE_SHARED
+ if (PyWin_DLLhModule) {
+ if((GetModuleFileNameW(PyWin_DLLhModule, dllpath, MAXPATHLEN) > 0)) {
+ result = 1;
+ Py_NormalizeSepsW(dllpath);
+ }
+ }
+#endif
+ return result;
+}
+#endif /* MS_WINDOWS */
+
static void
calculate_path(void)
{
@@ -551,6 +583,10 @@
}
}
#endif /* __APPLE__ */
+#ifdef MS_WINDOWS
+ else if(GetWindowsModulePaths()) {
+ }
+#endif /* MS_WINDOWS */
else if (path) {
while (1) {
wchar_t *delim = wcschr(path, DELIM);
@@ -889,6 +925,45 @@
}
+#ifdef MS_WINDOWS
+/* Load python3.dll before loading any extension module that might refer
+ to it. That way, we can be sure that always the python3.dll corresponding
+ to this python DLL is loaded, not a python3.dll that might be on the path
+ by chance.
+ Return whether the DLL was found.
+*/
+static int python3_checked = 0;
+static HANDLE hPython3;
+int
+_Py_CheckPython3()
+{
+ wchar_t py3path[MAXPATHLEN+1];
+ wchar_t *s;
+ if (python3_checked)
+ return hPython3 != NULL;
+ python3_checked = 1;
+
+ /* If there is a python3.dll next to the python3y.dll,
+ assume this is a build tree; use that DLL */
+ wcscpy(py3path, dllpath);
+ s = wcsrchr(py3path, Py_GetSepW(py3path));
+ if (!s)
+ s = py3path;
+ else
+ s += 1;
+ wcscpy(s, L"python3.dll");
+ hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+ if (hPython3 != NULL)
+ return 1;
+
+ /* Check sys.prefix\DLLs\python3.dll */
+ wcscpy(py3path, Py_GetPrefix());
+ wcscat(py3path, L"\\DLLs\\python3.dll");
+ hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+ return hPython3 != NULL;
+}
+#endif
+
#ifdef __cplusplus
}
#endif
diff -Naur Python-3.5.0-orig/Modules/posixmodule.c Python-3.5.0/Modules/posixmodule.c
--- Python-3.5.0-orig/Modules/posixmodule.c 2015-09-21 13:42:04.541324000 +0300
+++ Python-3.5.0/Modules/posixmodule.c 2015-09-21 13:42:04.747894400 +0300
@@ -3548,7 +3548,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(list);
list = path_error(path);
goto exit;
@@ -3603,7 +3603,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(list);
list = path_error(path);
goto exit;