From 2daed5f7a7087c63f47c57554ff55ee947e7a53d Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Wed, 4 Sep 2024 07:43:50 -0400 Subject: gh-123504: Fix regression in `_tkinter` initializer (#123662) * Add module traverse function to _tkinter. * Set m_size to -1 (instead of 0). --- Modules/_tkinter.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index e1e8108..4f05cab 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -3390,7 +3390,7 @@ DisableEventHook(void) } static int -module_clear(PyObject *mod) +module_clear(PyObject *Py_UNUSED(mod)) { Py_CLEAR(Tkinter_TclError); Py_CLEAR(Tkapp_Type); @@ -3399,16 +3399,28 @@ module_clear(PyObject *mod) return 0; } +static int +module_traverse(PyObject *Py_UNUSED(module), visitproc visit, void *arg) +{ + Py_VISIT(Tkinter_TclError); + Py_VISIT(Tkapp_Type); + Py_VISIT(Tktt_Type); + Py_VISIT(PyTclObject_Type); + return 0; +} + static void module_free(void *mod) { - module_clear((PyObject *)mod); + (void)module_clear((PyObject *)mod); } static struct PyModuleDef _tkintermodule = { PyModuleDef_HEAD_INIT, .m_name = "_tkinter", + .m_size = -1, .m_methods = moduleMethods, + .m_traverse = module_traverse, .m_clear = module_clear, .m_free = module_free }; -- cgit v0.12