mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
1960eb005e
commit
3a1dde8f29
13 changed files with 66 additions and 128 deletions
|
@ -311,8 +311,7 @@ weakref___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
if (callback == NULL && type == &_PyWeakref_RefType) {
|
||||
if (ref != NULL) {
|
||||
/* We can re-use an existing reference. */
|
||||
Py_INCREF(ref);
|
||||
return (PyObject *)ref;
|
||||
return Py_NewRef(ref);
|
||||
}
|
||||
}
|
||||
/* We have to create a new reference. */
|
||||
|
@ -826,8 +825,7 @@ PyWeakref_NewRef(PyObject *ob, PyObject *callback)
|
|||
to avoid violating the invariants of the list
|
||||
of weakrefs for ob. */
|
||||
Py_DECREF(result);
|
||||
Py_INCREF(ref);
|
||||
result = ref;
|
||||
result = (PyWeakReference*)Py_NewRef(ref);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -891,8 +889,7 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
|
|||
to avoid violating the invariants of the list
|
||||
of weakrefs for ob. */
|
||||
Py_DECREF(result);
|
||||
result = proxy;
|
||||
Py_INCREF(result);
|
||||
result = (PyWeakReference*)Py_NewRef(proxy);
|
||||
goto skip_insert;
|
||||
}
|
||||
prev = ref;
|
||||
|
@ -993,8 +990,7 @@ PyObject_ClearWeakRefs(PyObject *object)
|
|||
PyWeakReference *next = current->wr_next;
|
||||
|
||||
if (Py_REFCNT((PyObject *)current) > 0) {
|
||||
Py_INCREF(current);
|
||||
PyTuple_SET_ITEM(tuple, i * 2, (PyObject *) current);
|
||||
PyTuple_SET_ITEM(tuple, i * 2, Py_NewRef(current));
|
||||
PyTuple_SET_ITEM(tuple, i * 2 + 1, current->wr_callback);
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue