diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-30 02:51:13 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-30 02:51:13 +0200 |
commit | ea9c0dd2c27884691f0a0af983fd41d4d818e93f (patch) | |
tree | a8da8821f8fa7c484073538e41b8eb72de384b81 /Python/pytime.c | |
parent | 160e819a1d0a01fe79b66bf398c925c0dac0ded1 (diff) | |
download | cpython-git-ea9c0dd2c27884691f0a0af983fd41d4d818e93f.tar.gz |
Issue #22117: Fix usage of _PyTime_AsTimeval()
Add _PyTime_AsTimeval_noraise() function. Call it when it's not possible (or
not useful) to raise a Python exception on overflow.
Diffstat (limited to 'Python/pytime.c')
-rw-r--r-- | Python/pytime.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Python/pytime.c b/Python/pytime.c index 2bf6ba5cf2..a7eda869a0 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -311,8 +311,9 @@ _PyTime_AsMicroseconds(_PyTime_t t, _PyTime_round_t round) return _PyTime_Multiply(t, 1000 * 1000, round); } -int -_PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round) +static int +_PyTime_AsTimeval_impl(_PyTime_t t, struct timeval *tv, _PyTime_round_t round, + int raise) { _PyTime_t secs, ns; int res = 0; @@ -357,9 +358,23 @@ _PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round) tv->tv_sec += 1; } + if (res && raise) + _PyTime_overflow(); return res; } +int +_PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round) +{ + return _PyTime_AsTimeval_impl(t, tv, round, 1); +} + +int +_PyTime_AsTimeval_noraise(_PyTime_t t, struct timeval *tv, _PyTime_round_t round) +{ + return _PyTime_AsTimeval_impl(t, tv, round, 0); +} + #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_KQUEUE) int _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts) |