mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +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
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,8 +283,7 @@ method_repr(PyMethodObject *a)
|
|||
}
|
||||
|
||||
if (funcname != NULL && !PyUnicode_Check(funcname)) {
|
||||
Py_DECREF(funcname);
|
||||
funcname = NULL;
|
||||
Py_SETREF(funcname, NULL);
|
||||
}
|
||||
|
||||
/* XXX Shouldn't use repr()/%R here! */
|
||||
|
|
@ -484,8 +483,7 @@ instancemethod_repr(PyObject *self)
|
|||
return NULL;
|
||||
}
|
||||
if (funcname != NULL && !PyUnicode_Check(funcname)) {
|
||||
Py_DECREF(funcname);
|
||||
funcname = NULL;
|
||||
Py_SETREF(funcname, NULL);
|
||||
}
|
||||
|
||||
result = PyUnicode_FromFormat("<instancemethod %V at %p>",
|
||||
|
|
|
|||
|
|
@ -906,8 +906,7 @@ descr_new(PyTypeObject *descrtype, PyTypeObject *type, const char *name)
|
|||
descr->d_type = (PyTypeObject*)Py_XNewRef(type);
|
||||
descr->d_name = PyUnicode_InternFromString(name);
|
||||
if (descr->d_name == NULL) {
|
||||
Py_DECREF(descr);
|
||||
descr = NULL;
|
||||
Py_SETREF(descr, NULL);
|
||||
}
|
||||
else {
|
||||
descr->d_qualname = NULL;
|
||||
|
|
|
|||
|
|
@ -67,8 +67,7 @@ PyFile_GetLine(PyObject *f, int n)
|
|||
}
|
||||
if (result != NULL && !PyBytes_Check(result) &&
|
||||
!PyUnicode_Check(result)) {
|
||||
Py_DECREF(result);
|
||||
result = NULL;
|
||||
Py_SETREF(result, NULL);
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"object.readline() returned non-string");
|
||||
}
|
||||
|
|
@ -77,8 +76,7 @@ PyFile_GetLine(PyObject *f, int n)
|
|||
const char *s = PyBytes_AS_STRING(result);
|
||||
Py_ssize_t len = PyBytes_GET_SIZE(result);
|
||||
if (len == 0) {
|
||||
Py_DECREF(result);
|
||||
result = NULL;
|
||||
Py_SETREF(result, NULL);
|
||||
PyErr_SetString(PyExc_EOFError,
|
||||
"EOF when reading a line");
|
||||
}
|
||||
|
|
@ -95,8 +93,7 @@ PyFile_GetLine(PyObject *f, int n)
|
|||
if (n < 0 && result != NULL && PyUnicode_Check(result)) {
|
||||
Py_ssize_t len = PyUnicode_GET_LENGTH(result);
|
||||
if (len == 0) {
|
||||
Py_DECREF(result);
|
||||
result = NULL;
|
||||
Py_SETREF(result, NULL);
|
||||
PyErr_SetString(PyExc_EOFError,
|
||||
"EOF when reading a line");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue