Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Author: Daniel Stutzbach */

#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
Expand Down Expand Up @@ -300,14 +301,17 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
return -1;
}
}
fd = PyLong_AsInt(nameobj);
if (fd < 0) {
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError,
"negative file descriptor");
return -1;
if (_PyIndex_Check(nameobj)) {
fd = PyLong_AsInt(nameobj);
if (fd < 0) {
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError,
"negative file descriptor");
return -1;
}
/* Failed to convert; try other paths. */
PyErr_Clear();
}
PyErr_Clear();
}

if (fd < 0) {
Expand Down
Loading