]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #25182: Fix compilation on Windows
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 30 Sep 2015 13:01:34 +0000 (15:01 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 30 Sep 2015 13:01:34 +0000 (15:01 +0200)
Restore also errno value before calling PyErr_SetFromErrno().

Objects/fileobject.c

index 403d718dfe5489894c5dad08e3091c113265c195..1a93a6dd6b2f3d7de01b7a7229df7dd4e05f4956 100644 (file)
@@ -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;
     }