diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-07-25 22:05:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-25 22:05:27 (GMT) |
commit | 7f731943393d57cf26ed5f2353e6e53084cd55fd (patch) | |
tree | c8c8abdbf76cf74188d0dd7f7c775660007826c7 /Objects/dictobject.c | |
parent | 4c10dbab4e677a2aa2e37211d418293a542c3bc4 (diff) | |
download | cpython-7f731943393d57cf26ed5f2353e6e53084cd55fd.zip cpython-7f731943393d57cf26ed5f2353e6e53084cd55fd.tar.gz cpython-7f731943393d57cf26ed5f2353e6e53084cd55fd.tar.bz2 |
[3.11] GH-92678: Expose managed dict clear and visit functions (GH-95246). (#95256)
Co-authored-by: Mark Shannon <mark@hotpy.org>
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index ebbd22e..25e191f 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -5583,6 +5583,35 @@ _PyObject_FreeInstanceAttributes(PyObject *self) free_values(*values_ptr); } +int +_PyObject_VisitManagedDict(PyObject *self, visitproc visit, void *arg) +{ + PyTypeObject *tp = Py_TYPE(self); + if((tp->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0) { + return 0; + } + assert(tp->tp_dictoffset); + int err = _PyObject_VisitInstanceAttributes(self, visit, arg); + if (err) { + return err; + } + Py_VISIT(*_PyObject_ManagedDictPointer(self)); + return 0; +} + + +void +_PyObject_ClearManagedDict(PyObject *self) +{ + PyTypeObject *tp = Py_TYPE(self); + if((tp->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0) { + return; + } + _PyObject_FreeInstanceAttributes(self); + *_PyObject_ValuesPointer(self) = NULL; + Py_CLEAR(*_PyObject_ManagedDictPointer(self)); +} + PyObject * PyObject_GenericGetDict(PyObject *obj, void *context) { |