Index: Parser/myreadline.c =================================================================== --- Parser/myreadline.c (revision 86190) +++ Parser/myreadline.c (working copy) @@ -36,12 +36,14 @@ my_fgets(char *buf, int len, FILE *fp) { char *p; + int err; if (PyOS_InputHook != NULL) (void)(PyOS_InputHook)(); errno = 0; p = fgets(buf, len, fp); if (p != NULL) return 0; /* No error */ + err = errno; #ifdef MS_WINDOWS /* In the case of a Ctrl+C or some other external event interrupting the operation: @@ -75,7 +77,7 @@ return -1; /* EOF */ } #ifdef EINTR - if (errno == EINTR) { + if (err == EINTR) { int s; #ifdef WITH_THREAD PyEval_RestoreThread(_PyOS_ReadlineTState); Index: Modules/_io/fileio.c =================================================================== --- Modules/_io/fileio.c (revision 86190) +++ Modules/_io/fileio.c (working copy) @@ -507,6 +507,7 @@ { Py_buffer pbuf; Py_ssize_t n; + int err; if (self->fd < 0) return err_closed(); @@ -523,9 +524,10 @@ Py_END_ALLOW_THREADS } else n = -1; + err = errno; PyBuffer_Release(&pbuf); if (n < 0) { - if (errno == EAGAIN) + if (err == EAGAIN) Py_RETURN_NONE; PyErr_SetFromErrno(PyExc_IOError); return NULL; @@ -664,8 +666,9 @@ n = -1; if (n < 0) { + int err = errno; Py_DECREF(bytes); - if (errno == EAGAIN) + if (err == EAGAIN) Py_RETURN_NONE; PyErr_SetFromErrno(PyExc_IOError); return NULL; @@ -686,6 +689,7 @@ { Py_buffer pbuf; Py_ssize_t n; + int err; if (self->fd < 0) return err_closed(); @@ -702,11 +706,12 @@ Py_END_ALLOW_THREADS } else n = -1; + err = errno; PyBuffer_Release(&pbuf); if (n < 0) { - if (errno == EAGAIN) + if (err == EAGAIN) Py_RETURN_NONE; PyErr_SetFromErrno(PyExc_IOError); return NULL; Index: Modules/_multiprocessing/semaphore.c =================================================================== --- Modules/_multiprocessing/semaphore.c (revision 86190) +++ Modules/_multiprocessing/semaphore.c (working copy) @@ -267,7 +267,7 @@ static PyObject * semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds) { - int blocking = 1, res; + int blocking = 1, res, err; double timeout; PyObject *timeout_obj = Py_None; struct timespec deadline = {0}; @@ -313,14 +313,17 @@ else res = sem_timedwait(self->handle, &deadline); Py_END_ALLOW_THREADS + if (res >= 0) + break; + err = errno; if (res == MP_EXCEPTION_HAS_BEEN_SET) break; - } while (res < 0 && errno == EINTR && !PyErr_CheckSignals()); + } while (err == EINTR && !PyErr_CheckSignals()); if (res < 0) { - if (errno == EAGAIN || errno == ETIMEDOUT) + if (err == EAGAIN || err == ETIMEDOUT) Py_RETURN_FALSE; - else if (errno == EINTR) + else if (err == EINTR) return NULL; else return PyErr_SetFromErrno(PyExc_OSError); #@@ -304,7 +304,7 @@ # deadline.tv_nsec %= 1000000000; # } # #- do { #+ for (;;) { # Py_BEGIN_ALLOW_THREADS # if (blocking && timeout_obj == Py_None) # res = sem_wait(self->handle); #@@ -313,17 +313,20 @@ # else # res = sem_timedwait(self->handle, &deadline); # Py_END_ALLOW_THREADS #- if (res == MP_EXCEPTION_HAS_BEEN_SET) #+ if (res >= 0) # break; #- } while (res < 0 && errno == EINTR && !PyErr_CheckSignals()); # #- if (res < 0) { #- if (errno == EAGAIN || errno == ETIMEDOUT) #+ switch (errno) { #+ case EINTR: #+ if (res == MP_EXCEPTION_HAS_BEEN_SET || PyErr_CheckSignals()) #+ return NULL; #+ break; #+ case EAGAIN: #+ case ETIMEDOUT: # Py_RETURN_FALSE; #- else if (errno == EINTR) #- return NULL; #- else #+ default: # return PyErr_SetFromErrno(PyExc_OSError); #+ } # } # # ++self->count; Index: Modules/readline.c =================================================================== --- Modules/readline.c (revision 86190) +++ Modules/readline.c (working copy) @@ -154,6 +154,7 @@ { PyObject *filename_obj = Py_None, *filename_bytes; char *filename; + int err; if (!PyArg_ParseTuple(args, "|O:write_history_file", &filename_obj)) return NULL; if (filename_obj != Py_None) { @@ -164,11 +165,12 @@ filename_bytes = NULL; filename = NULL; } - errno = write_history(filename); - if (!errno && _history_length >= 0) + errno = err = write_history(filename); + if (!err && _history_length >= 0) history_truncate_file(filename, _history_length); + err = errno; Py_XDECREF(filename_bytes); - if (errno) + if (err) return PyErr_SetFromErrno(PyExc_IOError); Py_RETURN_NONE; } @@ -957,7 +959,7 @@ completed_input_string = not_done_reading; while (completed_input_string == not_done_reading) { - int has_input = 0; + int has_input = 0, err = 0; while (!has_input) { struct timeval timeout = {0, 100000}; /* 0.1 seconds */ @@ -971,13 +973,14 @@ /* select resets selectset if no input was available */ has_input = select(fileno(rl_instream) + 1, &selectset, NULL, NULL, timeoutp); + err = errno; if(PyOS_InputHook) PyOS_InputHook(); } if(has_input > 0) { rl_callback_read_char(); } - else if (errno == EINTR) { + else if (err == EINTR) { int s; #ifdef WITH_THREAD PyEval_RestoreThread(_PyOS_ReadlineTState); Index: Modules/timemodule.c =================================================================== --- Modules/timemodule.c (revision 86190) +++ Modules/timemodule.c (working copy) @@ -558,14 +558,15 @@ PyMem_Free(outbuf); break; } - PyMem_Free(outbuf); #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__) /* VisualStudio .NET 2005 does this properly */ if (buflen == 0 && errno == EINVAL) { + PyMem_Free(outbuf); PyErr_SetString(PyExc_ValueError, "Invalid format string"); break; } #endif + PyMem_Free(outbuf); } #ifdef HAVE_WCSFTIME PyMem_Free(format); Index: Modules/main.c =================================================================== --- Modules/main.c (revision 86190) +++ Modules/main.c (working copy) @@ -646,13 +646,14 @@ if (fp == NULL) { char *cfilename_buffer; const char *cfilename; + int err = errno; cfilename_buffer = _Py_wchar2char(filename); if (cfilename_buffer != NULL) cfilename = cfilename_buffer; else cfilename = ""; fprintf(stderr, "%ls: can't open file '%s': [Errno %d] %s\n", - argv[0], cfilename, errno, strerror(errno)); + argv[0], cfilename, err, strerror(err)); if (cfilename_buffer) PyMem_Free(cfilename_buffer); return 2;