diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-21 22:26:52 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-21 22:26:52 +0200 |
commit | 9b3aa4bf2f5db16c635e0a2b07bb319d27293921 (patch) | |
tree | 800b6c5368f9aefe3bfdd54342fa0fc630c407ef /Python/pythonrun.c | |
parent | 77772c41204d33ca7ccb96908d2275a1d2711aa6 (diff) | |
download | cpython-9b3aa4bf2f5db16c635e0a2b07bb319d27293921.tar.gz |
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.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 14 |
1 files changed, 12 insertions, 2 deletions
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); |