File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -294,6 +294,20 @@ in various ways. There is a separate error indicator for each thread.
294294 parameter specifying the exception type to be raised. Availability: Windows.
295295
296296
297+ .. cfunction :: void PyErr_SyntaxLocationEx(char *filename, int lineno, int col_offset)
298+
299+ Set file, line, and offset information for the current exception. If the
300+ current exception is not a :exc: `SyntaxError `, then it sets additional
301+ attributes, which make the exception printing subsystem think the exception
302+ is a :exc: `SyntaxError `.
303+
304+
305+ .. cfunction :: void PyErr_SyntaxLocation(char *filename, int lineno)
306+
307+ Like :cfunc: `PyErr_SyntaxLocationExc `, but the col_offset parameter is
308+ omitted.
309+
310+
297311.. cfunction :: void PyErr_BadInternalCall()
298312
299313 This is a shorthand for ``PyErr_SetString(PyExc_SystemError, message) ``,
Original file line number Diff line number Diff line change @@ -229,6 +229,7 @@ int PySignal_SetWakeupFd(int fd);
229229
230230/* Support for adding program text to SyntaxErrors */
231231PyAPI_FUNC (void ) PyErr_SyntaxLocation (const char * , int );
232+ PyAPI_FUNC (void ) PyErr_SyntaxLocationEx (const char * , int , int );
232233PyAPI_FUNC (PyObject * ) PyErr_ProgramText (const char * , int );
233234
234235/* The following functions are used to create and modify unicode
Original file line number Diff line number Diff line change @@ -780,12 +780,18 @@ PyErr_WriteUnraisable(PyObject *obj)
780780extern PyObject * PyModule_GetWarningsModule (void );
781781
782782
783+ void
784+ PyErr_SyntaxLocation (const char * filename , int lineno ) {
785+ PyErr_SyntaxLocationEx (filename , lineno , -1 );
786+ }
787+
788+
783789/* Set file and line information for the current exception.
784790 If the exception is not a SyntaxError, also sets additional attributes
785791 to make printing of exceptions believe it is a syntax error. */
786792
787793void
788- PyErr_SyntaxLocation (const char * filename , int lineno )
794+ PyErr_SyntaxLocationEx (const char * filename , int lineno , int col_offset )
789795{
790796 PyObject * exc , * v , * tb , * tmp ;
791797
@@ -802,6 +808,16 @@ PyErr_SyntaxLocation(const char *filename, int lineno)
802808 PyErr_Clear ();
803809 Py_DECREF (tmp );
804810 }
811+ if (col_offset >= 0 ) {
812+ tmp = PyLong_FromLong (col_offset );
813+ if (tmp == NULL )
814+ PyErr_Clear ();
815+ else {
816+ if (PyObject_SetAttrString (v , "offset" , tmp ))
817+ PyErr_Clear ();
818+ Py_DECREF (tmp );
819+ }
820+ }
805821 if (filename != NULL ) {
806822 tmp = PyUnicode_FromString (filename );
807823 if (tmp == NULL )
You can’t perform that action at this time.
0 commit comments