Commit 34d649e3 authored by Victor Stinner's avatar Victor Stinner

Issue #9425: PyFile_FromFd() ignores the name argument

This function is only by imp.find_module() which does return the filename in a
separated variable.
parent 03475a85
...@@ -22,8 +22,9 @@ the :mod:`io` APIs instead. ...@@ -22,8 +22,9 @@ the :mod:`io` APIs instead.
Create a Python file object from the file descriptor of an already Create a Python file object from the file descriptor of an already
opened file *fd*. The arguments *name*, *encoding*, *errors* and *newline* opened file *fd*. The arguments *name*, *encoding*, *errors* and *newline*
can be *NULL* to use the defaults; *buffering* can be *-1* to use the can be *NULL* to use the defaults; *buffering* can be *-1* to use the
default. Return *NULL* on failure. For a more comprehensive description of default. *name* is ignored and kept for backward compatibility. Return
the arguments, please refer to the :func:`io.open` function documentation. *NULL* on failure. For a more comprehensive description of the arguments,
please refer to the :func:`io.open` function documentation.
.. warning:: .. warning::
...@@ -31,6 +32,9 @@ the :mod:`io` APIs instead. ...@@ -31,6 +32,9 @@ the :mod:`io` APIs instead.
OS-level file descriptors can produce various issues (such as unexpected OS-level file descriptors can produce various issues (such as unexpected
ordering of data). ordering of data).
.. versionchanged:: 3.2
Ignore *name* attribute.
.. cfunction:: int PyObject_AsFileDescriptor(PyObject *p) .. cfunction:: int PyObject_AsFileDescriptor(PyObject *p)
......
...@@ -29,7 +29,7 @@ PyObject * ...@@ -29,7 +29,7 @@ PyObject *
PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding, PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding,
char *errors, char *newline, int closefd) char *errors, char *newline, int closefd)
{ {
PyObject *io, *stream, *nameobj = NULL; PyObject *io, *stream;
io = PyImport_ImportModule("io"); io = PyImport_ImportModule("io");
if (io == NULL) if (io == NULL)
...@@ -40,16 +40,8 @@ PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding, ...@@ -40,16 +40,8 @@ PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding,
Py_DECREF(io); Py_DECREF(io);
if (stream == NULL) if (stream == NULL)
return NULL; return NULL;
if (name != NULL) { /* ignore name attribute because the name attribute of _BufferedIOMixin
nameobj = PyUnicode_DecodeFSDefault(name); and TextIOWrapper is read only */
if (nameobj == NULL)
PyErr_Clear();
else {
if (PyObject_SetAttrString(stream, "name", nameobj) < 0)
PyErr_Clear();
Py_DECREF(nameobj);
}
}
return stream; return stream;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment