@@ -391,8 +391,7 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
391391 Py_DECREF ((PyObject * )dict );
392392 return NULL ;
393393 }
394- Py_DECREF (result -> tp_dict );
395- result -> tp_dict = (PyObject * )dict ;
394+ Py_SETREF (result -> tp_dict , (PyObject * )dict );
396395 dict -> format = _ctypes_alloc_format_string (NULL , "B" );
397396 if (dict -> format == NULL ) {
398397 Py_DECREF (result );
@@ -871,8 +870,7 @@ PyCPointerType_SetProto(StgDictObject *stgdict, PyObject *proto)
871870 return -1 ;
872871 }
873872 Py_INCREF (proto );
874- Py_XDECREF (stgdict -> proto );
875- stgdict -> proto = proto ;
873+ Py_SETREF (stgdict -> proto , proto );
876874 return 0 ;
877875}
878876
@@ -962,8 +960,7 @@ PyCPointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
962960 Py_DECREF ((PyObject * )stgdict );
963961 return NULL ;
964962 }
965- Py_DECREF (result -> tp_dict );
966- result -> tp_dict = (PyObject * )stgdict ;
963+ Py_SETREF (result -> tp_dict , (PyObject * )stgdict );
967964
968965 return (PyObject * )result ;
969966}
@@ -1406,8 +1403,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
14061403 /* replace the class dict by our updated spam dict */
14071404 if (-1 == PyDict_Update ((PyObject * )stgdict , result -> tp_dict ))
14081405 goto error ;
1409- Py_DECREF (result -> tp_dict );
1410- result -> tp_dict = (PyObject * )stgdict ; /* steal the reference */
1406+ Py_SETREF (result -> tp_dict , (PyObject * )stgdict ); /* steal the reference */
14111407 stgdict = NULL ;
14121408
14131409 /* Special case for character arrays.
@@ -1820,8 +1816,7 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
18201816 Py_DECREF ((PyObject * )stgdict );
18211817 return NULL ;
18221818 }
1823- Py_DECREF (result -> tp_dict );
1824- result -> tp_dict = (PyObject * )stgdict ;
1819+ Py_SETREF (result -> tp_dict , (PyObject * )stgdict );
18251820
18261821 return (PyObject * )result ;
18271822}
@@ -1949,8 +1944,7 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
19491944 Py_DECREF ((PyObject * )stgdict );
19501945 return NULL ;
19511946 }
1952- Py_DECREF (result -> tp_dict );
1953- result -> tp_dict = (PyObject * )stgdict ;
1947+ Py_SETREF (result -> tp_dict , (PyObject * )stgdict );
19541948
19551949 /* Install from_param class methods in ctypes base classes.
19561950 Overrides the PyCSimpleType_from_param generic method.
@@ -2313,8 +2307,7 @@ PyCFuncPtrType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
23132307 Py_DECREF ((PyObject * )stgdict );
23142308 return NULL ;
23152309 }
2316- Py_DECREF (result -> tp_dict );
2317- result -> tp_dict = (PyObject * )stgdict ;
2310+ Py_SETREF (result -> tp_dict , (PyObject * )stgdict );
23182311
23192312 if (-1 == make_funcptrtype_dict (stgdict )) {
23202313 Py_DECREF (result );
@@ -2458,8 +2451,7 @@ KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep)
24582451 return -1 ;
24592452 }
24602453 if (ob -> b_objects == NULL || !PyDict_CheckExact (ob -> b_objects )) {
2461- Py_XDECREF (ob -> b_objects );
2462- ob -> b_objects = keep ; /* refcount consumed */
2454+ Py_SETREF (ob -> b_objects , keep ); /* refcount consumed */
24632455 return 0 ;
24642456 }
24652457 key = unique_key (target , index );
@@ -2962,9 +2954,8 @@ PyCFuncPtr_set_errcheck(PyCFuncPtrObject *self, PyObject *ob)
29622954 "the errcheck attribute must be callable" );
29632955 return -1 ;
29642956 }
2965- Py_XDECREF (self -> errcheck );
29662957 Py_XINCREF (ob );
2967- self -> errcheck = ob ;
2958+ Py_SETREF ( self -> errcheck , ob ) ;
29682959 return 0 ;
29692960}
29702961
@@ -2993,9 +2984,8 @@ PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob)
29932984 return -1 ;
29942985 }
29952986 Py_XDECREF (self -> checker );
2996- Py_XDECREF (self -> restype );
29972987 Py_INCREF (ob );
2998- self -> restype = ob ;
2988+ Py_SETREF ( self -> restype , ob ) ;
29992989 self -> checker = PyObject_GetAttrString (ob , "_check_retval_" );
30002990 if (self -> checker == NULL )
30012991 PyErr_Clear ();
@@ -3033,11 +3023,9 @@ PyCFuncPtr_set_argtypes(PyCFuncPtrObject *self, PyObject *ob)
30333023 converters = converters_from_argtypes (ob );
30343024 if (!converters )
30353025 return -1 ;
3036- Py_XDECREF (self -> converters );
3037- self -> converters = converters ;
3038- Py_XDECREF (self -> argtypes );
3026+ Py_SETREF (self -> converters , converters );
30393027 Py_INCREF (ob );
3040- self -> argtypes = ob ;
3028+ Py_SETREF ( self -> argtypes , ob ) ;
30413029 }
30423030 return 0 ;
30433031}
@@ -5164,9 +5152,8 @@ comerror_init(PyObject *self, PyObject *args, PyObject *kwds)
51645152 return -1 ;
51655153
51665154 bself = (PyBaseExceptionObject * )self ;
5167- Py_DECREF (bself -> args );
5168- bself -> args = args ;
5169- Py_INCREF (bself -> args );
5155+ Py_INCREF (args );
5156+ Py_SETREF (bself -> args , args );
51705157
51715158 return 0 ;
51725159}
0 commit comments