summaryrefslogtreecommitdiffstats
path: root/Modules/_io/bytesio.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-14 12:08:43 (GMT)
committerGitHub <noreply@github.com>2022-11-14 12:08:43 (GMT)
commit7e4dec02ac86bcbe958f299f68ed25d543c23ef9 (patch)
treebc9999d57707f92f6dc390fed16af10f71e29ddb /Modules/_io/bytesio.c
parent3817607b8a345851e4fa436747a346890ced33f1 (diff)
downloadcpython-7e4dec02ac86bcbe958f299f68ed25d543c23ef9.zip
cpython-7e4dec02ac86bcbe958f299f68ed25d543c23ef9.tar.gz
cpython-7e4dec02ac86bcbe958f299f68ed25d543c23ef9.tar.bz2
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.
Diffstat (limited to 'Modules/_io/bytesio.c')
-rw-r--r--Modules/_io/bytesio.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index 930ef7e..41be349 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -324,8 +324,7 @@ _io_BytesIO_getbuffer_impl(bytesio *self)
buf = (bytesiobuf *) type->tp_alloc(type, 0);
if (buf == NULL)
return NULL;
- Py_INCREF(self);
- buf->source = self;
+ buf->source = (bytesio*)Py_NewRef(self);
view = PyMemoryView_FromObject((PyObject *) buf);
Py_DECREF(buf);
return view;
@@ -356,8 +355,7 @@ _io_BytesIO_getvalue_impl(bytesio *self)
return NULL;
}
}
- Py_INCREF(self->buf);
- return self->buf;
+ return Py_NewRef(self->buf);
}
/*[clinic input]
@@ -401,8 +399,7 @@ read_bytes(bytesio *self, Py_ssize_t size)
self->pos == 0 && size == PyBytes_GET_SIZE(self->buf) &&
self->exports == 0) {
self->pos += size;
- Py_INCREF(self->buf);
- return self->buf;
+ return Py_NewRef(self->buf);
}
output = PyBytes_AS_STRING(self->buf) + self->pos;
@@ -791,8 +788,7 @@ bytesio_getstate(bytesio *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);
@@ -875,8 +871,7 @@ bytesio_setstate(bytesio *self, PyObject *state)
return NULL;
}
else {
- Py_INCREF(dict);
- self->dict = dict;
+ self->dict = Py_NewRef(dict);
}
}
@@ -943,8 +938,7 @@ _io_BytesIO___init___impl(bytesio *self, PyObject *initvalue)
}
if (initvalue && initvalue != Py_None) {
if (PyBytes_CheckExact(initvalue)) {
- Py_INCREF(initvalue);
- Py_XSETREF(self->buf, initvalue);
+ Py_XSETREF(self->buf, Py_NewRef(initvalue));
self->string_size = PyBytes_GET_SIZE(initvalue);
}
else {