summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-10-16 15:44:31 (GMT)
committerGitHub <noreply@github.com>2017-10-16 15:44:31 (GMT)
commitbdaeb7d237462a629e6c85001317faa85f94a0c6 (patch)
tree65dd0eb7017f7cb7dc79467afb655d3b56337100 /Modules
parent0df19055c92a0b0728659807978e4ca4d6c8e1bc (diff)
downloadcpython-bdaeb7d237462a629e6c85001317faa85f94a0c6.zip
cpython-bdaeb7d237462a629e6c85001317faa85f94a0c6.tar.gz
cpython-bdaeb7d237462a629e6c85001317faa85f94a0c6.tar.bz2
bpo-31773: _PyTime_GetPerfCounter() uses _PyTime_t (GH-3983)
* Rewrite win_perf_counter() to only use integers internally. * Add _PyTime_MulDiv() which compute "ticks * mul / div" in two parts (int part and remaining) to prevent integer overflow. * Clock frequency is checked at initialization for integer overflow. * Enhance also pymonotonic() to reduce the precision loss on macOS (mach_absolute_time() clock).
Diffstat (limited to 'Modules')
-rw-r--r--Modules/timemodule.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 3cb1b4e..6af9a90 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -91,11 +91,12 @@ floatclock(_Py_clock_info_t *info)
static PyObject*
perf_counter(_Py_clock_info_t *info)
{
- double t;
- if (_PyTime_GetPerfCounterDoubleWithInfo(&t, info) < 0) {
+ _PyTime_t t;
+ if (_PyTime_GetPerfCounterWithInfo(&t, info) < 0) {
return NULL;
}
- return PyFloat_FromDouble(t);
+ double d = _PyTime_AsSecondsDouble(t);
+ return PyFloat_FromDouble(d);
}
#if defined(MS_WINDOWS) || defined(HAVE_CLOCK)