diff options
| author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-14 12:04:34 +0000 |
|---|---|---|
| committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-14 12:04:34 +0000 |
| commit | 7c73635b5819332a4b0eefb160ae9d1045614dbf (patch) | |
| tree | bc9065fd42b888eaad0ab077204ef600f8928631 /Parser | |
| parent | 00284afa20ae99adf6268e493d45bd3e5bdc1382 (diff) | |
| download | cpython-7c73635b5819332a4b0eefb160ae9d1045614dbf.tar.gz | |
Issue #10095: fp_setreadl() doesn't reopen the file, reuse instead the file
descriptor.
Diffstat (limited to 'Parser')
| -rw-r--r-- | Parser/tokenizer.c | 15 | ||||
| -rw-r--r-- | Parser/tokenizer.h | 2 |
2 files changed, 10 insertions, 7 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 90b1b689b5..28dcea1085 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -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; diff --git a/Parser/tokenizer.h b/Parser/tokenizer.h index c8e19c19ba..d9866f6c18 100644 --- a/Parser/tokenizer.h +++ b/Parser/tokenizer.h @@ -53,7 +53,7 @@ struct tok_state { int cont_line; /* whether we are in a continuation line. */ const char* line_start; /* pointer to start of current line */ #ifndef PGEN - PyObject *decoding_readline; /* codecs.open(...).readline */ + PyObject *decoding_readline; /* open(...).readline */ PyObject *decoding_buffer; #endif const char* enc; /* Encoding for the current str. */ |
