mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
Issue #10095: fp_setreadl() doesn't reopen the file, reuse instead the file
descriptor.
This commit is contained in:
parent
383c32dd38
commit
22a351aabf
3 changed files with 13 additions and 7 deletions
|
|
@ -462,17 +462,20 @@ static int
|
|||
fp_setreadl(struct tok_state *tok, const char* enc)
|
||||
{
|
||||
PyObject *readline = NULL, *stream = NULL, *io = NULL;
|
||||
int fd;
|
||||
|
||||
io = PyImport_ImportModuleNoBlock("io");
|
||||
if (io == NULL)
|
||||
goto cleanup;
|
||||
|
||||
if (tok->filename)
|
||||
stream = PyObject_CallMethod(io, "open", "ssis",
|
||||
tok->filename, "r", -1, enc);
|
||||
else
|
||||
stream = PyObject_CallMethod(io, "open", "isisOOO",
|
||||
fileno(tok->fp), "r", -1, enc, Py_None, Py_None, Py_False);
|
||||
fd = fileno(tok->fp);
|
||||
if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
|
||||
PyErr_SetFromErrnoWithFilename(PyExc_OSError, NULL);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
stream = PyObject_CallMethod(io, "open", "isisOOO",
|
||||
fd, "r", -1, enc, Py_None, Py_None, Py_False);
|
||||
if (stream == NULL)
|
||||
goto cleanup;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue