summaryrefslogtreecommitdiffstats
path: root/Objects/fileobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-09-30 13:01:34 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-09-30 13:01:34 (GMT)
commit89719e1daf8b15810145baf56d984ecbc1bab7ef (patch)
tree9823a357a068dbb42c063460947f175bd4a1fe67 /Objects/fileobject.c
parenta59018c7ab905584ed94d35b2cf93067e116f8f2 (diff)
downloadcpython-89719e1daf8b15810145baf56d984ecbc1bab7ef.zip
cpython-89719e1daf8b15810145baf56d984ecbc1bab7ef.tar.gz
cpython-89719e1daf8b15810145baf56d984ecbc1bab7ef.tar.bz2
Issue #25182: Fix compilation on Windows
Restore also errno value before calling PyErr_SetFromErrno().
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r--Objects/fileobject.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 403d718..1a93a6d 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -376,7 +376,7 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
PyObject *bytes = NULL;
char *str;
Py_ssize_t n;
- int _errno;
+ int err;
if (self->fd < 0) {
/* fd might be invalid on Windows
@@ -411,13 +411,16 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
#else
n = write(self->fd, str, n);
#endif
- _errno = errno;
+ /* save errno, it can be modified indirectly by Py_XDECREF() */
+ err = errno;
Py_END_ALLOW_THREADS
+
Py_XDECREF(bytes);
if (n < 0) {
- if (_errno == EAGAIN)
+ if (err == EAGAIN)
Py_RETURN_NONE;
+ errno = err;
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}