gh-99300: Replace Py_INCREF() with Py_NewRef() (#99530)

Replace Py_INCREF() and Py_XINCREF() using a cast with Py_NewRef()
and Py_XNewRef().
This commit is contained in:
Victor Stinner 2022-11-16 18:34:24 +01:00 committed by GitHub
parent 19c1462e8d
commit 8211cf5d28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 40 additions and 74 deletions

View file

@ -5437,8 +5437,7 @@ object_getstate_default(PyObject *obj, int required)
for (i = 0; i < slotnames_size; i++) {
PyObject *name, *value;
name = PyList_GET_ITEM(slotnames, i);
Py_INCREF(name);
name = Py_NewRef(PyList_GET_ITEM(slotnames, i));
if (_PyObject_LookupAttr(obj, name, &value) < 0) {
Py_DECREF(name);
goto error;
@ -5570,10 +5569,8 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs)
Py_DECREF(newargs);
return -1;
}
*args = PyTuple_GET_ITEM(newargs, 0);
Py_INCREF(*args);
*kwargs = PyTuple_GET_ITEM(newargs, 1);
Py_INCREF(*kwargs);
*args = Py_NewRef(PyTuple_GET_ITEM(newargs, 0));
*kwargs = Py_NewRef(PyTuple_GET_ITEM(newargs, 1));
Py_DECREF(newargs);
/* XXX We should perhaps allow None to be passed here. */
@ -9601,8 +9598,7 @@ super_init_impl(PyObject *self, PyTypeObject *type, PyObject *obj) {
return -1;
Py_INCREF(obj);
}
Py_INCREF(type);
Py_XSETREF(su->type, type);
Py_XSETREF(su->type, Py_NewRef(type));
Py_XSETREF(su->obj, obj);
Py_XSETREF(su->obj_type, obj_type);
return 0;