@@ -249,7 +249,6 @@ func_get_code(PyFunctionObject *op)
249249static int
250250func_set_code (PyFunctionObject * op , PyObject * value )
251251{
252- PyObject * tmp ;
253252 Py_ssize_t nfree , nclosure ;
254253
255254 /* Not legal to del f.func_code or to set it to anything
@@ -270,10 +269,8 @@ func_set_code(PyFunctionObject *op, PyObject *value)
270269 nclosure , nfree );
271270 return -1 ;
272271 }
273- tmp = op -> func_code ;
274272 Py_INCREF (value );
275- op -> func_code = value ;
276- Py_DECREF (tmp );
273+ Py_SETREF (op -> func_code , value );
277274 return 0 ;
278275}
279276
@@ -287,19 +284,15 @@ func_get_name(PyFunctionObject *op)
287284static int
288285func_set_name (PyFunctionObject * op , PyObject * value )
289286{
290- PyObject * tmp ;
291-
292287 /* Not legal to del f.func_name or to set it to anything
293288 * other than a string object. */
294289 if (value == NULL || !PyUnicode_Check (value )) {
295290 PyErr_SetString (PyExc_TypeError ,
296291 "__name__ must be set to a string object" );
297292 return -1 ;
298293 }
299- tmp = op -> func_name ;
300294 Py_INCREF (value );
301- op -> func_name = value ;
302- Py_DECREF (tmp );
295+ Py_SETREF (op -> func_name , value );
303296 return 0 ;
304297}
305298
@@ -313,19 +306,15 @@ func_get_qualname(PyFunctionObject *op)
313306static int
314307func_set_qualname (PyFunctionObject * op , PyObject * value )
315308{
316- PyObject * tmp ;
317-
318309 /* Not legal to del f.__qualname__ or to set it to anything
319310 * other than a string object. */
320311 if (value == NULL || !PyUnicode_Check (value )) {
321312 PyErr_SetString (PyExc_TypeError ,
322313 "__qualname__ must be set to a string object" );
323314 return -1 ;
324315 }
325- tmp = op -> func_qualname ;
326316 Py_INCREF (value );
327- op -> func_qualname = value ;
328- Py_DECREF (tmp );
317+ Py_SETREF (op -> func_qualname , value );
329318 return 0 ;
330319}
331320
@@ -343,8 +332,6 @@ func_get_defaults(PyFunctionObject *op)
343332static int
344333func_set_defaults (PyFunctionObject * op , PyObject * value )
345334{
346- PyObject * tmp ;
347-
348335 /* Legal to del f.func_defaults.
349336 * Can only set func_defaults to NULL or a tuple. */
350337 if (value == Py_None )
@@ -354,10 +341,8 @@ func_set_defaults(PyFunctionObject *op, PyObject *value)
354341 "__defaults__ must be set to a tuple object" );
355342 return -1 ;
356343 }
357- tmp = op -> func_defaults ;
358344 Py_XINCREF (value );
359- op -> func_defaults = value ;
360- Py_XDECREF (tmp );
345+ Py_SETREF (op -> func_defaults , value );
361346 return 0 ;
362347}
363348
@@ -375,8 +360,6 @@ func_get_kwdefaults(PyFunctionObject *op)
375360static int
376361func_set_kwdefaults (PyFunctionObject * op , PyObject * value )
377362{
378- PyObject * tmp ;
379-
380363 if (value == Py_None )
381364 value = NULL ;
382365 /* Legal to del f.func_kwdefaults.
@@ -386,10 +369,8 @@ func_set_kwdefaults(PyFunctionObject *op, PyObject *value)
386369 "__kwdefaults__ must be set to a dict object" );
387370 return -1 ;
388371 }
389- tmp = op -> func_kwdefaults ;
390372 Py_XINCREF (value );
391- op -> func_kwdefaults = value ;
392- Py_XDECREF (tmp );
373+ Py_SETREF (op -> func_kwdefaults , value );
393374 return 0 ;
394375}
395376
@@ -408,8 +389,6 @@ func_get_annotations(PyFunctionObject *op)
408389static int
409390func_set_annotations (PyFunctionObject * op , PyObject * value )
410391{
411- PyObject * tmp ;
412-
413392 if (value == Py_None )
414393 value = NULL ;
415394 /* Legal to del f.func_annotations.
@@ -420,10 +399,8 @@ func_set_annotations(PyFunctionObject *op, PyObject *value)
420399 "__annotations__ must be set to a dict object" );
421400 return -1 ;
422401 }
423- tmp = op -> func_annotations ;
424402 Py_XINCREF (value );
425- op -> func_annotations = value ;
426- Py_XDECREF (tmp );
403+ Py_SETREF (op -> func_annotations , value );
427404 return 0 ;
428405}
429406
0 commit comments