mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
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).
This commit is contained in:
parent
0df19055c9
commit
bdaeb7d237
4 changed files with 137 additions and 50 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue