diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-10-24 23:53:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-24 23:53:32 (GMT) |
commit | 850a18e03e8f8309bc8c39adc6e7d51a4568cd9a (patch) | |
tree | 56455b89cb152566734d1fc5de5c70029c3baa70 /Modules | |
parent | 3557b05c5a7dfd7d97ddfd3b79aefd53d25e5132 (diff) | |
download | cpython-850a18e03e8f8309bc8c39adc6e7d51a4568cd9a.zip cpython-850a18e03e8f8309bc8c39adc6e7d51a4568cd9a.tar.gz cpython-850a18e03e8f8309bc8c39adc6e7d51a4568cd9a.tar.bz2 |
bpo-30768: Recompute timeout on interrupted lock (GH-4103)
Fix the pthread+semaphore implementation of
PyThread_acquire_lock_timed() when called with timeout > 0 and
intr_flag=0: recompute the timeout if sem_timedwait() is interrupted
by a signal (EINTR).
See also the PEP 475.
The pthread implementation of PyThread_acquire_lock() now fails with
a fatal error if the timeout is larger than PY_TIMEOUT_MAX, as done
in the Windows implementation.
The check prevents any risk of overflow in PyThread_acquire_lock().
Add also PY_DWORD_MAX constant.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_threadmodule.c | 6 | ||||
-rw-r--r-- | Modules/_winapi.c | 10 | ||||
-rw-r--r-- | Modules/clinic/_winapi.c.h | 6 | ||||
-rw-r--r-- | Modules/posixmodule.c | 4 |
4 files changed, 12 insertions, 14 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 72df78f..99611ee 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -1363,9 +1363,11 @@ PyInit__thread(void) if (m == NULL) return NULL; - timeout_max = PY_TIMEOUT_MAX / 1000000; - time_max = floor(_PyTime_AsSecondsDouble(_PyTime_MAX)); + timeout_max = (double)PY_TIMEOUT_MAX * 1e-6; + time_max = _PyTime_AsSecondsDouble(_PyTime_MAX); timeout_max = Py_MIN(timeout_max, time_max); + /* Round towards minus infinity */ + timeout_max = floor(timeout_max); v = PyFloat_FromDouble(timeout_max); if (!v) diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 00a26d51..7e8d4e3 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -61,8 +61,6 @@ #define T_HANDLE T_POINTER -#define DWORD_MAX 4294967295U - /* Grab CancelIoEx dynamically from kernel32 */ static int has_CancelIoEx = -1; static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED); @@ -184,11 +182,11 @@ class DWORD_return_converter(CReturnConverter): def render(self, function, data): self.declare(data) - self.err_occurred_if("_return_value == DWORD_MAX", data) + self.err_occurred_if("_return_value == PY_DWORD_MAX", data) data.return_conversion.append( 'return_value = Py_BuildValue("k", _return_value);\n') [python start generated code]*/ -/*[python end generated code: output=da39a3ee5e6b4b0d input=94819e72d2c6d558]*/ +/*[python end generated code: output=da39a3ee5e6b4b0d input=4527052fe06e5823]*/ #include "clinic/_winapi.c.h" @@ -1009,7 +1007,7 @@ _winapi_GetExitCodeProcess_impl(PyObject *module, HANDLE process) if (! result) { PyErr_SetFromWindowsErr(GetLastError()); - exit_code = DWORD_MAX; + exit_code = PY_DWORD_MAX; } return exit_code; @@ -1466,7 +1464,7 @@ _winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer, } Py_BEGIN_ALLOW_THREADS - len = (DWORD)Py_MIN(buf->len, DWORD_MAX); + len = (DWORD)Py_MIN(buf->len, PY_DWORD_MAX); ret = WriteFile(handle, buf->buf, len, &written, overlapped ? &overlapped->overlapped : NULL); Py_END_ALLOW_THREADS diff --git a/Modules/clinic/_winapi.c.h b/Modules/clinic/_winapi.c.h index 9e1fbe1..01bba36 100644 --- a/Modules/clinic/_winapi.c.h +++ b/Modules/clinic/_winapi.c.h @@ -460,7 +460,7 @@ _winapi_GetExitCodeProcess(PyObject *module, PyObject *arg) goto exit; } _return_value = _winapi_GetExitCodeProcess_impl(module, process); - if ((_return_value == DWORD_MAX) && PyErr_Occurred()) { + if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) { goto exit; } return_value = Py_BuildValue("k", _return_value); @@ -487,7 +487,7 @@ _winapi_GetLastError(PyObject *module, PyObject *Py_UNUSED(ignored)) DWORD _return_value; _return_value = _winapi_GetLastError_impl(module); - if ((_return_value == DWORD_MAX) && PyErr_Occurred()) { + if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) { goto exit; } return_value = Py_BuildValue("k", _return_value); @@ -889,4 +889,4 @@ _winapi_WriteFile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject exit: return return_value; } -/*[clinic end generated code: output=afa6bd61eb0f18d2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fba2ad7bf1a87e4a input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index c7d8b00..661fa13 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -390,8 +390,6 @@ static int win32_can_symlink = 0; #endif #endif -#define DWORD_MAX 4294967295U - #ifdef MS_WINDOWS #define INITFUNC PyInit_nt #define MODNAME "nt" @@ -3817,7 +3815,7 @@ os__getvolumepathname_impl(PyObject *module, PyObject *path) /* Volume path should be shorter than entire path */ buflen = Py_MAX(buflen, MAX_PATH); - if (buflen > DWORD_MAX) { + if (buflen > PY_DWORD_MAX) { PyErr_SetString(PyExc_OverflowError, "path too long"); return NULL; } |