mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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:
parent
5d9183c7ad
commit
81f7359f67
22 changed files with 44 additions and 87 deletions
|
@ -3152,8 +3152,7 @@ math_prod_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);
|
||||
}
|
||||
/* Loop over all the items in the iterable until we finish, we overflow
|
||||
* or we found a non integer element */
|
||||
|
@ -3200,8 +3199,7 @@ math_prod_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) {
|
||||
|
@ -3250,8 +3248,7 @@ math_prod_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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue