summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiaoling Bao <xiaolingbao@google.com>2019-03-17 10:50:08 -0700
committerGiampaolo Rodola <g.rodola@gmail.com>2019-03-17 18:50:08 +0100
commit7b70d288648aa1117c2f7043092269de35105bec (patch)
tree1374f38bd860ec23e73999a0695140176733119e
parent01ca8967d5d875dcb1747875bb76149d70835452 (diff)
downloadpsutil-7b70d288648aa1117c2f7043092269de35105bec.tar.gz
Make uptime type consitent to fix boot time error. (#1225)
-rw-r--r--psutil/_psutil_windows.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 092b5af2..a11d8c5c 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -134,14 +134,12 @@ static PyObject *TimeoutAbandoned;
*/
static PyObject *
psutil_boot_time(PyObject *self, PyObject *args) {
-#if (_WIN32_WINNT >= 0x0600) // Windows Vista
ULONGLONG uptime;
-#else
- double uptime;
-#endif
time_t pt;
FILETIME fileTime;
- long long ll;
+ ULONGLONG ll;
+ HINSTANCE hKernel32;
+ psutil_GetTickCount64 = NULL;
GetSystemTimeAsFileTime(&fileTime);
/*
@@ -157,33 +155,26 @@ psutil_boot_time(PyObject *self, PyObject *args) {
and 01-01-1601, from time_t the divide by 1e+7 to get to the same
base granularity.
*/
-#if (_WIN32_WINNT >= 0x0600) // Windows Vista
ll = (((ULONGLONG)
-#else
- ll = (((LONGLONG)
-#endif
(fileTime.dwHighDateTime)) << 32) + fileTime.dwLowDateTime;
pt = (time_t)((ll - 116444736000000000ull) / 10000000ull);
- // GetTickCount64() is Windows Vista+ only. Dinamically load
- // it at runtime. We may have used
+ // GetTickCount64() is Windows Vista+ only. Dynamically load
+ // GetTickCount64() at runtime. We may have used
// "#if (_WIN32_WINNT >= 0x0600)" pre-processor but that way
// the produced exe/wheels cannot be used on Windows XP, see:
// https://github.com/giampaolo/psutil/issues/811#issuecomment-230639178
if (psutil_GetTickCount64 != NULL) {
// Windows >= Vista
- uptime = psutil_GetTickCount64() / (ULONGLONG)1000.00f;
- return Py_BuildValue("K", pt - uptime);
+ uptime = psutil_GetTickCount64() / 1000ull;
}
else {
// Windows XP.
// GetTickCount() time will wrap around to zero if the
// system is run continuously for 49.7 days.
- psutil_debug("Windows < Vista; using GetTickCount() instead of "
- "GetTickCount64()");
- uptime = GetTickCount() / (LONGLONG)1000.00f;
- return Py_BuildValue("L", pt - uptime);
+ uptime = (ULONGLONG)GetTickCount() / 1000ull;
}
+ return Py_BuildValue("K", pt - uptime);
}