summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-07-25 21:30:53 (GMT)
committerGitHub <noreply@github.com>2022-07-25 21:30:53 (GMT)
commit27055d766ab0ee5ddcfbd1fb51fb47419af1ddba (patch)
tree0e9f2ca9f0a8eac1e354e357aa7cee4581578e1e /Objects/dictobject.c
parent2d26449b06f310d72eb7df58a7133a16d47d30ed (diff)
downloadcpython-27055d766ab0ee5ddcfbd1fb51fb47419af1ddba.zip
cpython-27055d766ab0ee5ddcfbd1fb51fb47419af1ddba.tar.gz
cpython-27055d766ab0ee5ddcfbd1fb51fb47419af1ddba.tar.bz2
GH-92678: Expose managed dict clear and visit functions (#95246)
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c29
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)
{