mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Explicitly convert err->text to Unicode. Fixes #1069.
This commit is contained in:
parent
90d1fcd101
commit
5deb2101df
1 changed files with 12 additions and 3 deletions
|
@ -1459,7 +1459,7 @@ PyParser_SetError(perrdetail *err)
|
||||||
static void
|
static void
|
||||||
err_input(perrdetail *err)
|
err_input(perrdetail *err)
|
||||||
{
|
{
|
||||||
PyObject *v, *w, *errtype;
|
PyObject *v, *w, *errtype, *errtext;
|
||||||
PyObject* u = NULL;
|
PyObject* u = NULL;
|
||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
errtype = PyExc_SyntaxError;
|
errtype = PyExc_SyntaxError;
|
||||||
|
@ -1539,8 +1539,17 @@ err_input(perrdetail *err)
|
||||||
msg = "unknown parsing error";
|
msg = "unknown parsing error";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
v = Py_BuildValue("(ziiz)", err->filename,
|
/* err->text may not be UTF-8 in case of decoding errors.
|
||||||
err->lineno, err->offset, err->text);
|
Explicitly convert to an object. */
|
||||||
|
if (!err->text) {
|
||||||
|
errtext = Py_None;
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
} else {
|
||||||
|
errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text),
|
||||||
|
"replace");
|
||||||
|
}
|
||||||
|
v = Py_BuildValue("(ziiN)", err->filename,
|
||||||
|
err->lineno, err->offset, errtext);
|
||||||
if (err->text != NULL) {
|
if (err->text != NULL) {
|
||||||
PyObject_FREE(err->text);
|
PyObject_FREE(err->text);
|
||||||
err->text = NULL;
|
err->text = NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue