@@ -206,8 +206,7 @@ BaseException_set_args(PyBaseExceptionObject *self, PyObject *val)
206206 seq = PySequence_Tuple (val );
207207 if (!seq )
208208 return -1 ;
209- Py_CLEAR (self -> args );
210- self -> args = seq ;
209+ Py_SETREF (self -> args , seq );
211210 return 0 ;
212211}
213212
@@ -646,9 +645,8 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds)
646645 if (!PyArg_UnpackTuple (args , "ImportError" , 1 , 1 , & msg ))
647646 return -1 ;
648647
649- Py_CLEAR (self -> msg ); /* replacing */
650- self -> msg = msg ;
651- Py_INCREF (self -> msg );
648+ Py_INCREF (msg );
649+ Py_SETREF (self -> msg , msg );
652650
653651 return 0 ;
654652}
@@ -858,8 +856,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
858856#endif
859857
860858 /* Steals the reference to args */
861- Py_CLEAR (self -> args );
862- self -> args = args ;
859+ Py_SETREF (self -> args , args );
863860 * p_args = args = NULL ;
864861
865862 return 0 ;
@@ -1278,9 +1275,8 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
12781275 return -1 ;
12791276
12801277 if (lenargs >= 1 ) {
1281- Py_CLEAR (self -> msg );
1282- self -> msg = PyTuple_GET_ITEM (args , 0 );
1283- Py_INCREF (self -> msg );
1278+ Py_INCREF (PyTuple_GET_ITEM (args , 0 ));
1279+ Py_SETREF (self -> msg , PyTuple_GET_ITEM (args , 0 ));
12841280 }
12851281 if (lenargs == 2 ) {
12861282 info = PyTuple_GET_ITEM (args , 1 );
@@ -1295,21 +1291,17 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
12951291 return -1 ;
12961292 }
12971293
1298- Py_CLEAR (self -> filename );
1299- self -> filename = PyTuple_GET_ITEM (info , 0 );
1300- Py_INCREF (self -> filename );
1294+ Py_INCREF (PyTuple_GET_ITEM (info , 0 ));
1295+ Py_SETREF (self -> filename , PyTuple_GET_ITEM (info , 0 ));
13011296
1302- Py_CLEAR (self -> lineno );
1303- self -> lineno = PyTuple_GET_ITEM (info , 1 );
1304- Py_INCREF (self -> lineno );
1297+ Py_INCREF (PyTuple_GET_ITEM (info , 1 ));
1298+ Py_SETREF (self -> lineno , PyTuple_GET_ITEM (info , 1 ));
13051299
1306- Py_CLEAR (self -> offset );
1307- self -> offset = PyTuple_GET_ITEM (info , 2 );
1308- Py_INCREF (self -> offset );
1300+ Py_INCREF (PyTuple_GET_ITEM (info , 2 ));
1301+ Py_SETREF (self -> offset , PyTuple_GET_ITEM (info , 2 ));
13091302
1310- Py_CLEAR (self -> text );
1311- self -> text = PyTuple_GET_ITEM (info , 3 );
1312- Py_INCREF (self -> text );
1303+ Py_INCREF (PyTuple_GET_ITEM (info , 3 ));
1304+ Py_SETREF (self -> text , PyTuple_GET_ITEM (info , 3 ));
13131305
13141306 Py_DECREF (info );
13151307
@@ -1554,8 +1546,7 @@ set_unicodefromstring(PyObject **attr, const char *value)
15541546 PyObject * obj = PyUnicode_FromString (value );
15551547 if (!obj )
15561548 return -1 ;
1557- Py_CLEAR (* attr );
1558- * attr = obj ;
1549+ Py_SETREF (* attr , obj );
15591550 return 0 ;
15601551}
15611552
@@ -1961,8 +1952,7 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds)
19611952 Py_buffer view ;
19621953 if (PyObject_GetBuffer (ude -> object , & view , PyBUF_SIMPLE ) != 0 )
19631954 goto error ;
1964- Py_CLEAR (ude -> object );
1965- ude -> object = PyBytes_FromStringAndSize (view .buf , view .len );
1955+ Py_SETREF (ude -> object , PyBytes_FromStringAndSize (view .buf , view .len ));
19661956 PyBuffer_Release (& view );
19671957 if (!ude -> object )
19681958 goto error ;
@@ -2871,9 +2861,8 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
28712861 }
28722862 if (PyUnicode_Tailmatch (self -> text , print_prefix ,
28732863 start , text_len , -1 )) {
2874- Py_CLEAR (self -> msg );
2875- self -> msg = PyUnicode_FromString (
2876- "Missing parentheses in call to 'print'" );
2864+ Py_SETREF (self -> msg ,
2865+ PyUnicode_FromString ("Missing parentheses in call to 'print'" ));
28772866 return 1 ;
28782867 }
28792868
@@ -2886,9 +2875,8 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
28862875 }
28872876 if (PyUnicode_Tailmatch (self -> text , exec_prefix ,
28882877 start , text_len , -1 )) {
2889- Py_CLEAR (self -> msg );
2890- self -> msg = PyUnicode_FromString (
2891- "Missing parentheses in call to 'exec'" );
2878+ Py_SETREF (self -> msg ,
2879+ PyUnicode_FromString ("Missing parentheses in call to 'exec'" ));
28922880 return 1 ;
28932881 }
28942882 /* Fall back to the default error message */
0 commit comments