]> granicus.if.org Git - python/commitdiff
Forward UnicodeDecodeError into SyntaxError for source encoding errors.
authorMartin v. Löwis <martin@v.loewis.de>
Wed, 24 Aug 2005 08:39:24 +0000 (08:39 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Wed, 24 Aug 2005 08:39:24 +0000 (08:39 +0000)
Will backport to 2.4.

Misc/NEWS
Python/pythonrun.c

index a65db9d8098b9a72a4072f18ba2e0264fc4b9713..f5a2526e51b2c312d35ef028074b76c0cb1ba1f7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.5 alpha 1?
 Core and builtins
 -----------------
 
+- Forward UnicodeDecodeError into SyntaxError for source encoding errors.
+
 - SF bug #900092: When tracing (e.g. for hotshot), restore 'return' events for
   exceptions that cause a function to exit.
 
index 9e53564ad868915638b3cd21a40dfe7169db3f5a..68948fc34cd945fceed357e777664a33f0b5cdcf 100644 (file)
@@ -1474,18 +1474,20 @@ err_input(perrdetail *err)
                errtype = PyExc_IndentationError;
                msg = "too many levels of indentation";
                break;
-       case E_DECODE: {        /* XXX */
-               PyThreadState* tstate = PyThreadState_GET();
-               PyObject* value = tstate->curexc_value;
+       case E_DECODE: {
+               PyObject *type, *value, *tb;
+               PyErr_Fetch(&type, &value, &tb);
                if (value != NULL) {
-                       u = PyObject_Repr(value);
+                       u = PyObject_Str(value);
                        if (u != NULL) {
                                msg = PyString_AsString(u);
-                               break;
                        }
                }
                if (msg == NULL)
                        msg = "unknown decode error";
+               Py_DECREF(type);
+               Py_DECREF(value);
+               Py_DECREF(tb);
                break;
        }
        case E_LINECONT: