summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2017-10-18 08:12:47 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-10-18 08:12:47 (GMT)
commit95602b368b87da3702a0f340ded2a23e823bb104 (patch)
tree48698f6120f2e0ee60d3df01a3fefc9531d3473d /Python
parent178148025494c4058571831fb11fc8eeff8b7365 (diff)
downloadcpython-95602b368b87da3702a0f340ded2a23e823bb104.zip
cpython-95602b368b87da3702a0f340ded2a23e823bb104.tar.gz
cpython-95602b368b87da3702a0f340ded2a23e823bb104.tar.bz2
[3.6] bpo-31786: Make functions in the select module blocking when timeout is a small negative value. (GH-4003). (#4022)
(cherry picked from commit 2c15b29aea5d6b9c61aa42d2c24a07ff1edb4b46)
Diffstat (limited to 'Python')
-rw-r--r--Python/pytime.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/Python/pytime.c b/Python/pytime.c
index b416eff..19fdb55 100644
--- a/Python/pytime.c
+++ b/Python/pytime.c
@@ -84,12 +84,19 @@ _PyTime_Round(double x, _PyTime_round_t round)
volatile double d;
d = x;
- if (round == _PyTime_ROUND_HALF_EVEN)
+ if (round == _PyTime_ROUND_HALF_EVEN){
d = _PyTime_RoundHalfEven(d);
- else if (round == _PyTime_ROUND_CEILING)
+ }
+ 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;
}
@@ -395,16 +402,29 @@ _PyTime_Divide(const _PyTime_t t, const _PyTime_t k,
return x;
}
else if (round == _PyTime_ROUND_CEILING) {
- if (t >= 0)
+ if (t >= 0){
return (t + k - 1) / k;
- else
+ }
+ else{
return t / k;
+ }
}
- else {
- if (t >= 0)
+ else if (round == _PyTime_ROUND_FLOOR){
+ if (t >= 0) {
return t / k;
- else
+ }
+ else{
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;
+ }
}
}