diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2002-03-03 21:30:27 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2002-03-03 21:30:27 +0000 |
commit | a33c1e69bcc2312323114e06b2fcd5d4ba900f8d (patch) | |
tree | ead518f9ffd9a0d6058358eee42399b870d98ab7 /Python/errors.c | |
parent | 5393a9d4fbfeacc988f09e03411c052bc0768253 (diff) | |
download | cpython-a33c1e69bcc2312323114e06b2fcd5d4ba900f8d.tar.gz |
Patch #50002: Display line information for bad \x escapes:
- recognize "SyntaxError"s by the print_file_and_line attribute.
- add the syntaxerror attributes to all exceptions in compile.c.
Fixes #221791
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Python/errors.c b/Python/errors.c index 2799cffc93..13b3d11ed6 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -561,7 +561,9 @@ PyErr_WarnExplicit(PyObject *category, char *message, } -/* XXX There's a comment missing here */ +/* Set file and line information for the current exception. + If the exception is not a SyntaxError, also sets additional attributes + to make printing of exceptions believe it is a syntax error. */ void PyErr_SyntaxLocation(char *filename, int lineno) @@ -596,6 +598,26 @@ PyErr_SyntaxLocation(char *filename, int lineno) Py_DECREF(tmp); } } + if (PyObject_SetAttrString(v, "offset", Py_None)) { + PyErr_Clear(); + } + if (exc != PyExc_SyntaxError) { + if (!PyObject_HasAttrString(v, "msg")) { + tmp = PyObject_Str(v); + if (tmp) { + if (PyObject_SetAttrString(v, "msg", tmp)) + PyErr_Clear(); + Py_DECREF(tmp); + } else { + PyErr_Clear(); + } + } + if (!PyObject_HasAttrString(v, "print_file_and_line")) { + if (PyObject_SetAttrString(v, "print_file_and_line", + Py_None)) + PyErr_Clear(); + } + } PyErr_Restore(exc, v, tb); } |