Author: martin.v.loewis
Date: Fri Aug 31 13:17:42 2007
New Revision: 57838

Modified:
   python/branches/py3k/Python/pythonrun.c
Log:
Explicitly convert err->text to Unicode. Fixes #1069.


Modified: python/branches/py3k/Python/pythonrun.c
==============================================================================
--- python/branches/py3k/Python/pythonrun.c     (original)
+++ python/branches/py3k/Python/pythonrun.c     Fri Aug 31 13:17:42 2007
@@ -1459,7 +1459,7 @@
 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 @@
                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;
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to