Skip to content

Commit

Permalink
python3: Bring XP support back to 3.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mingwandroid committed Oct 5, 2015
1 parent 97cb820 commit 861c312
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 1 deletion.
@@ -0,0 +1,46 @@
--- Python-3.5.0/Python/pytime.c.orig 2015-10-05 21:30:23.839918600 +0100
+++ Python-3.5.0/Python/pytime.c 2015-10-05 21:30:28.078842500 +0100
@@ -435,7 +435,7 @@
/* 11,644,473,600,000,000,000: number of nanoseconds between
the 1st january 1601 and the 1st january 1970 (369 years + 89 leap
days). */
- *tp = large.QuadPart * 100 - 11644473600000000000;
+ *tp = large.QuadPart * 100 - 11644473600000000000ULL;
if (info) {
DWORD timeAdjustment, timeIncrement;
BOOL isTimeAdjustmentDisabled, ok;
@@ -529,6 +529,34 @@
return pygettimeofday_new(t, info, 1);
}

+#if defined(MS_WINDOWS) && _WIN32_WINNT < 0x0600
+/* GetTickCount64() is not available on XP. */
+ULONGLONG GetTickCount64 ()
+{
+ static ULONGLONG (CALLBACK *Py_GetTickCount64)() = (ULONGLONG (*)(void))-1;
+ static DWORD last_ticks = 0;
+ static DWORD n_overflow = 0;
+ DWORD ticks = 0;
+ HINSTANCE hKernel32;
+
+ if (Py_GetTickCount64 == (void*)-1)
+ {
+ hKernel32 = GetModuleHandleW(L"KERNEL32");
+ Py_GetTickCount64 = *(ULONGLONG (*)(void))(GetProcAddress(hKernel32,
+ "GetTickCount64"));
+ }
+ if (Py_GetTickCount64 != (void*)-1)
+ {
+ return Py_GetTickCount64();
+ }
+
+ ticks = GetTickCount();
+ if (ticks < last_ticks)
+ n_overflow++;
+ last_ticks = ticks;
+ return ((ULONGLONG)n_overflow << 32LL) + (ULONGLONG)GetTickCount();
+}
+#endif

static int
pymonotonic_new(_PyTime_t *tp, _Py_clock_info_t *info, int raise)
@@ -0,0 +1,114 @@
--- Python-3.5.0/Modules/posixmodule.c.orig 2015-10-05 21:34:15.284022500 +0100
+++ Python-3.5.0/Modules/posixmodule.c 2015-10-05 21:34:18.082536800 +0100
@@ -1462,6 +1462,31 @@
return TRUE;
}

+/* Grab GetFinalPathNameByHandle dynamically from kernel32 */
+static int has_GetFinalPathNameByHandle = -1;
+static DWORD (CALLBACK *Py_GetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD,
+ DWORD);
+static int
+check_GetFinalPathNameByHandle()
+{
+ HINSTANCE hKernel32;
+ DWORD (CALLBACK *Py_GetFinalPathNameByHandleA)(HANDLE, LPSTR, DWORD,
+ DWORD);
+
+ /* only recheck */
+ if (-1 == has_GetFinalPathNameByHandle)
+ {
+ hKernel32 = GetModuleHandleW(L"KERNEL32");
+ *(FARPROC*)&Py_GetFinalPathNameByHandleA = GetProcAddress(hKernel32,
+ "GetFinalPathNameByHandleA");
+ *(FARPROC*)&Py_GetFinalPathNameByHandleW = GetProcAddress(hKernel32,
+ "GetFinalPathNameByHandleW");
+ has_GetFinalPathNameByHandle = Py_GetFinalPathNameByHandleA &&
+ Py_GetFinalPathNameByHandleW;
+ }
+ return has_GetFinalPathNameByHandle;
+}
+
static BOOL
get_target_path(HANDLE hdl, wchar_t **target_path)
{
@@ -1470,8 +1495,8 @@

/* We have a good handle to the target, use it to determine
the target path name (then we'll call lstat on it). */
- buf_size = GetFinalPathNameByHandleW(hdl, 0, 0,
- VOLUME_NAME_DOS);
+ buf_size = Py_GetFinalPathNameByHandleW(hdl, 0, 0,
+ VOLUME_NAME_DOS);
if(!buf_size)
return FALSE;

@@ -1481,7 +1506,7 @@
return FALSE;
}

- result_length = GetFinalPathNameByHandleW(hdl,
+ result_length = Py_GetFinalPathNameByHandleW(hdl,
buf, buf_size, VOLUME_NAME_DOS);

if(!result_length) {
@@ -1514,6 +1539,12 @@
wchar_t *target_path;
const char *dot;

+ if(!check_GetFinalPathNameByHandle()) {
+ /* If the OS doesn't have GetFinalPathNameByHandle, don't
+ traverse reparse point. */
+ traverse = FALSE;
+ }
+
hFile = CreateFileA(
path,
FILE_READ_ATTRIBUTES, /* desired access */
@@ -1604,6 +1635,12 @@
wchar_t *target_path;
const wchar_t *dot;

+ if(!check_GetFinalPathNameByHandle()) {
+ /* If the OS doesn't have GetFinalPathNameByHandle, don't
+ traverse reparse point. */
+ traverse = FALSE;
+ }
+
hFile = CreateFileW(
path,
FILE_READ_ATTRIBUTES, /* desired access */
@@ -3846,6 +3883,13 @@
if (path_wchar == NULL)
return NULL;

+ if(!check_GetFinalPathNameByHandle()) {
+ /* If the OS doesn't have GetFinalPathNameByHandle, return a
+ NotImplementedError. */
+ return PyErr_Format(PyExc_NotImplementedError,
+ "GetFinalPathNameByHandle not available on this platform");
+ }
+
hFile = CreateFileW(
path_wchar,
0, /* desired access */
@@ -3861,7 +3905,7 @@

/* We have a good handle to the target, use it to determine the
target path name. */
- buf_size = GetFinalPathNameByHandleW(hFile, 0, 0, VOLUME_NAME_NT);
+ buf_size = Py_GetFinalPathNameByHandleW(hFile, 0, 0, VOLUME_NAME_NT);

if(!buf_size)
return win32_error_object("GetFinalPathNameByHandle", path);
@@ -3870,8 +3914,8 @@
if(!target_path)
return PyErr_NoMemory();

- result_length = GetFinalPathNameByHandleW(hFile, target_path,
- buf_size, VOLUME_NAME_DOS);
+ result_length = Py_GetFinalPathNameByHandleW(hFile, target_path,
+ buf_size, VOLUME_NAME_DOS);
if(!result_length)
return win32_error_object("GetFinalPathNamyByHandle", path);

8 changes: 7 additions & 1 deletion mingw-w64-python3/PKGBUILD
Expand Up @@ -18,7 +18,7 @@ pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pybasever=3.5
pkgver=${_pybasever}.0
pkgrel=1
pkgrel=2
pkgdesc="A high-level scripting language (mingw-w64)"
arch=('any')
license=('PSF')
Expand Down Expand Up @@ -120,6 +120,8 @@ source=("http://www.python.org/ftp/python/${pkgver%rc?}/Python-${pkgver}.tar.xz"
0920-mingw-add-LIBPL-to-library-dirs.patch
0930-mingw-w64-build-overlapped-module.patch
0940-mingw-w64-Also-define-_Py_BEGIN_END_SUPPRESS_IPH-when-Py_BUILD_CORE_MODULE.patch
0950-mingw-w64-XP3-compat-GetProcAddress-GetTickCount64.patch
0960-mingw-w64-XP3-compat-GetProcAddress-GetFinalPathNameByHandleW.patch
1000-fix-building-posixmodule.patch
1010-install-msilib.patch
1500-mingw-w64-dont-look-in-DLLs-folder-for-python-dll.patch)
Expand Down Expand Up @@ -222,6 +224,8 @@ prepare() {
patch -Np1 -i "${srcdir}"/0920-mingw-add-LIBPL-to-library-dirs.patch
patch -Np1 -i "${srcdir}"/0930-mingw-w64-build-overlapped-module.patch
patch -Np1 -i "${srcdir}"/0940-mingw-w64-Also-define-_Py_BEGIN_END_SUPPRESS_IPH-when-Py_BUILD_CORE_MODULE.patch
patch -Np1 -i "${srcdir}"/0950-mingw-w64-XP3-compat-GetProcAddress-GetTickCount64.patch
patch -Np1 -i "${srcdir}"/0960-mingw-w64-XP3-compat-GetProcAddress-GetFinalPathNameByHandleW.patch

patch -Np1 -i "${srcdir}"/1000-fix-building-posixmodule.patch
patch -Np1 -i "${srcdir}"/1010-install-msilib.patch
Expand Down Expand Up @@ -461,6 +465,8 @@ sha1sums=('871a06df9ab70984b7398ac53047fe125c757a70'
'ce026983639b7e5e503b32345bbcf81972447868'
'8ca0fdb71ee8198997b30466c367ac0c84f14237'
'4564e95c83e30dca025d6a7ecf0b24a709ea5120'
'79ff9a468dcfd2c55afa70758bd6a50b2a940ed4'
'2bf23da1017ab6ed5bc59c4f3fbf713093036a09'
'a97dbe5299385b9fde442779d00f9a161ef3f950'
'd5c9e4e47db62db241f4488d9bc974b083b7b0e3'
'c7eb543aee59f4c246018fa7943a1eaa12e6809c')

0 comments on commit 861c312

Please sign in to comment.