diff options
author | Victor Stinner <vstinner@python.org> | 2020-04-07 16:36:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-07 16:36:04 (GMT) |
commit | 9cc3ebd7e04cb645ac7b2f372eaafa7464e16b9c (patch) | |
tree | 6567a7cfc6b9b42168698121df78e77d82d6e5f0 /Modules | |
parent | d8acf0d9aae71d1897e8f91989bd8bfb4a9ef9c6 (diff) | |
download | cpython-9cc3ebd7e04cb645ac7b2f372eaafa7464e16b9c.zip cpython-9cc3ebd7e04cb645ac7b2f372eaafa7464e16b9c.tar.gz cpython-9cc3ebd7e04cb645ac7b2f372eaafa7464e16b9c.tar.bz2 |
bpo-40149: Implement traverse in _abc._abc_data (GH-19412)
Implement traverse and clear slots in _abc._abc_data type.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_abc.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/Modules/_abc.c b/Modules/_abc.c index 6270982..1efc98b 100644 --- a/Modules/_abc.c +++ b/Modules/_abc.c @@ -51,13 +51,29 @@ typedef struct { unsigned long long _abc_negative_cache_version; } _abc_data; +static int +abc_data_traverse(_abc_data *self, visitproc visit, void *arg) +{ + Py_VISIT(self->_abc_registry); + Py_VISIT(self->_abc_cache); + Py_VISIT(self->_abc_negative_cache); + return 0; +} + +static int +abc_data_clear(_abc_data *self) +{ + Py_CLEAR(self->_abc_registry); + Py_CLEAR(self->_abc_cache); + Py_CLEAR(self->_abc_negative_cache); + return 0; +} + static void abc_data_dealloc(_abc_data *self) { PyTypeObject *tp = Py_TYPE(self); - Py_XDECREF(self->_abc_registry); - Py_XDECREF(self->_abc_cache); - Py_XDECREF(self->_abc_negative_cache); + (void)abc_data_clear(self); tp->tp_free(self); Py_DECREF(tp); } @@ -84,13 +100,15 @@ static PyType_Slot _abc_data_type_spec_slots[] = { {Py_tp_doc, (void *)abc_data_doc}, {Py_tp_new, abc_data_new}, {Py_tp_dealloc, abc_data_dealloc}, + {Py_tp_traverse, abc_data_traverse}, + {Py_tp_clear, abc_data_clear}, {0, 0} }; static PyType_Spec _abc_data_type_spec = { .name = "_abc._abc_data", .basicsize = sizeof(_abc_data), - .flags = Py_TPFLAGS_DEFAULT, + .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, .slots = _abc_data_type_spec_slots, }; |