Files
MINGW-packages/mingw-w64-python3/0045-mingw-use-posix-getpath.patch
2013-12-09 00:08:47 +04:00

453 lines
14 KiB
Diff

diff -urN a/configure.ac b/configure.ac
--- a/configure.ac 2013-04-24 23:35:34.545710821 +0100
+++ b/configure.ac 2013-04-24 23:35:34.891713117 +0100
@@ -576,6 +576,27 @@
fi
AC_MSG_RESULT($MACHDEP)
+# Windows uses ; to separate paths, everything else uses :
+AC_MSG_CHECKING(DELIM)
+DELIM=:
+if test "$MACHDEP" = "win"
+then
+ DELIM=\;
+fi
+AC_MSG_RESULT([$DELIM])
+AC_SUBST(DELIM)
+
+# MSYS make uses a 'virtual' VPATH, but getpath.c uses
+# GetModuleFileNameW (replacing \ with /). This allows the user to
+# define the 'actual 'real' value. Note, it should contain / not \,
+# which is what is returned by "pwd -W".
+AC_ARG_VAR(MSYSVPATH,
+ For MSYS, allows specifying the real VPATH. Use / not \)
+if test -z "$MSYSVPATH"; then
+ MSYSVPATH=$srcdir
+fi
+AC_SUBST(MSYSVPATH)
+
AC_MSG_CHECKING([for init system calls])
AC_SUBST(INITSYS)
case $host in
@@ -4255,6 +4276,28 @@
# check for endianness
AC_C_BIGENDIAN
+# REPARSE_DATA_BUFFER is in winnt.h on mingw32 and (unusably) ddk/ntifs.h on mingw64.
+case $host in
+ *-*-mingw*)
+AC_CACHE_CHECK([if struct REPARSE_DATA_BUFFER is in winnt.h],
+[ac_cv_struct_reparse_data_buffer_in_winnt_h],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [#include <windows.h>
+ #include <winnt.h>],
+ [REPARSE_DATA_BUFFER rdb],
+ )],
+ [ac_cv_struct_reparse_data_buffer_in_winnt_h=yes],
+ [ac_cv_struct_reparse_data_buffer_in_winnt_h=no]
+ )
+])
+if test "x${ac_cv_struct_reparse_data_buffer_in_winnt_h}" = xyes; then
+ AC_DEFINE([REPARSE_DATA_BUFFER_IN_WINNT], [], [REPARSE_DATA_BUFFER in winnt.h])
+ AC_SUBST(REPARSE_DATA_BUFFER_IN_WINNT)
+fi
+ ;;
+esac
+
# ABI version string for Python extension modules. This appears between the
# periods in shared library file names, e.g. foo.<SOABI>.so. It is calculated
# from the following attributes which affect the ABI of this Python build (in
@@ -4950,7 +4993,8 @@
# 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=PC/getpathp.o
+ MODULE_GETPATH=Modules/getpath.o
;;
esac
diff -urN a/Include/fileutils.h b/Include/fileutils.h
--- a/Include/fileutils.h 2013-04-24 23:35:34.542710801 +0100
+++ b/Include/fileutils.h 2013-04-24 23:35:34.882713057 +0100
@@ -15,7 +15,7 @@
const wchar_t *text,
size_t *error_pos);
-#if defined(HAVE_STAT) && !defined(MS_WINDOWS)
+#if defined(HAVE_STAT) && (!defined(MS_WINDOWS) || defined(__MINGW32__))
PyAPI_FUNC(int) _Py_wstat(
const wchar_t* path,
struct stat *buf);
diff -urN a/Include/osdefs.h b/Include/osdefs.h
--- a/Include/osdefs.h 2013-04-24 23:35:34.543710808 +0100
+++ b/Include/osdefs.h 2013-04-24 23:35:34.883713064 +0100
@@ -10,7 +10,7 @@
/* Mod by chrish: QNX has WATCOM, but isn't DOS */
#if !defined(__QNX__)
#if defined(MS_WINDOWS) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__DJGPP__) || defined(PYOS_OS2)
-#if defined(PYOS_OS2) && defined(PYCC_GCC)
+#if (defined(PYOS_OS2) && defined(PYCC_GCC)) || defined(__MINGW32__)
#define MAXPATHLEN 260
#define SEP L'/'
#define ALTSEP L'\\'
@@ -22,6 +22,7 @@
#endif
#endif
#define DELIM L';'
+#define DELIMSTR ";"
#endif
#endif
@@ -42,6 +43,7 @@
/* Search path entry delimiter */
#ifndef DELIM
#define DELIM L':'
+#define DELIMSTR ":"
#endif
#ifdef __cplusplus
diff -urN a/Lib/plat-generic/regen b/Lib/plat-generic/regen
--- a/Lib/plat-generic/regen 2013-04-24 23:35:34.638711438 +0100
+++ b/Lib/plat-generic/regen 2013-04-24 23:35:34.884713071 +0100
@@ -1,3 +1,9 @@
#! /bin/sh
set -v
-eval $PYTHON_FOR_BUILD ../../Tools/scripts/h2py.py -i "'(u_long)'" /usr/include/netinet/in.h
+if [ -n "$1" ]; then
+ CCINSTALL=$($1 -print-search-dirs | head -1 | cut -d' ' -f2)
+ REGENHEADER=${CCINSTALL//\\//}/include/stddef.h
+else
+ REGENHEADER=/usr/include/netinet/in.h
+fi
+eval $PYTHON_FOR_BUILD ../../Tools/scripts/h2py.py -i "'(u_long)'" $REGENHEADER
diff -urN a/Makefile.pre.in b/Makefile.pre.in
--- a/Makefile.pre.in 2013-04-24 23:35:34.542710801 +0100
+++ b/Makefile.pre.in 2013-04-24 23:35:34.886713084 +0100
@@ -27,6 +27,7 @@
VERSION= @VERSION@
srcdir= @srcdir@
VPATH= @srcdir@
+MSYSVPATH= @MSYSVPATH@
abs_srcdir= @abs_srcdir@
abs_builddir= @abs_builddir@
@@ -89,7 +90,8 @@
# C flags used for building the interpreter object files
PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
-
+# ; on Windows otherwise :
+DELIM= @DELIM@
# Machine-dependent subdirectories
MACHDEP= @MACHDEP@
@@ -625,7 +627,7 @@
-DPREFIX='"$(prefix)"' \
-DEXEC_PREFIX='"$(exec_prefix)"' \
-DVERSION='"$(VERSION)"' \
- -DVPATH='"$(VPATH)"' \
+ -DVPATH='"$(MSYSVPATH)"' \
-o $@ $(srcdir)/Modules/getpath.c
# default sys.path calculations for windows platforms
@@ -930,6 +932,7 @@
if test -f $(LDLIBRARY); then \
if test -n "$(DLLLIBRARY)" ; then \
$(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \
+ mkdir -p $(DESTDIR)$(LIBPL); $(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBPL); \
else \
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
if test $(LDLIBRARY) != $(INSTSONAME); then \
@@ -1120,7 +1123,7 @@
else \
PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)"; \
fi; \
- cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen
+ cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen "$(CC)"
python-config: $(srcdir)/Misc/python-config.in
# Substitution happens here, as the completely-expanded BINDIR
diff -urN a/Modules/getpath.c b/Modules/getpath.c
--- a/Modules/getpath.c 2013-04-24 23:35:34.503710542 +0100
+++ b/Modules/getpath.c 2013-04-24 23:35:34.887713090 +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
@@ -122,7 +126,7 @@
#endif
#ifndef PYTHONPATH
-#define PYTHONPATH PREFIX "/lib/python" VERSION ":" \
+#define PYTHONPATH PREFIX "/lib/python" VERSION DELIMSTR \
EXEC_PREFIX "/lib/python" VERSION "/lib-dynload"
#endif
@@ -130,9 +134,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;
static int module_search_path_malloced = 0;
static wchar_t *lib_python = L"lib/python" VERSION;
@@ -143,7 +155,7 @@
size_t i = wcslen(dir);
while (i > 0 && dir[i] != SEP)
--i;
- dir[i] = '\0';
+ dir[i] = 0;
}
static int
@@ -213,7 +225,11 @@
joinpath(wchar_t *buffer, wchar_t *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 = wcslen(buffer);
@@ -234,7 +250,11 @@
static void
copy_absolute(wchar_t *path, wchar_t *p, size_t pathlen)
{
+#ifdef MS_WINDOWS
+ if (p[0] == SEP || (p[0] != 0 && p[1] == L':'))
+#else
if (p[0] == SEP)
+#endif
wcscpy(path, p);
else {
if (!_Py_wgetcwd(path, pathlen)) {
@@ -254,7 +274,11 @@
{
wchar_t buffer[MAXPATHLEN+1];
+#ifdef MS_WINDOWS
+ if (path[0] == SEP || (path[0] != 0 && path[1] == L':'))
+#else
if (path[0] == SEP)
+#endif
return;
copy_absolute(buffer, path, MAXPATHLEN+1);
wcscpy(path, buffer);
@@ -451,6 +475,35 @@
return 0;
}
+#ifdef MS_WINDOWS
+/* Calculates dllpath and progpath, replacing \\ with / */
+int GetWindowsModulePaths()
+{
+ int result = 0;
+ wchar_t* seps;
+ result = GetModuleFileNameW(NULL, progpath, MAXPATHLEN);
+ seps = wcschr(progpath, L'\\');
+ while(seps) {
+ *seps = L'/';
+ seps = wcschr(seps, L'\\');
+ }
+ dllpath[0] = 0;
+#ifdef Py_ENABLE_SHARED
+ if (PyWin_DLLhModule) {
+ if((GetModuleFileNameW(PyWin_DLLhModule, dllpath, MAXPATHLEN) > 0)) {
+ result = 1;
+ seps = wcschr(dllpath, L'\\');
+ while(seps) {
+ *seps = L'/';
+ seps = wcschr(seps, L'\\');
+ }
+ }
+ }
+#endif
+ return result;
+}
+#endif /* MS_WINDOWS */
+
static void
calculate_path(void)
{
@@ -527,6 +580,10 @@
}
}
#endif /* __APPLE__ */
+#ifdef MS_WINDOWS
+ else if(GetWindowsModulePaths()) {
+ }
+#endif /* MS_WINDOWS */
else if (path) {
while (1) {
wchar_t *delim = wcschr(path, DELIM);
@@ -556,7 +613,11 @@
progpath[0] = '\0';
if (path_buffer != NULL)
PyMem_Free(path_buffer);
+#ifdef MS_WINDOWS
+ if (progpath[0] != '\0' && progpath[0] != SEP && progpath[1] != L':')
+#else
if (progpath[0] != SEP && progpath[0] != '\0')
+#endif
absolutize(progpath);
wcsncpy(argv0_path, progpath, MAXPATHLEN);
argv0_path[MAXPATHLEN] = '\0';
@@ -873,7 +934,43 @@
}
-#ifdef __cplusplus
+#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, L'\\');
+ if (!s)
+ s = py3path;
+ 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 -urN a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c 2013-04-24 23:35:34.506710562 +0100
+++ b/Modules/posixmodule.c 2013-04-24 23:35:34.889713104 +0100
@@ -791,7 +791,7 @@
}
/* A helper used by a number of POSIX-only functions */
-#ifndef MS_WINDOWS
+#if !defined(MS_WINDOWS) || defined(__MINGW32__)
static int
_parse_off_t(PyObject* arg, void* addr)
{
@@ -3430,7 +3430,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 = win32_error_unicode("FindNextFileW", wnamebuf);
goto exit;
@@ -3485,7 +3485,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 = win32_error("FindNextFile", namebuf);
goto exit;
diff -urN a/Modules/Setup.config.in b/Modules/Setup.config.in
--- a/Modules/Setup.config.in 2013-04-24 23:35:34.507710569 +0100
+++ b/Modules/Setup.config.in 2013-04-24 23:35:34.887713090 +0100
@@ -15,6 +15,8 @@
# On win32 host(mingw build in MSYS environment) show that site.py
# fail to load if some modules are not build-in:
@BUILDIN_WIN32_MODULE@winreg ../PC/winreg.c
+@BUILDIN_WIN32_MODULE@time timemodule.c
+@BUILDIN_WIN32_MODULE@msvcrt ../PC/msvcrtmodule.c
# The rest of the modules previously listed in this file are built
diff -urN a/Modules/Setup.dist b/Modules/Setup.dist
--- a/Modules/Setup.dist 2013-04-24 23:35:34.513710609 +0100
+++ b/Modules/Setup.dist 2013-04-24 23:35:34.887713090 +0100
@@ -84,14 +84,14 @@
# Empty since this is now just the runtime prefix.
DESTPATH=
-# Site specific path components -- should begin with : if non-empty
+# Site specific path components -- should begin with $(DELIM) if non-empty
SITEPATH=
# Standard path components for test modules
TESTPATH=
# Path components for machine- or system-dependent modules and shared libraries
-MACHDEPPATH=:plat-$(MACHDEP)
+MACHDEPPATH=$(DELIM)plat-$(MACHDEP)
EXTRAMACHDEPPATH=
COREPYTHONPATH=$(DESTPATH)$(SITEPATH)$(TESTPATH)$(MACHDEPPATH)$(EXTRAMACHDEPPATH)
diff -urN a/Python/fileutils.c b/Python/fileutils.c
--- a/Python/fileutils.c 2013-04-24 23:35:34.473710343 +0100
+++ b/Python/fileutils.c 2013-04-24 23:35:34.889713104 +0100
@@ -251,7 +251,7 @@
Not sure whether the MS_WINDOWS guards are necessary:
perhaps for cygwin/mingw builds?
*/
-#if defined(HAVE_STAT) && !defined(MS_WINDOWS)
+#if defined(HAVE_STAT) && (!defined(MS_WINDOWS) || defined(__MINGW32__))
/* Get file status. Encode the path to the locale encoding. */
diff -urN a/Python/pythonrun.c b/Python/pythonrun.c
--- a/Python/pythonrun.c 2013-04-24 23:35:34.479710383 +0100
+++ b/Python/pythonrun.c 2013-04-24 23:35:34.890713110 +0100
@@ -787,6 +787,13 @@
void
Py_SetProgramName(wchar_t *pn)
{
+#ifdef __MINGW32__
+ wchar_t* seps = wcschr(pn, ALTSEP);
+ while(seps) {
+ *seps = SEP;
+ seps = wcschr(seps, ALTSEP);
+ }
+#endif
if (pn && *pn)
progname = pn;
}