Files
MINGW-packages/mingw-w64-python3/0950-mingw-w64-XP3-compat-GetProcAddress-GetTickCount64.patch
2016-07-12 14:49:26 +03:00

48 lines
1.6 KiB
Diff

diff -Naur Python-3.5.2-orig/Python/pytime.c Python-3.5.2/Python/pytime.c
--- Python-3.5.2-orig/Python/pytime.c 2016-06-26 00:38:38.000000000 +0300
+++ Python-3.5.2/Python/pytime.c 2016-07-12 14:23:01.904300700 +0300
@@ -463,7 +463,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;
@@ -557,6 +557,34 @@
return pygettimeofday(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(_PyTime_t *tp, _Py_clock_info_t *info, int raise)