mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
[3.13] gh-118789: Add PyUnstable_Object_ClearWeakRefsNoCallbacks (GH-118807) (#120695)
This exposes `PyUnstable_Object_ClearWeakRefsNoCallbacks` 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.
(cherry picked from commit e8752d7b80)
Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
parent
4f4973d740
commit
1ce5984961
8 changed files with 68 additions and 4 deletions
|
|
@ -117,11 +117,19 @@ pyobject_print_os_error(PyObject *self, PyObject *args)
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
pyobject_clear_weakrefs_no_callbacks(PyObject *self, PyObject *obj)
|
||||
{
|
||||
PyUnstable_Object_ClearWeakRefsNoCallbacks(obj);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef test_methods[] = {
|
||||
{"call_pyobject_print", call_pyobject_print, METH_VARARGS},
|
||||
{"pyobject_print_null", pyobject_print_null, METH_VARARGS},
|
||||
{"pyobject_print_noref_object", pyobject_print_noref_object, METH_VARARGS},
|
||||
{"pyobject_print_os_error", pyobject_print_os_error, METH_VARARGS},
|
||||
{"pyobject_clear_weakrefs_no_callbacks", pyobject_clear_weakrefs_no_callbacks, METH_O},
|
||||
|
||||
{NULL},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue