Commit 89719e1d authored by Victor Stinner's avatar Victor Stinner

Issue #25182: Fix compilation on Windows

Restore also errno value before calling PyErr_SetFromErrno().
parent a59018c7
...@@ -376,7 +376,7 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args) ...@@ -376,7 +376,7 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
PyObject *bytes = NULL; PyObject *bytes = NULL;
char *str; char *str;
Py_ssize_t n; Py_ssize_t n;
int _errno; int err;
if (self->fd < 0) { if (self->fd < 0) {
/* fd might be invalid on Windows /* fd might be invalid on Windows
...@@ -411,13 +411,16 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args) ...@@ -411,13 +411,16 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
#else #else
n = write(self->fd, str, n); n = write(self->fd, str, n);
#endif #endif
_errno = errno; /* save errno, it can be modified indirectly by Py_XDECREF() */
err = errno;
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
Py_XDECREF(bytes); Py_XDECREF(bytes);
if (n < 0) { if (n < 0) {
if (_errno == EAGAIN) if (err == EAGAIN)
Py_RETURN_NONE; Py_RETURN_NONE;
errno = err;
PyErr_SetFromErrno(PyExc_IOError); PyErr_SetFromErrno(PyExc_IOError);
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment