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

@ -806,8 +806,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
PyErr_Format(PyExc_TypeError,
"__format__ must return a str, not %.200s",
Py_TYPE(result)->tp_name);
Py_DECREF(result);
result = NULL;
Py_SETREF(result, NULL);
goto done;
}
@ -2791,8 +2790,7 @@ PyObject_GetIter(PyObject *o)
"iter() returned non-iterator "
"of type '%.100s'",
Py_TYPE(res)->tp_name);
Py_DECREF(res);
res = NULL;
Py_SETREF(res, NULL);
}
return res;
}
@ -2812,8 +2810,7 @@ PyObject_GetAIter(PyObject *o) {
PyErr_Format(PyExc_TypeError,
"aiter() returned not an async iterator of type '%.100s'",
Py_TYPE(it)->tp_name);
Py_DECREF(it);
it = NULL;
Py_SETREF(it, NULL);
}
return it;
}