@@ -465,14 +465,21 @@ com_error(struct compiling *c, PyObject *exc, char *msg)
465465 Py_INCREF (Py_None );
466466 line = Py_None ;
467467 }
468- t = Py_BuildValue ("(ziOO)" , c -> c_filename , c -> c_lineno ,
469- Py_None , line );
470- if (t == NULL )
471- goto exit ;
472- w = Py_BuildValue ("(OO)" , v , t );
473- if (w == NULL )
474- goto exit ;
475- PyErr_SetObject (exc , w );
468+ if (exc == PyExc_SyntaxError ) {
469+ t = Py_BuildValue ("(ziOO)" , c -> c_filename , c -> c_lineno ,
470+ Py_None , line );
471+ if (t == NULL )
472+ goto exit ;
473+ w = Py_BuildValue ("(OO)" , v , t );
474+ if (w == NULL )
475+ goto exit ;
476+ PyErr_SetObject (exc , w );
477+ } else {
478+ /* Make sure additional exceptions are printed with
479+ file and line, also. */
480+ PyErr_SetObject (exc , v );
481+ PyErr_SyntaxLocation (c -> c_filename , c -> c_lineno );
482+ }
476483 exit :
477484 Py_XDECREF (t );
478485 Py_XDECREF (v );
@@ -1153,7 +1160,8 @@ parsestr(struct compiling *com, char *s)
11531160 s ++ ;
11541161 len = strlen (s );
11551162 if (len > INT_MAX ) {
1156- PyErr_SetString (PyExc_OverflowError , "string to parse is too long" );
1163+ com_error (com , PyExc_OverflowError ,
1164+ "string to parse is too long" );
11571165 return NULL ;
11581166 }
11591167 if (s [-- len ] != quote ) {
@@ -1171,11 +1179,15 @@ parsestr(struct compiling *com, char *s)
11711179#ifdef Py_USING_UNICODE
11721180 if (unicode || Py_UnicodeFlag ) {
11731181 if (rawmode )
1174- return PyUnicode_DecodeRawUnicodeEscape (
1175- s , len , NULL );
1182+ v = PyUnicode_DecodeRawUnicodeEscape (
1183+ s , len , NULL );
11761184 else
1177- return PyUnicode_DecodeUnicodeEscape (
1185+ v = PyUnicode_DecodeUnicodeEscape (
11781186 s , len , NULL );
1187+ if (v == NULL )
1188+ PyErr_SyntaxLocation (com -> c_filename , com -> c_lineno );
1189+ return v ;
1190+
11791191 }
11801192#endif
11811193 if (rawmode || strchr (s , '\\' ) == NULL )
@@ -1238,9 +1250,9 @@ parsestr(struct compiling *com, char *s)
12381250 * p ++ = x ;
12391251 break ;
12401252 }
1241- PyErr_SetString (PyExc_ValueError ,
1242- "invalid \\x escape" );
12431253 Py_DECREF (v );
1254+ com_error (com , PyExc_ValueError ,
1255+ "invalid \\x escape" );
12441256 return NULL ;
12451257 default :
12461258 * p ++ = '\\' ;
0 commit comments