gh-99300: Use Py_NewRef() in Modules/ directory (#99440)

Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in test C files of the Modules/ directory.
This commit is contained in:
Victor Stinner 2022-11-13 16:04:33 +01:00 committed by GitHub
parent 0bedc28d14
commit bbba3f3f43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 82 deletions

View file

@ -57,8 +57,7 @@ Example_demo(ExampleObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|O:demo", &o))
return NULL;
if (o != NULL && PyUnicode_Check(o)) {
Py_INCREF(o);
return o;
return Py_NewRef(o);
}
Py_RETURN_NONE;
}
@ -77,8 +76,7 @@ Example_getattro(ExampleObject *self, PyObject *name)
if (self->x_attr != NULL) {
PyObject *v = PyDict_GetItemWithError(self->x_attr, name);
if (v != NULL) {
Py_INCREF(v);
return v;
return Py_NewRef(v);
}
else if (PyErr_Occurred()) {
return NULL;
@ -151,8 +149,7 @@ _testmultiphase_StateAccessType_get_defining_module_impl(StateAccessTypeObject *
return NULL;
}
assert(PyType_GetModuleByDef(Py_TYPE(self), &def_meth_state_access) == retval);
Py_INCREF(retval);
return retval;
return Py_NewRef(retval);
}
/*[clinic input]