diff options
author | Victor Stinner <vstinner@python.org> | 2022-11-23 13:57:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-23 13:57:50 (GMT) |
commit | 81f7359f67a7166d57a10a3d5366406d9c85f1de (patch) | |
tree | f72a35747fa77ab9c63ba70ef9e1620daddf0cc3 /Python | |
parent | 5d9183c7ad68eb9ddb53d54a3f9a27e29dbabf31 (diff) | |
download | cpython-81f7359f67a7166d57a10a3d5366406d9c85f1de.zip cpython-81f7359f67a7166d57a10a3d5366406d9c85f1de.tar.gz cpython-81f7359f67a7166d57a10a3d5366406d9c85f1de.tar.bz2 |
gh-99537: Use Py_SETREF(var, NULL) in C code (#99687)
Replace "Py_DECREF(var); var = NULL;" with "Py_SETREF(var, NULL);".
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 12 | ||||
-rw-r--r-- | Python/errors.c | 3 | ||||
-rw-r--r-- | Python/marshal.c | 12 |
3 files changed, 9 insertions, 18 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index c2cf79a..b3b7e8d 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -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; } diff --git a/Python/errors.c b/Python/errors.c index 6a42f59..05ef622 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -37,8 +37,7 @@ _PyErr_Restore(PyThreadState *tstate, PyObject *type, PyObject *value, if (traceback != NULL && !PyTraceBack_Check(traceback)) { /* XXX Should never happen -- fatal error instead? */ /* Well, it could be None. */ - Py_DECREF(traceback); - traceback = NULL; + Py_SETREF(traceback, NULL); } /* Save these in locals to safeguard against recursive diff --git a/Python/marshal.c b/Python/marshal.c index 86cf57d..5f392d9 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -1217,8 +1217,7 @@ r_object(RFILE *p) if (!PyErr_Occurred()) PyErr_SetString(PyExc_TypeError, "NULL object in marshal data for tuple"); - Py_DECREF(v); - v = NULL; + Py_SETREF(v, NULL); break; } PyTuple_SET_ITEM(v, i, v2); @@ -1244,8 +1243,7 @@ r_object(RFILE *p) if (!PyErr_Occurred()) PyErr_SetString(PyExc_TypeError, "NULL object in marshal data for list"); - Py_DECREF(v); - v = NULL; + Py_SETREF(v, NULL); break; } PyList_SET_ITEM(v, i, v2); @@ -1277,8 +1275,7 @@ r_object(RFILE *p) Py_DECREF(val); } if (PyErr_Occurred()) { - Py_DECREF(v); - v = NULL; + Py_SETREF(v, NULL); } retval = v; break; @@ -1322,8 +1319,7 @@ r_object(RFILE *p) if (!PyErr_Occurred()) PyErr_SetString(PyExc_TypeError, "NULL object in marshal data for set"); - Py_DECREF(v); - v = NULL; + Py_SETREF(v, NULL); break; } if (PySet_Add(v, v2) == -1) { |