Files
MINGW-packages/mingw-w64-python3/0950-mingw-w64-XP3-compat-GetProcAddress-GetTickCount64.patch
2015-10-05 21:36:30 +01:00

47 lines
1.5 KiB
Diff

--- 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)