Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 89719e1

Browse files
committed
Issue #25182: Fix compilation on Windows
Restore also errno value before calling PyErr_SetFromErrno().
1 parent a59018c commit 89719e1

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Objects/fileobject.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
376376
PyObject *bytes = NULL;
377377
char *str;
378378
Py_ssize_t n;
379-
int _errno;
379+
int err;
380380

381381
if (self->fd < 0) {
382382
/* fd might be invalid on Windows
@@ -411,13 +411,16 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
411411
#else
412412
n = write(self->fd, str, n);
413413
#endif
414-
_errno = errno;
414+
/* save errno, it can be modified indirectly by Py_XDECREF() */
415+
err = errno;
415416
Py_END_ALLOW_THREADS
417+
416418
Py_XDECREF(bytes);
417419

418420
if (n < 0) {
419-
if (_errno == EAGAIN)
421+
if (err == EAGAIN)
420422
Py_RETURN_NONE;
423+
errno = err;
421424
PyErr_SetFromErrno(PyExc_IOError);
422425
return NULL;
423426
}

0 commit comments

Comments
 (0)