Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb35229

Browse files
committed
Issue #23451, #22117: Python 3.5 now requires Windows Vista or newer, so
GetTickCount64() is now always available.
1 parent cb29f01 commit eb35229

1 file changed

Lines changed: 2 additions & 47 deletions

File tree

Python/pytime.c

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
#define MS_TO_NS (MS_TO_US * US_TO_NS)
2020
#define SEC_TO_NS (SEC_TO_MS * MS_TO_NS)
2121

22-
#ifdef MS_WINDOWS
23-
static OSVERSIONINFOEX winver;
24-
#endif
25-
2622
static int
2723
pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info, int raise)
2824
{
@@ -542,41 +538,11 @@ pymonotonic_new(_PyTime_t *tp, _Py_clock_info_t *info, int raise)
542538
static _PyTime_t last = 0;
543539
#endif
544540
#if defined(MS_WINDOWS)
545-
static ULONGLONG (*GetTickCount64) (void) = NULL;
546-
static ULONGLONG (CALLBACK *Py_GetTickCount64)(void);
547-
static int has_gettickcount64 = -1;
548541
ULONGLONG result;
549542

550543
assert(info == NULL || raise);
551544

552-
if (has_gettickcount64 == -1) {
553-
/* GetTickCount64() was added to Windows Vista */
554-
has_gettickcount64 = (winver.dwMajorVersion >= 6);
555-
if (has_gettickcount64) {
556-
HINSTANCE hKernel32;
557-
hKernel32 = GetModuleHandleW(L"KERNEL32");
558-
*(FARPROC*)&Py_GetTickCount64 = GetProcAddress(hKernel32,
559-
"GetTickCount64");
560-
assert(Py_GetTickCount64 != NULL);
561-
}
562-
}
563-
564-
if (has_gettickcount64) {
565-
result = Py_GetTickCount64();
566-
}
567-
else {
568-
static DWORD last_ticks = 0;
569-
static DWORD n_overflow = 0;
570-
DWORD ticks;
571-
572-
ticks = GetTickCount();
573-
if (ticks < last_ticks)
574-
n_overflow++;
575-
last_ticks = ticks;
576-
577-
result = (ULONGLONG)n_overflow << 32;
578-
result += ticks;
579-
}
545+
result = GetTickCount64();
580546

581547
*tp = result * MS_TO_NS;
582548
if (*tp / MS_TO_NS != result) {
@@ -591,10 +557,7 @@ pymonotonic_new(_PyTime_t *tp, _Py_clock_info_t *info, int raise)
591557
if (info) {
592558
DWORD timeAdjustment, timeIncrement;
593559
BOOL isTimeAdjustmentDisabled, ok;
594-
if (has_gettickcount64)
595-
info->implementation = "GetTickCount64()";
596-
else
597-
info->implementation = "GetTickCount()";
560+
info->implementation = "GetTickCount64()";
598561
info->monotonic = 1;
599562
ok = GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement,
600563
&isTimeAdjustmentDisabled);
@@ -692,14 +655,6 @@ _PyTime_Init(void)
692655
_PyTime_timeval tv;
693656
_PyTime_t t;
694657

695-
#ifdef MS_WINDOWS
696-
winver.dwOSVersionInfoSize = sizeof(winver);
697-
if (!GetVersionEx((OSVERSIONINFO*)&winver)) {
698-
PyErr_SetFromWindowsErr(0);
699-
return -1;
700-
}
701-
#endif
702-
703658
/* ensure that the system clock works */
704659
if (_PyTime_gettimeofday_info(&tv, NULL) < 0)
705660
return -1;

0 commit comments

Comments
 (0)