diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2017-10-17 15:14:41 +0100 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-10-17 17:14:41 +0300 |
commit | 2c15b29aea5d6b9c61aa42d2c24a07ff1edb4b46 (patch) | |
tree | b6b9f24a447144147ddd1959f90016106c077c05 /Python/pytime.c | |
parent | 552be9d7e64f91b8e4ba5b29cd5dcc442d56f92c (diff) | |
download | cpython-git-2c15b29aea5d6b9c61aa42d2c24a07ff1edb4b46.tar.gz |
bpo-31786: Make functions in the select module blocking when timeout is a small negative value. (#4003)
Diffstat (limited to 'Python/pytime.c')
-rw-r--r-- | Python/pytime.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Python/pytime.c b/Python/pytime.c index 7b55b10d10..f19bb3673e 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -120,9 +120,13 @@ _PyTime_Round(double x, _PyTime_round_t round) else if (round == _PyTime_ROUND_CEILING) { d = ceil(d); } - else { + else if (round == _PyTime_ROUND_FLOOR) { d = floor(d); } + else { + assert(round == _PyTime_ROUND_UP); + d = (d >= 0.0) ? ceil(d) : floor(d); + } return d; } @@ -427,7 +431,7 @@ _PyTime_Divide(const _PyTime_t t, const _PyTime_t k, return t / k; } } - else { + else if (round == _PyTime_ROUND_FLOOR){ if (t >= 0) { return t / k; } @@ -435,6 +439,15 @@ _PyTime_Divide(const _PyTime_t t, const _PyTime_t k, return (t - (k - 1)) / k; } } + else { + assert(round == _PyTime_ROUND_UP); + if (t >= 0) { + return (t + k - 1) / k; + } + else { + return (t - (k - 1)) / k; + } + } } _PyTime_t |