]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-31806: Use _PyTime_ROUND_TIMEOUT for the timeout argument parsing in more functio...
authorPablo Galindo <Pablogsal@gmail.com>
Wed, 18 Oct 2017 07:13:09 +0000 (08:13 +0100)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 18 Oct 2017 07:13:09 +0000 (10:13 +0300)
Fix timeout rounding in time.sleep(), threading.Lock.acquire() and
socket.socket.settimeout() to round correctly negative timeouts between -1.0 and
0.0. The functions now block waiting for events as expected. Previously, the
call was incorrectly non-blocking.

Misc/NEWS.d/next/Library/2017-10-17-23-27-03.bpo-31806.TzphdL.rst [new file with mode: 0644]
Modules/_threadmodule.c
Modules/socketmodule.c
Modules/timemodule.c

diff --git a/Misc/NEWS.d/next/Library/2017-10-17-23-27-03.bpo-31806.TzphdL.rst b/Misc/NEWS.d/next/Library/2017-10-17-23-27-03.bpo-31806.TzphdL.rst
new file mode 100644 (file)
index 0000000..941e77d
--- /dev/null
@@ -0,0 +1,4 @@
+Fix timeout rounding in time.sleep(), threading.Lock.acquire() and
+socket.socket.settimeout() to round correctly negative timeouts between -1.0 and
+0.0. The functions now block waiting for events as expected. Previously, the
+call was incorrectly non-blocking. Patch by Pablo Galindo.
index 2657a1fc68d1f9395793aacaebc05af8bfc43a35..72df78f9ccc577235bd6925d5157e2269936e0f4 100644 (file)
@@ -104,7 +104,7 @@ lock_acquire_parse_args(PyObject *args, PyObject *kwds,
 
     if (timeout_obj
         && _PyTime_FromSecondsObject(timeout,
-                                     timeout_obj, _PyTime_ROUND_CEILING) < 0)
+                                     timeout_obj, _PyTime_ROUND_TIMEOUT) < 0)
         return -1;
 
     if (!blocking && *timeout != unset_timeout ) {
@@ -122,7 +122,7 @@ lock_acquire_parse_args(PyObject *args, PyObject *kwds,
     else if (*timeout != unset_timeout) {
         _PyTime_t microseconds;
 
-        microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_CEILING);
+        microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_TIMEOUT);
         if (microseconds >= PY_TIMEOUT_MAX) {
             PyErr_SetString(PyExc_OverflowError,
                             "timeout value is too large");
index 5df9d014c35a729d6f7f7e1548077fa31fd37635..0758f9bd4099c19fa44b46482e9000848277ce9f 100644 (file)
@@ -2539,7 +2539,7 @@ socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj)
     }
 
     if (_PyTime_FromSecondsObject(timeout,
-                                  timeout_obj, _PyTime_ROUND_CEILING) < 0)
+                                  timeout_obj, _PyTime_ROUND_TIMEOUT) < 0)
         return -1;
 
     if (*timeout < 0) {
@@ -2548,10 +2548,10 @@ socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj)
     }
 
 #ifdef MS_WINDOWS
-    overflow |= (_PyTime_AsTimeval(*timeout, &tv, _PyTime_ROUND_CEILING) < 0);
+    overflow |= (_PyTime_AsTimeval(*timeout, &tv, _PyTime_ROUND_TIMEOUT) < 0);
 #endif
 #ifndef HAVE_POLL
-    ms = _PyTime_AsMilliseconds(*timeout, _PyTime_ROUND_CEILING);
+    ms = _PyTime_AsMilliseconds(*timeout, _PyTime_ROUND_TIMEOUT);
     overflow |= (ms > INT_MAX);
 #endif
     if (overflow) {
index 463f5c55770f239dd8bacf948476b9bee93c1e1c..b5e168f9ec3c45e2d9e13efff2461f1b27751f87 100644 (file)
@@ -245,7 +245,7 @@ static PyObject *
 time_sleep(PyObject *self, PyObject *obj)
 {
     _PyTime_t secs;
-    if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_CEILING))
+    if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_TIMEOUT))
         return NULL;
     if (secs < 0) {
         PyErr_SetString(PyExc_ValueError,