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)``,
/* 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
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;
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)