aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-10-09 23:37:48 +0000
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-10-09 23:37:48 +0000
commitcf8016a8d6b3fed550ed961ffd957ab3d19f04da (patch)
treed0b5d0faf11161269fe26e154837ec0ae19a3c28 /Parser/tokenizer.c
parentSome more notes about bytes/string filename APIs. (diff)
downloadcpython-cf8016a8d6b3fed550ed961ffd957ab3d19f04da.tar.gz
cpython-cf8016a8d6b3fed550ed961ffd957ab3d19f04da.tar.bz2
cpython-cf8016a8d6b3fed550ed961ffd957ab3d19f04da.zip
Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
contains a ``coding:`` header: the wrong line was displayed, and the encoding was not respected. Patch by Victor Stinner.
Diffstat (limited to 'Parser/tokenizer.c')
-rw-r--r--Parser/tokenizer.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 18815aef452..4edf6d07e44 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -461,6 +461,14 @@ fp_setreadl(struct tok_state *tok, const char* enc)
readline = PyObject_GetAttrString(stream, "readline");
tok->decoding_readline = readline;
+ /* The file has been reopened; parsing will restart from
+ * the beginning of the file, we have to reset the line number.
+ * But this function has been called from inside tok_nextc() which
+ * will increment lineno before it returns. So we set it -1 so that
+ * the next call to tok_nextc() will start with tok->lineno == 0.
+ */
+ tok->lineno = -1;
+
cleanup:
Py_XDECREF(stream);
Py_XDECREF(io);