summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-09-20 22:42:10 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-09-20 22:42:10 (GMT)
commit2c53971b37cd69f45d52c498c953734f961deb77 (patch)
tree6fa5bb08f26cad8da01998fb92ae0d5650924438
parent26d64aeee4face9f6929f4207647b0052ad27c36 (diff)
downloadcpython-2c53971b37cd69f45d52c498c953734f961deb77.zip
cpython-2c53971b37cd69f45d52c498c953734f961deb77.tar.gz
cpython-2c53971b37cd69f45d52c498c953734f961deb77.tar.bz2
add PyErr_SyntaxLocationEx, to support adding a column offset
-rw-r--r--Doc/c-api/exceptions.rst14
-rw-r--r--Include/pyerrors.h1
-rw-r--r--Python/errors.c18
3 files changed, 32 insertions, 1 deletions
diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst
index f969b96..899666f 100644
--- a/Doc/c-api/exceptions.rst
+++ b/Doc/c-api/exceptions.rst
@@ -294,6 +294,20 @@ in various ways. There is a separate error indicator for each thread.
parameter specifying the exception type to be raised. Availability: Windows.
+.. cfunction:: void PyErr_SyntaxLocationEx(char *filename, int lineno, int col_offset)
+
+ Set file, line, and offset information for the current exception. If the
+ current exception is not a :exc:`SyntaxError`, then it sets additional
+ attributes, which make the exception printing subsystem think the exception
+ is a :exc:`SyntaxError`.
+
+
+.. cfunction:: void PyErr_SyntaxLocation(char *filename, int lineno)
+
+ Like :cfunc:`PyErr_SyntaxLocationExc`, but the col_offset parameter is
+ omitted.
+
+
.. cfunction:: void PyErr_BadInternalCall()
This is a shorthand for ``PyErr_SetString(PyExc_SystemError, message)``,
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index 243bc01..fb9ce91 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -229,6 +229,7 @@ int PySignal_SetWakeupFd(int fd);
/* Support for adding program text to SyntaxErrors */
PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
+PyAPI_FUNC(void) PyErr_SyntaxLocationEx(const char *, int, int);
PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);
/* The following functions are used to create and modify unicode
diff --git a/Python/errors.c b/Python/errors.c
index 4ae661a..a24095d 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)