-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-118789: Add PyUnstable_Object_ClearWeakRefsNoCallbacks
#118807
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
Changes from 1 commit
f1fc2bc
9330f51
dc28627
652c1c1
519a347
29582a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
PyUnstable_Weakref_ClearWeakRefsExceptCallbacks
This exposes `_PyWeakref_ClearWeakRefsExceptCallbacks` as an unstable C-API function to provide a thread-safe mechanism for clearing weakrefs without executing callbacks. Some C-API extensions need to clear weakrefs without calling callbacks, such as after running finalizers like we do in subtype_dealloc. Previously they could use `_PyWeakref_ClearRef` on each weakref, but that's not thread-safe in the free-threaded build.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -96,3 +96,10 @@ as much as it can. | |||
This iterates through the weak references for *object* and calls callbacks | ||||
for those references which have one. It returns when all callbacks have | ||||
been attempted. | ||||
|
||||
|
||||
.. c:function:: void PyUnstable_Weakref_ClearWeakRefsExceptCallbacks(PyObject *object) | ||||
|
||||
Clears the weakrefs for *object* without calling the callbacks. | ||||
|
||||
.. versionadded:: 3.13 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO it's too late for 3.13, we're past beta1.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yhg1s - is it okay to make this function public in 3.13? From our discussion on Discord in May, it sounded like you were okay with this before the RC, but I'd like to make sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, considering the circumstances, this is reasonable to add in beta 3. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add :c:func:`PyUnstable_Weakref_ClearWeakRefsExceptCallbacks`, which clears | ||
weakrefs without calling their callbacks. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1090,6 +1090,12 @@ _PyWeakref_ClearWeakRefsExceptCallbacks(PyObject *obj) | |
UNLOCK_WEAKREFS(obj); | ||
} | ||
|
||
void | ||
PyUnstable_Weakref_ClearWeakRefsExceptCallbacks(PyObject *obj) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to check if |
||
_PyWeakref_ClearWeakRefsExceptCallbacks(obj); | ||
} | ||
|
||
int | ||
_PyWeakref_IsDead(PyObject *weakref) | ||
{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.