mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
bpo-41710: Add _PyTime_AsTimespec_clamp() (GH-28629)
Add the _PyTime_AsTimespec_clamp() function: similar to _PyTime_AsTimespec(), but clamp to _PyTime_t min/max and don't raise an exception. PyThread_acquire_lock_timed() now uses _PyTime_AsTimespec_clamp() to remove the Py_UNREACHABLE() code path. * Add _PyTime_AsTime_t() function. * Add PY_TIME_T_MIN and PY_TIME_T_MAX constants. * Replace _PyTime_AsTimeval_noraise() with _PyTime_AsTimeval_clamp(). * Add pytime_divide_round_up() function. * Fix integer overflow in pytime_divide(). * Add pytime_divmod() function.
This commit is contained in:
parent
8d3e7eff09
commit
09796f2f14
8 changed files with 270 additions and 92 deletions
|
@ -481,11 +481,7 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,
|
|||
}
|
||||
else if (dt > 0) {
|
||||
_PyTime_t realtime_deadline = _PyTime_GetSystemClock() + dt;
|
||||
if (_PyTime_AsTimespec(realtime_deadline, &ts) < 0) {
|
||||
/* Cannot occur thanks to (microseconds > PY_TIMEOUT_MAX)
|
||||
check done above */
|
||||
Py_UNREACHABLE();
|
||||
}
|
||||
_PyTime_AsTimespec_clamp(realtime_deadline, &ts);
|
||||
/* no need to update microseconds value, the code only care
|
||||
if (microseconds > 0 or (microseconds == 0). */
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue