summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2021-01-03 13:11:15 (GMT)
committerGitHub <noreply@github.com>2021-01-03 13:11:15 (GMT)
commitb8eb3765908c0063f0739595ba4b296cc8863d19 (patch)
tree9a01bfa1fdbbbfa123b434ce0f98889fef1c7564 /Modules
parent66136768615472a8d1a18b5018095b9737dbab8c (diff)
downloadcpython-b8eb3765908c0063f0739595ba4b296cc8863d19.zip
cpython-b8eb3765908c0063f0739595ba4b296cc8863d19.tar.gz
cpython-b8eb3765908c0063f0739595ba4b296cc8863d19.tar.bz2
bpo-40077: Add traverse/clear/free to arraymodule (GH-24066)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/arraymodule.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 12bd517..e7d5ab7 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -2977,18 +2977,42 @@ static PyType_Spec arrayiter_spec = {
/*********************** Install Module **************************/
+static int
+array_traverse(PyObject *module, visitproc visit, void *arg)
+{
+ array_state *state = get_array_state(module);
+ Py_VISIT(state->ArrayType);
+ Py_VISIT(state->ArrayIterType);
+ return 0;
+}
+
+static int
+array_clear(PyObject *module)
+{
+ array_state *state = get_array_state(module);
+ Py_CLEAR(state->ArrayType);
+ Py_CLEAR(state->ArrayIterType);
+ return 0;
+}
+
+static void
+array_free(void *module)
+{
+ array_clear((PyObject *)module);
+}
+
/* No functions in array module. */
static PyMethodDef a_methods[] = {
ARRAY__ARRAY_RECONSTRUCTOR_METHODDEF
{NULL, NULL, 0, NULL} /* Sentinel */
};
-#define CREATE_TYPE(module, type, spec) \
-do { \
- type = (PyTypeObject *)PyType_FromModuleAndSpec(m, spec, NULL); \
- if (type == NULL) { \
- return -1; \
- } \
+#define CREATE_TYPE(module, type, spec) \
+do { \
+ type = (PyTypeObject *)PyType_FromModuleAndSpec(module, spec, NULL); \
+ if (type == NULL) { \
+ return -1; \
+ } \
} while (0)
static int
@@ -3059,6 +3083,9 @@ static struct PyModuleDef arraymodule = {
.m_doc = module_doc,
.m_methods = a_methods,
.m_slots = arrayslots,
+ .m_traverse = array_traverse,
+ .m_clear = array_clear,
+ .m_free = array_free,
};