diff Python/errors.c @ 64859:00e4ce31d404

add PyErr_SyntaxLocationEx, to support adding a column offset
author Benjamin Peterson <benjamin@python.org>
date Mon, 20 Sep 2010 22:42:10 +0000
parents 600c23127207
children 38ad57db88ac
line wrap: on
line diff
--- a/Python/errors.c	Mon Sep 20 21:47:37 2010 +0000
+++ b/Python/errors.c	Mon Sep 20 22:42:10 2010 +0000
@@ -780,12 +780,18 @@
 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_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)