@@ -424,8 +424,7 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
424424 Py_DECREF ((PyObject * )dict );
425425 return NULL ;
426426 }
427- Py_DECREF (result -> tp_dict );
428- result -> tp_dict = (PyObject * )dict ;
427+ Py_SETREF (result -> tp_dict , (PyObject * )dict );
429428 dict -> format = _ctypes_alloc_format_string (NULL , "B" );
430429 if (dict -> format == NULL ) {
431430 Py_DECREF (result );
@@ -903,8 +902,7 @@ PyCPointerType_SetProto(StgDictObject *stgdict, PyObject *proto)
903902 return -1 ;
904903 }
905904 Py_INCREF (proto );
906- Py_XDECREF (stgdict -> proto );
907- stgdict -> proto = proto ;
905+ Py_SETREF (stgdict -> proto , proto );
908906 return 0 ;
909907}
910908
@@ -994,8 +992,7 @@ PyCPointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
994992 Py_DECREF ((PyObject * )stgdict );
995993 return NULL ;
996994 }
997- Py_DECREF (result -> tp_dict );
998- result -> tp_dict = (PyObject * )stgdict ;
995+ Py_SETREF (result -> tp_dict , (PyObject * )stgdict );
999996
1000997 return (PyObject * )result ;
1001998}
@@ -1460,8 +1457,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
14601457 Py_DECREF ((PyObject * )stgdict );
14611458 return NULL ;
14621459 }
1463- Py_DECREF (result -> tp_dict );
1464- result -> tp_dict = (PyObject * )stgdict ;
1460+ Py_SETREF (result -> tp_dict , (PyObject * )stgdict );
14651461
14661462 /* Special case for character arrays.
14671463 A permanent annoyance: char arrays are also strings!
@@ -1884,8 +1880,7 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
18841880 Py_DECREF ((PyObject * )stgdict );
18851881 return NULL ;
18861882 }
1887- Py_DECREF (result -> tp_dict );
1888- result -> tp_dict = (PyObject * )stgdict ;
1883+ Py_SETREF (result -> tp_dict , (PyObject * )stgdict );
18891884
18901885 return (PyObject * )result ;
18911886}
@@ -2393,8 +2388,7 @@ PyCFuncPtrType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
23932388 Py_DECREF ((PyObject * )stgdict );
23942389 return NULL ;
23952390 }
2396- Py_DECREF (result -> tp_dict );
2397- result -> tp_dict = (PyObject * )stgdict ;
2391+ Py_SETREF (result -> tp_dict , (PyObject * )stgdict );
23982392
23992393 if (-1 == make_funcptrtype_dict (stgdict )) {
24002394 Py_DECREF (result );
@@ -2536,8 +2530,7 @@ KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep)
25362530 }
25372531 ob = PyCData_GetContainer (target );
25382532 if (ob -> b_objects == NULL || !PyDict_CheckExact (ob -> b_objects )) {
2539- Py_XDECREF (ob -> b_objects );
2540- ob -> b_objects = keep ; /* refcount consumed */
2533+ Py_SETREF (ob -> b_objects , keep ); /* refcount consumed */
25412534 return 0 ;
25422535 }
25432536 key = unique_key (target , index );
@@ -3059,9 +3052,8 @@ PyCFuncPtr_set_errcheck(PyCFuncPtrObject *self, PyObject *ob)
30593052 "the errcheck attribute must be callable" );
30603053 return -1 ;
30613054 }
3062- Py_XDECREF (self -> errcheck );
30633055 Py_XINCREF (ob );
3064- self -> errcheck = ob ;
3056+ Py_SETREF ( self -> errcheck , ob ) ;
30653057 return 0 ;
30663058}
30673059
@@ -3090,9 +3082,8 @@ PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob)
30903082 return -1 ;
30913083 }
30923084 Py_XDECREF (self -> checker );
3093- Py_XDECREF (self -> restype );
30943085 Py_INCREF (ob );
3095- self -> restype = ob ;
3086+ Py_SETREF ( self -> restype , ob ) ;
30963087 self -> checker = PyObject_GetAttrString (ob , "_check_retval_" );
30973088 if (self -> checker == NULL )
30983089 PyErr_Clear ();
@@ -3130,11 +3121,9 @@ PyCFuncPtr_set_argtypes(PyCFuncPtrObject *self, PyObject *ob)
31303121 converters = converters_from_argtypes (ob );
31313122 if (!converters )
31323123 return -1 ;
3133- Py_XDECREF (self -> converters );
3134- self -> converters = converters ;
3135- Py_XDECREF (self -> argtypes );
3124+ Py_SETREF (self -> converters , converters );
31363125 Py_INCREF (ob );
3137- self -> argtypes = ob ;
3126+ Py_SETREF ( self -> argtypes , ob ) ;
31383127 }
31393128 return 0 ;
31403129}
0 commit comments