gh-99537: Use Py_SETREF(var, NULL) in C code (#99687)

Replace "Py_DECREF(var); var = NULL;" with "Py_SETREF(var, NULL);".
This commit is contained in:
Victor Stinner 2022-11-23 14:57:50 +01:00 committed by GitHub
parent 5d9183c7ad
commit 81f7359f67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 44 additions and 87 deletions

View file

@ -1213,8 +1213,7 @@ type_repr(PyTypeObject *type)
if (mod == NULL)
PyErr_Clear();
else if (!PyUnicode_Check(mod)) {
Py_DECREF(mod);
mod = NULL;
Py_SETREF(mod, NULL);
}
name = type_qualname(type, NULL);
if (name == NULL) {
@ -1288,8 +1287,7 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds)
int res = type->tp_init(obj, args, kwds);
if (res < 0) {
assert(_PyErr_Occurred(tstate));
Py_DECREF(obj);
obj = NULL;
Py_SETREF(obj, NULL);
}
else {
assert(!_PyErr_Occurred(tstate));
@ -5007,8 +5005,7 @@ object_repr(PyObject *self)
if (mod == NULL)
PyErr_Clear();
else if (!PyUnicode_Check(mod)) {
Py_DECREF(mod);
mod = NULL;
Py_SETREF(mod, NULL);
}
name = type_qualname(type, NULL);
if (name == NULL) {
@ -8107,8 +8104,7 @@ slot_tp_hash(PyObject *self)
func = lookup_maybe_method(self, &_Py_ID(__hash__), &unbound);
if (func == Py_None) {
Py_DECREF(func);
func = NULL;
Py_SETREF(func, NULL);
}
if (func == NULL) {