diff options
| author | Victor Stinner <vstinner@python.org> | 2022-11-10 23:58:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-10 23:58:07 +0100 |
| commit | 3a1dde8f29215418ec4e27fd6234cfa19a5407c6 (patch) | |
| tree | 433d4efb6105ded7a5abcc0f96360731840b10aa /Objects/weakrefobject.c | |
| parent | 1960eb005e04b7ad8a91018088cfdb0646bc1ca0 (diff) | |
| download | cpython-git-3a1dde8f29215418ec4e27fd6234cfa19a5407c6.tar.gz | |
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/weakrefobject.c')
| -rw-r--r-- | Objects/weakrefobject.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index cf89a9231d..ff284c882b 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -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 { |
