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

Skip to content

Commit ac67161

Browse files
tacaswellMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #11636: Don't flush file object opened for reading
1 parent 05c9a12 commit ac67161

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/file_compat.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ static NPY_INLINE FILE *mpl_PyFile_Dup(PyObject *file, char *mode, mpl_off_t *or
6060
mpl_off_t pos;
6161
FILE *handle;
6262

63-
/* Flush first to ensure things end up in the file in the correct order */
64-
ret = PyObject_CallMethod(file, (char *)"flush", (char *)"");
65-
if (ret == NULL) {
66-
return NULL;
63+
if (mode[0] != 'r') {
64+
/* Flush first to ensure things end up in the file in the correct order */
65+
ret = PyObject_CallMethod(file, (char *)"flush", (char *)"");
66+
if (ret == NULL) {
67+
return NULL;
68+
}
69+
Py_DECREF(ret);
6770
}
68-
Py_DECREF(ret);
71+
6972
fd = PyObject_AsFileDescriptor(file);
7073
if (fd == -1) {
7174
return NULL;

0 commit comments

Comments
 (0)