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

@ -218,8 +218,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
"__class__ set to %.200R defining %.200R as %.200R";
PyErr_Format(PyExc_TypeError, msg, cell_cls, name, cls);
}
Py_DECREF(cls);
cls = NULL;
Py_SETREF(cls, NULL);
goto error;
}
}
@ -2483,8 +2482,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
long i_result = PyLong_AsLongAndOverflow(result, &overflow);
/* If this already overflowed, don't even enter the loop. */
if (overflow == 0) {
Py_DECREF(result);
result = NULL;
Py_SETREF(result, NULL);
}
while(result == NULL) {
item = PyIter_Next(iter);
@ -2534,8 +2532,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
if (PyFloat_CheckExact(result)) {
double f_result = PyFloat_AS_DOUBLE(result);
Py_DECREF(result);
result = NULL;
Py_SETREF(result, NULL);
while(result == NULL) {
item = PyIter_Next(iter);
if (item == NULL) {
@ -2582,8 +2579,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
if (item == NULL) {
/* error, or end-of-sequence */
if (PyErr_Occurred()) {
Py_DECREF(result);
result = NULL;
Py_SETREF(result, NULL);
}
break;
}