summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-08-31 11:17:42 +0000
committerMartin v. Löwis <martin@v.loewis.de>2007-08-31 11:17:42 +0000
commitaa4f5cb96931b47ddd00880fc00dac6632273296 (patch)
tree07a68a5408fcd5778e20b411bf2027301a06a487 /Python/pythonrun.c
parent8177435214062959524498a5f1a436ebd9962a35 (diff)
downloadcpython-aa4f5cb96931b47ddd00880fc00dac6632273296.tar.gz
Explicitly convert err->text to Unicode. Fixes #1069.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index a0019c4c4b..eeed820faa 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1459,7 +1459,7 @@ PyParser_SetError(perrdetail *err)
static void
err_input(perrdetail *err)
{
- PyObject *v, *w, *errtype;
+ PyObject *v, *w, *errtype, *errtext;
PyObject* u = NULL;
char *msg = NULL;
errtype = PyExc_SyntaxError;
@@ -1539,8 +1539,17 @@ err_input(perrdetail *err)
msg = "unknown parsing error";
break;
}
- v = Py_BuildValue("(ziiz)", err->filename,
- err->lineno, err->offset, err->text);
+ /* err->text may not be UTF-8 in case of decoding errors.
+ 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) {
PyObject_FREE(err->text);
err->text = NULL;