diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-09-20 22:42:10 +0000 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-09-20 22:42:10 +0000 |
commit | 98907bab94e60d8a2b492aa0669b0bf792c6303e (patch) | |
tree | 43042d14aec982f0bdac7f20f7a95596694792a4 /Python/errors.c | |
parent | 2d70d69596358735a84187039675d5d38b9fef6b (diff) | |
download | cpython-98907bab94e60d8a2b492aa0669b0bf792c6303e.tar.gz |
add PyErr_SyntaxLocationEx, to support adding a column offset
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Python/errors.c b/Python/errors.c index 4ae661a16f..a24095dff9 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -780,12 +780,18 @@ PyErr_WriteUnraisable(PyObject *obj) extern PyObject *PyModule_GetWarningsModule(void); +void +PyErr_SyntaxLocation(const char *filename, int lineno) { + PyErr_SyntaxLocationEx(filename, lineno, -1); +} + + /* 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(const char *filename, int lineno) +PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset) { PyObject *exc, *v, *tb, *tmp; @@ -802,6 +808,16 @@ PyErr_SyntaxLocation(const char *filename, int lineno) PyErr_Clear(); Py_DECREF(tmp); } + if (col_offset >= 0) { + tmp = PyLong_FromLong(col_offset); + if (tmp == NULL) + PyErr_Clear(); + else { + if (PyObject_SetAttrString(v, "offset", tmp)) + PyErr_Clear(); + Py_DECREF(tmp); + } + } if (filename != NULL) { tmp = PyUnicode_FromString(filename); if (tmp == NULL) |