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

Skip to content

Commit 711bb3f

Browse files
authored
Merge pull request #11638 from meeseeksmachine/auto-backport-of-pr-11636-on-v2.2.x
Backport PR #11636 on branch v2.2.x
2 parents bd4649c + ac67161 commit 711bb3f

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)