summaryrefslogtreecommitdiffstats
path: root/Objects/memoryobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-10 22:58:07 (GMT)
committerGitHub <noreply@github.com>2022-11-10 22:58:07 (GMT)
commit3a1dde8f29215418ec4e27fd6234cfa19a5407c6 (patch)
tree433d4efb6105ded7a5abcc0f96360731840b10aa /Objects/memoryobject.c
parent1960eb005e04b7ad8a91018088cfdb0646bc1ca0 (diff)
downloadcpython-3a1dde8f29215418ec4e27fd6234cfa19a5407c6.zip
cpython-3a1dde8f29215418ec4e27fd6234cfa19a5407c6.tar.gz
cpython-3a1dde8f29215418ec4e27fd6234cfa19a5407c6.tar.bz2
gh-99300: Use Py_NewRef() in Objects/ directory (#99354)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Objects/ directory.
Diffstat (limited to 'Objects/memoryobject.c')
-rw-r--r--Objects/memoryobject.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c
index c5ab0bf..1d6cc3b 100644
--- a/Objects/memoryobject.c
+++ b/Objects/memoryobject.c
@@ -682,8 +682,7 @@ mbuf_add_view(_PyManagedBufferObject *mbuf, const Py_buffer *src)
init_suboffsets(dest, src);
init_flags(mv);
- mv->mbuf = mbuf;
- Py_INCREF(mbuf);
+ mv->mbuf = (_PyManagedBufferObject*)Py_NewRef(mbuf);
mbuf->exports++;
return (PyObject *)mv;
@@ -713,8 +712,7 @@ mbuf_add_incomplete_view(_PyManagedBufferObject *mbuf, const Py_buffer *src,
dest = &mv->view;
init_shared_values(dest, src);
- mv->mbuf = mbuf;
- Py_INCREF(mbuf);
+ mv->mbuf = (_PyManagedBufferObject*)Py_NewRef(mbuf);
mbuf->exports++;
return (PyObject *)mv;
@@ -1102,8 +1100,7 @@ static PyObject *
memory_enter(PyObject *self, PyObject *args)
{
CHECK_RELEASED(self);
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
static PyObject *
@@ -1515,8 +1512,7 @@ memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags)
}
- view->obj = (PyObject *)self;
- Py_INCREF(view->obj);
+ view->obj = Py_NewRef(self);
self->exports++;
return 0;
@@ -2047,10 +2043,9 @@ struct_unpack_single(const char *ptr, struct unpacker *x)
return NULL;
if (PyTuple_GET_SIZE(v) == 1) {
- PyObject *tmp = PyTuple_GET_ITEM(v, 0);
- Py_INCREF(tmp);
+ PyObject *res = Py_NewRef(PyTuple_GET_ITEM(v, 0));
Py_DECREF(v);
- return tmp;
+ return res;
}
return v;
@@ -2496,8 +2491,7 @@ memory_subscript(PyMemoryViewObject *self, PyObject *key)
return unpack_single(self, view->buf, fmt);
}
else if (key == Py_Ellipsis) {
- Py_INCREF(self);
- return (PyObject *)self;
+ return Py_NewRef(self);
}
else {
PyErr_SetString(PyExc_TypeError,
@@ -2957,8 +2951,7 @@ result:
unpacker_free(unpack_v);
unpacker_free(unpack_w);
- Py_XINCREF(res);
- return res;
+ return Py_XNewRef(res);
}
/**************************************************************************/
@@ -3052,8 +3045,7 @@ memory_obj_get(PyMemoryViewObject *self, void *Py_UNUSED(ignored))
if (view->obj == NULL) {
Py_RETURN_NONE;
}
- Py_INCREF(view->obj);
- return view->obj;
+ return Py_NewRef(view->obj);
}
static PyObject *
@@ -3281,8 +3273,7 @@ memory_iter(PyObject *seq)
it->it_fmt = fmt;
it->it_length = memory_length(obj);
it->it_index = 0;
- Py_INCREF(seq);
- it->it_seq = obj;
+ it->it_seq = (PyMemoryViewObject*)Py_NewRef(obj);
_PyObject_GC_TRACK(it);
return (PyObject *)it;
}