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

Skip to content

Commit c273783

Browse files
authored
Merge pull request #11636 from gson1703/fix-11635
MNT: Don't flush file object opened for reading
2 parents 19d5fbc + 61dd35a commit c273783

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
@@ -59,12 +59,15 @@ static NPY_INLINE FILE *mpl_PyFile_Dup(PyObject *file, char *mode, mpl_off_t *or
5959
mpl_off_t pos;
6060
FILE *handle;
6161

62-
/* Flush first to ensure things end up in the file in the correct order */
63-
ret = PyObject_CallMethod(file, (char *)"flush", (char *)"");
64-
if (ret == NULL) {
65-
return NULL;
62+
if (mode[0] != 'r') {
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;
67+
}
68+
Py_DECREF(ret);
6669
}
67-
Py_DECREF(ret);
70+
6871
fd = PyObject_AsFileDescriptor(file);
6972
if (fd == -1) {
7073
return NULL;

0 commit comments

Comments
 (0)