From 2c15b29aea5d6b9c61aa42d2c24a07ff1edb4b46 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Tue, 17 Oct 2017 15:14:41 +0100 Subject: bpo-31786: Make functions in the select module blocking when timeout is a small negative value. (#4003) --- Python/pytime.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'Python/pytime.c') 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 -- cgit v1.2.1