mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-99300: Replace Py_INCREF() with Py_NewRef() (#99513)
Replace Py_INCREF() and Py_XINCREF() using a cast with Py_NewRef() and Py_XNewRef().
This commit is contained in:
parent
ea88d34de2
commit
3ed8803ef5
12 changed files with 22 additions and 44 deletions
|
@ -1756,8 +1756,7 @@ future_new_iter(PyObject *fut)
|
|||
}
|
||||
}
|
||||
|
||||
Py_INCREF(fut);
|
||||
it->future = (FutureObj*)fut;
|
||||
it->future = (FutureObj*)Py_NewRef(fut);
|
||||
PyObject_GC_Track(it);
|
||||
return (PyObject*)it;
|
||||
}
|
||||
|
@ -1821,8 +1820,7 @@ static PyObject *
|
|||
TaskStepMethWrapper_get___self__(TaskStepMethWrapper *o, void *Py_UNUSED(ignored))
|
||||
{
|
||||
if (o->sw_task) {
|
||||
Py_INCREF(o->sw_task);
|
||||
return (PyObject*)o->sw_task;
|
||||
return Py_NewRef(o->sw_task);
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
|
|
@ -2937,8 +2937,7 @@ PyCData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr)
|
|||
assert(CDataObject_Check(base));
|
||||
cmem->b_ptr = adr;
|
||||
cmem->b_needsfree = 0;
|
||||
Py_INCREF(base);
|
||||
cmem->b_base = (CDataObject *)base;
|
||||
cmem->b_base = (CDataObject *)Py_NewRef(base);
|
||||
cmem->b_index = index;
|
||||
} else { /* copy contents of adr */
|
||||
if (-1 == PyCData_MallocBuffer(cmem, dict)) {
|
||||
|
|
|
@ -230,8 +230,7 @@ PyCField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type)
|
|||
{
|
||||
CDataObject *src;
|
||||
if (inst == NULL) {
|
||||
Py_INCREF(self);
|
||||
return (PyObject *)self;
|
||||
return Py_NewRef(self);
|
||||
}
|
||||
if (!CDataObject_Check(inst)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
|
|
|
@ -933,8 +933,7 @@ _elementtree_Element___getstate___impl(ElementObject *self)
|
|||
if (!children)
|
||||
return NULL;
|
||||
for (i = 0; i < PyList_GET_SIZE(children); i++) {
|
||||
PyObject *child = self->extra->children[i];
|
||||
Py_INCREF(child);
|
||||
PyObject *child = Py_NewRef(self->extra->children[i]);
|
||||
PyList_SET_ITEM(children, i, child);
|
||||
}
|
||||
|
||||
|
@ -1365,8 +1364,7 @@ _elementtree_Element_get_impl(ElementObject *self, PyObject *key,
|
|||
/*[clinic end generated code: output=523c614142595d75 input=ee153bbf8cdb246e]*/
|
||||
{
|
||||
if (self->extra && self->extra->attrib) {
|
||||
PyObject *attrib = self->extra->attrib;
|
||||
Py_INCREF(attrib);
|
||||
PyObject *attrib = Py_NewRef(self->extra->attrib);
|
||||
PyObject *value = PyDict_GetItemWithError(attrib, key);
|
||||
Py_XINCREF(value);
|
||||
Py_DECREF(attrib);
|
||||
|
@ -1723,8 +1721,7 @@ element_subscr(PyObject* self_, PyObject* item)
|
|||
|
||||
for (cur = start, i = 0; i < slicelen;
|
||||
cur += step, i++) {
|
||||
PyObject* item = self->extra->children[cur];
|
||||
Py_INCREF(item);
|
||||
PyObject* item = Py_NewRef(self->extra->children[cur]);
|
||||
PyList_SET_ITEM(list, i, item);
|
||||
}
|
||||
|
||||
|
@ -2761,8 +2758,7 @@ treebuilder_handle_end(TreeBuilderObject* self, PyObject* tag)
|
|||
if (treebuilder_append_event(self, self->end_event_obj, self->last) < 0)
|
||||
return NULL;
|
||||
|
||||
Py_INCREF(self->last);
|
||||
return (PyObject*) self->last;
|
||||
return Py_NewRef(self->last);
|
||||
}
|
||||
|
||||
LOCAL(PyObject*)
|
||||
|
|
|
@ -1787,8 +1787,7 @@ ndarray_subscript(NDArrayObject *self, PyObject *key)
|
|||
return unpack_single(base->buf, base->format, base->itemsize);
|
||||
}
|
||||
else if (key == Py_Ellipsis) {
|
||||
Py_INCREF(self);
|
||||
return (PyObject *)self;
|
||||
return Py_NewRef(self);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError, "invalid indexing of scalar");
|
||||
|
|
|
@ -137,11 +137,9 @@ get_timezone_utc_capi(PyObject *self, PyObject *args)
|
|||
return NULL;
|
||||
}
|
||||
if (macro) {
|
||||
Py_INCREF(PyDateTime_TimeZone_UTC);
|
||||
return PyDateTime_TimeZone_UTC;
|
||||
return Py_NewRef(PyDateTime_TimeZone_UTC);
|
||||
}
|
||||
Py_INCREF(PyDateTimeAPI->TimeZone_UTC);
|
||||
return PyDateTimeAPI->TimeZone_UTC;
|
||||
return Py_NewRef(PyDateTimeAPI->TimeZone_UTC);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
|
@ -746,8 +746,7 @@ mmap__enter__method(mmap_object *self, PyObject *args)
|
|||
{
|
||||
CHECK_VALID(NULL);
|
||||
|
||||
Py_INCREF(self);
|
||||
return (PyObject *)self;
|
||||
return Py_NewRef(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
|
@ -1652,8 +1652,7 @@ select_epoll___enter___impl(pyEpoll_Object *self)
|
|||
if (self->epfd < 0)
|
||||
return pyepoll_err_closed();
|
||||
|
||||
Py_INCREF(self);
|
||||
return (PyObject *)self;
|
||||
return Py_NewRef(self);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
|
|
@ -205,8 +205,7 @@ syslog_syslog_impl(PyObject *module, int group_left_1, int priority,
|
|||
/* Incref ident, because it can be decrefed if syslog.openlog() is
|
||||
* called when the GIL is released.
|
||||
*/
|
||||
PyObject *ident = S_ident_o;
|
||||
Py_XINCREF(ident);
|
||||
PyObject *ident = Py_XNewRef(S_ident_o);
|
||||
#ifdef __APPLE__
|
||||
// gh-98178: On macOS, libc syslog() is not thread-safe
|
||||
syslog(priority, "%s", message);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue