#include "Python.h" #include "pycore_dict.h" // _PyDict_DelItemIf() #include "pycore_object.h" // _PyObject_GET_WEAKREFS_LISTPTR() #include "pycore_weakref.h" // _PyWeakref_IS_DEAD() #define GET_WEAKREFS_LISTPTR(o) … /*[clinic input] module _weakref [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=ffec73b85846596d]*/ #include "clinic/_weakref.c.h" /*[clinic input] _weakref.getweakrefcount -> Py_ssize_t object: object / Return the number of weak references to 'object'. [clinic start generated code]*/ static Py_ssize_t _weakref_getweakrefcount_impl(PyObject *module, PyObject *object) /*[clinic end generated code: output=301806d59558ff3e input=7d4d04fcaccf64d5]*/ { … } static int is_dead_weakref(PyObject *value, void *unused) { … } /*[clinic input] _weakref._remove_dead_weakref -> object dct: object(subclass_of='&PyDict_Type') key: object / Atomically remove key from dict if it points to a dead weakref. [clinic start generated code]*/ static PyObject * _weakref__remove_dead_weakref_impl(PyObject *module, PyObject *dct, PyObject *key) /*[clinic end generated code: output=d9ff53061fcb875c input=19fc91f257f96a1d]*/ { … } /*[clinic input] _weakref.getweakrefs object: object / Return a list of all weak reference objects pointing to 'object'. [clinic start generated code]*/ static PyObject * _weakref_getweakrefs(PyObject *module, PyObject *object) /*[clinic end generated code: output=25c7731d8e011824 input=00c6d0e5d3206693]*/ { … } /*[clinic input] _weakref.proxy object: object callback: object(c_default="NULL") = None / Create a proxy object that weakly references 'object'. 'callback', if given, is called with a reference to the proxy when 'object' is about to be finalized. [clinic start generated code]*/ static PyObject * _weakref_proxy_impl(PyObject *module, PyObject *object, PyObject *callback) /*[clinic end generated code: output=d68fa4ad9ea40519 input=4808adf22fd137e7]*/ { … } static PyMethodDef weakref_functions[] = …; static int weakref_exec(PyObject *module) { … } static struct PyModuleDef_Slot weakref_slots[] = …; static struct PyModuleDef weakrefmodule = …; PyMODINIT_FUNC PyInit__weakref(void) { … }