diff options
author | Victor Stinner <vstinner@python.org> | 2021-09-30 00:11:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-30 00:11:41 (GMT) |
commit | 09796f2f142fdb1214f34a3ca917959ecb32a88b (patch) | |
tree | 28ec5f6d88dbaaff416418964ce430221b7cacd0 /Include/cpython/pytime.h | |
parent | 8d3e7eff0936926554db6162c992af5829dc8160 (diff) | |
download | cpython-09796f2f142fdb1214f34a3ca917959ecb32a88b.zip cpython-09796f2f142fdb1214f34a3ca917959ecb32a88b.tar.gz cpython-09796f2f142fdb1214f34a3ca917959ecb32a88b.tar.bz2 |
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.
Diffstat (limited to 'Include/cpython/pytime.h')
-rw-r--r-- | Include/cpython/pytime.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Include/cpython/pytime.h b/Include/cpython/pytime.h index 8c29585..04c43ac 100644 --- a/Include/cpython/pytime.h +++ b/Include/cpython/pytime.h @@ -16,6 +16,7 @@ extern "C" { typedef int64_t _PyTime_t; #define _PyTime_MIN INT64_MIN #define _PyTime_MAX INT64_MAX +#define _SIZEOF_PYTIME_T 8 typedef enum { /* Round towards minus infinity (-inf). @@ -136,8 +137,9 @@ PyAPI_FUNC(int) _PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round); -/* Similar to _PyTime_AsTimeval(), but don't raise an exception on error. */ -PyAPI_FUNC(int) _PyTime_AsTimeval_noraise(_PyTime_t t, +/* Similar to _PyTime_AsTimeval() but don't raise an exception on overflow. + On overflow, clamp tv_sec to _PyTime_t min/max. */ +PyAPI_FUNC(void) _PyTime_AsTimeval_clamp(_PyTime_t t, struct timeval *tv, _PyTime_round_t round); @@ -162,6 +164,10 @@ PyAPI_FUNC(int) _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts); tv_nsec is always positive. Raise an exception and return -1 on error, return 0 on success. */ PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts); + +/* Similar to _PyTime_AsTimespec() but don't raise an exception on overflow. + On overflow, clamp tv_sec to _PyTime_t min/max. */ +PyAPI_FUNC(void) _PyTime_AsTimespec_clamp(_PyTime_t t, struct timespec *ts); #endif /* Compute ticks * mul / div. @@ -181,7 +187,7 @@ typedef struct { /* Get the current time from the system clock. If the internal clock fails, silently ignore the error and return 0. - On integer overflow, silently ignore the overflow and truncated the clock to + On integer overflow, silently ignore the overflow and clamp the clock to _PyTime_MIN or _PyTime_MAX. Use _PyTime_GetSystemClockWithInfo() to check for failure. */ @@ -201,7 +207,7 @@ PyAPI_FUNC(int) _PyTime_GetSystemClockWithInfo( results of consecutive calls is valid. If the internal clock fails, silently ignore the error and return 0. - On integer overflow, silently ignore the overflow and truncated the clock to + On integer overflow, silently ignore the overflow and clamp the clock to _PyTime_MIN or _PyTime_MAX. Use _PyTime_GetMonotonicClockWithInfo() to check for failure. */ @@ -232,7 +238,7 @@ PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm); measure a short duration. If the internal clock fails, silently ignore the error and return 0. - On integer overflow, silently ignore the overflow and truncated the clock to + On integer overflow, silently ignore the overflow and clamp the clock to _PyTime_MIN or _PyTime_MAX. Use _PyTime_GetPerfCounterWithInfo() to check for failure. */ |