From 850a18e03e8f8309bc8c39adc6e7d51a4568cd9a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 24 Oct 2017 16:53:32 -0700 Subject: 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. --- Modules/_winapi.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'Modules/_winapi.c') diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 00a26d515e..7e8d4e3846 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 -- cgit v1.2.1