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

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-14 13:08:43 +01:00 • committed by GitHub
parent 3817607b8a
commit 7e4dec02ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 75 additions and 144 deletions

View file

@ -188,8 +188,7 @@ write_str(stringio *self, PyObject *obj)
self->decoder, obj, 1 /* always final */);
}
else {
decoded = obj;
Py_INCREF(decoded);
decoded = Py_NewRef(obj);
}
if (self->writenl) {
PyObject *translated = PyUnicode_Replace(
@ -710,8 +709,7 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
is pointless for StringIO)
*/
if (newline != NULL && newline[0] == '\r') {
self->writenl = self->readnl;
Py_INCREF(self->writenl);
self->writenl = Py_NewRef(self->readnl);
}
if (self->readuniversal) {
@ -823,8 +821,7 @@ stringio_getstate(stringio *self, PyObject *Py_UNUSED(ignored))
if (initvalue == NULL)
return NULL;
if (self->dict == NULL) {
Py_INCREF(Py_None);
dict = Py_None;
dict = Py_NewRef(Py_None);
}
else {
dict = PyDict_Copy(self->dict);
@ -934,8 +931,7 @@ stringio_setstate(stringio *self, PyObject *state)
return NULL;
}
else {
Py_INCREF(dict);
self->dict = dict;
self->dict = Py_NewRef(dict);
}
}