From 76208054808964567c0ceecadaf75089045aec15 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sat, 7 Jun 2025 11:03:32 +0200 Subject: [PATCH] [3.13] gh-134160: Use PyModuleDef.m_free in the example module xxlimited (GH-135174) (GH-135214) gh-134160: Use PyModuleDef.m_free in the example module xxlimited (GH-135174) (cherry picked from commit 1adca08d658ee2d520f3193960eaf3ae2ead1cef) Co-authored-by: Petr Viktorin Co-authored-by: neonene <53406459+neonene@users.noreply.github.com> --- Modules/xxlimited.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Modules/xxlimited.c b/Modules/xxlimited.c index d86741e1dfc1..b29cd84d0b46 100644 --- a/Modules/xxlimited.c +++ b/Modules/xxlimited.c @@ -417,6 +417,13 @@ xx_clear(PyObject *module) return 0; } +static void +xx_free(void *module) +{ + // allow xx_modexec to omit calling xx_clear on error + (void)xx_clear((PyObject *)module); +} + static struct PyModuleDef xxmodule = { PyModuleDef_HEAD_INIT, .m_name = "xxlimited", @@ -426,9 +433,7 @@ static struct PyModuleDef xxmodule = { .m_slots = xx_slots, .m_traverse = xx_traverse, .m_clear = xx_clear, - /* m_free is not necessary here: xx_clear clears all references, - * and the module state is deallocated along with the module. - */ + .m_free = xx_free, }; -- 2.47.3