@@ -1112,27 +1112,15 @@ _PyCompile_Error(compiler *c, location loc, const char *format, ...)
11121112 if (msg == NULL ) {
11131113 return ERROR ;
11141114 }
1115- PyObject * loc_obj = PyErr_ProgramTextObject (c -> c_filename , loc .lineno );
1116- if (loc_obj == NULL ) {
1117- loc_obj = Py_None ;
1118- }
1119- PyObject * args = Py_BuildValue ("O(OiiOii)" , msg , c -> c_filename ,
1120- loc .lineno , loc .col_offset + 1 , loc_obj ,
1121- loc .end_lineno , loc .end_col_offset + 1 );
1115+ _PyErr_RaiseSyntaxError (msg , c -> c_filename , loc .lineno , loc .col_offset + 1 ,
1116+ loc .end_lineno , loc .end_col_offset + 1 );
11221117 Py_DECREF (msg );
1123- if (args == NULL ) {
1124- goto exit ;
1125- }
1126- PyErr_SetObject (PyExc_SyntaxError , args );
1127- exit :
1128- Py_DECREF (loc_obj );
1129- Py_XDECREF (args );
11301118 return ERROR ;
11311119}
11321120
1133- /* Emits a SyntaxWarning and returns 1 on success.
1121+ /* Emits a SyntaxWarning and returns 0 on success.
11341122 If a SyntaxWarning raised as error, replaces it with a SyntaxError
1135- and returns 0 .
1123+ and returns -1 .
11361124*/
11371125int
11381126_PyCompile_Warn (compiler * c , location loc , const char * format , ...)
@@ -1144,21 +1132,10 @@ _PyCompile_Warn(compiler *c, location loc, const char *format, ...)
11441132 if (msg == NULL ) {
11451133 return ERROR ;
11461134 }
1147- if (PyErr_WarnExplicitObject (PyExc_SyntaxWarning , msg , c -> c_filename ,
1148- loc .lineno , NULL , NULL ) < 0 )
1149- {
1150- if (PyErr_ExceptionMatches (PyExc_SyntaxWarning )) {
1151- /* Replace the SyntaxWarning exception with a SyntaxError
1152- to get a more accurate error report */
1153- PyErr_Clear ();
1154- assert (PyUnicode_AsUTF8 (msg ) != NULL );
1155- _PyCompile_Error (c , loc , PyUnicode_AsUTF8 (msg ));
1156- }
1157- Py_DECREF (msg );
1158- return ERROR ;
1159- }
1135+ int ret = _PyErr_EmitSyntaxWarning (msg , c -> c_filename , loc .lineno , loc .col_offset + 1 ,
1136+ loc .end_lineno , loc .end_col_offset + 1 );
11601137 Py_DECREF (msg );
1161- return SUCCESS ;
1138+ return ret ;
11621139}
11631140
11641141PyObject *
0 commit comments