Commit 22a351aa authored by Victor Stinner's avatar Victor Stinner

Issue #10095: fp_setreadl() doesn't reopen the file, reuse instead the file

descriptor.
parent 383c32dd
...@@ -10,6 +10,9 @@ What's New in Python 3.2 Beta 1? ...@@ -10,6 +10,9 @@ What's New in Python 3.2 Beta 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #10095: fp_setreadl() doesn't reopen the file, reuse instead the file
descriptor.
- Issue #9418: Moved private string methods ``_formatter_parser`` and - Issue #9418: Moved private string methods ``_formatter_parser`` and
``_formatter_field_name_split`` into a new ``_string`` module. ``_formatter_field_name_split`` into a new ``_string`` module.
......
...@@ -462,17 +462,20 @@ static int ...@@ -462,17 +462,20 @@ static int
fp_setreadl(struct tok_state *tok, const char* enc) fp_setreadl(struct tok_state *tok, const char* enc)
{ {
PyObject *readline = NULL, *stream = NULL, *io = NULL; PyObject *readline = NULL, *stream = NULL, *io = NULL;
int fd;
io = PyImport_ImportModuleNoBlock("io"); io = PyImport_ImportModuleNoBlock("io");
if (io == NULL) if (io == NULL)
goto cleanup; goto cleanup;
if (tok->filename) fd = fileno(tok->fp);
stream = PyObject_CallMethod(io, "open", "ssis", if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
tok->filename, "r", -1, enc); PyErr_SetFromErrnoWithFilename(PyExc_OSError, NULL);
else goto cleanup;
stream = PyObject_CallMethod(io, "open", "isisOOO", }
fileno(tok->fp), "r", -1, enc, Py_None, Py_None, Py_False);
stream = PyObject_CallMethod(io, "open", "isisOOO",
fd, "r", -1, enc, Py_None, Py_None, Py_False);
if (stream == NULL) if (stream == NULL)
goto cleanup; goto cleanup;
......
...@@ -53,7 +53,7 @@ struct tok_state { ...@@ -53,7 +53,7 @@ struct tok_state {
int cont_line; /* whether we are in a continuation line. */ int cont_line; /* whether we are in a continuation line. */
const char* line_start; /* pointer to start of current line */ const char* line_start; /* pointer to start of current line */
#ifndef PGEN #ifndef PGEN
PyObject *decoding_readline; /* codecs.open(...).readline */ PyObject *decoding_readline; /* open(...).readline */
PyObject *decoding_buffer; PyObject *decoding_buffer;
#endif #endif
const char* enc; /* Encoding for the current str. */ const char* enc; /* Encoding for the current str. */
......
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