diff options
| author | Benjamin Peterson <benjamin@python.org> | 2016-09-13 05:07:27 (GMT) |
|---|---|---|
| committer | Benjamin Peterson <benjamin@python.org> | 2016-09-13 05:07:27 (GMT) |
| commit | 98deab5e4ec3d02f01ee9066ca308de187c1638e (patch) | |
| tree | 052dec256a954b1c792c0a0c183a107d6f845716 /Parser/tokenizer.c | |
| parent | e4c16fa364e122e5e3810b43d490208c8ff07a8e (diff) | |
| parent | 5a715cfc57e242b93c5c5e8ad2443ee276b3e6fc (diff) | |
| download | cpython-98deab5e4ec3d02f01ee9066ca308de187c1638e.zip cpython-98deab5e4ec3d02f01ee9066ca308de187c1638e.tar.gz cpython-98deab5e4ec3d02f01ee9066ca308de187c1638e.tar.bz2 | |
merge 3.6 (#27981)
Diffstat (limited to 'Parser/tokenizer.c')
| -rw-r--r-- | Parser/tokenizer.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index a29ba47..8961884 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -497,16 +497,12 @@ error: static int fp_setreadl(struct tok_state *tok, const char* enc) { - PyObject *readline = NULL, *stream = NULL, *io = NULL; + PyObject *readline, *io, *stream; _Py_IDENTIFIER(open); _Py_IDENTIFIER(readline); int fd; long pos; - io = PyImport_ImportModuleNoBlock("io"); - if (io == NULL) - goto cleanup; - fd = fileno(tok->fp); /* Due to buffering the file offset for fd can be different from the file * position of tok->fp. If tok->fp was opened in text mode on Windows, @@ -517,27 +513,33 @@ fp_setreadl(struct tok_state *tok, const char* enc) if (pos == -1 || lseek(fd, (off_t)(pos > 0 ? pos - 1 : pos), SEEK_SET) == (off_t)-1) { PyErr_SetFromErrnoWithFilename(PyExc_OSError, NULL); - goto cleanup; + return 0; } + io = PyImport_ImportModuleNoBlock("io"); + if (io == NULL) + return 0; + stream = _PyObject_CallMethodId(io, &PyId_open, "isisOOO", fd, "r", -1, enc, Py_None, Py_None, Py_False); + Py_DECREF(io); if (stream == NULL) - goto cleanup; + return 0; readline = _PyObject_GetAttrId(stream, &PyId_readline); + Py_DECREF(stream); + if (readline == NULL) + return 0; Py_XSETREF(tok->decoding_readline, readline); + if (pos > 0) { - if (PyObject_CallObject(readline, NULL) == NULL) { - readline = NULL; - goto cleanup; - } + PyObject *bufobj = PyObject_CallObject(readline, NULL); + if (bufobj == NULL) + return 0; + Py_DECREF(bufobj); } - cleanup: - Py_XDECREF(stream); - Py_XDECREF(io); - return readline != NULL; + return 1; } /* Fetch the next byte from TOK. */ |
