[3.13] gh-118789: Add PyUnstable_Object_ClearWeakRefsNoCallbacks
(GH-118807)
#120695
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This exposes
PyUnstable_Object_ClearWeakRefsNoCallbacks
as an unstableC-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, butthat's not thread-safe in the free-threaded build.
(cherry picked from commit e8752d7)
Co-authored-by: Sam Gross colesbury@gmail.com
Co-authored-by: Petr Viktorin encukou@gmail.com
_PyWeakref_ClearRef
and_PyWeakref_ClearWeakRefsExceptCallbacks
should be exposed in 3.13 #118789📚 Documentation preview 📚: https://cpython-previews--120695.org.readthedocs.build/