8000 gh-111926: Simplify weakref/proxy creation by mpage · Pull Request #116825 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111926: Simplify weakref/proxy creation #116825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions Objects/weakrefobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,24 +801,14 @@ PyWeakref_NewRef(PyObject *ob, PyObject *callback)
if (result != NULL)
Py_INCREF(result);
else {
/* Note: new_weakref() can trigger cyclic GC, so the weakref
list on ob can be mutated. This means that the ref and
proxy pointers we got back earlier may have been collected,
so we need to compute these values again before we use
them. */
/* We do not need to recompute ref/proxy; new_weakref() cannot
trigger GC.
6861 */
result = new_weakref(ob, callback);
if (result != NULL) {
get_basic_refs(*list, &ref, &proxy);
if (callback == NULL) {
if (ref == NULL)
insert_head(result, list);
else {
/* Someone else added a ref without a callback
during GC. Return that one instead of this one
to avoid violating the invariants of the list
of weakrefs for ob. */
Py_SETREF(result, (PyWeakReference*)Py_NewRef(ref));
}
}
else {
PyWeakReference *prev;
Expand Down
0