From 65fd0592fb3845c17b27c441380553fc22f78812 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 21 Jan 2014 22:26:52 +0200 Subject: Issue #2382: SyntaxError cursor "^" now is written at correct position in most cases when multibyte characters are in line (before "^"). This still not works correctly with wide East Asian characters. --- Python/pythonrun.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'Python/pythonrun.c') diff --git a/Python/pythonrun.c b/Python/pythonrun.c index e02dbe2be1..91d56b78ee 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -2226,6 +2226,7 @@ err_input(perrdetail *err) PyObject *v, *w, *errtype, *errtext; PyObject *msg_obj = NULL; char *msg = NULL; + int offset = err->offset; errtype = PyExc_SyntaxError; switch (err->error) { @@ -2310,11 +2311,20 @@ err_input(perrdetail *err) errtext = Py_None; Py_INCREF(Py_None); } else { - errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text), + errtext = PyUnicode_DecodeUTF8(err->text, err->offset, "replace"); + if (errtext != NULL) { + Py_ssize_t len = strlen(err->text); + offset = (int)PyUnicode_GET_LENGTH(errtext); + if (len != err->offset) { + Py_DECREF(errtext); + errtext = PyUnicode_DecodeUTF8(err->text, len, + "replace"); + } + } } v = Py_BuildValue("(OiiN)", err->filename, - err->lineno, err->offset, errtext); + err->lineno, offset, errtext); if (v != NULL) { if (msg_obj) w = Py_BuildValue("(OO)", msg_obj, v); -- cgit v1.2.1