]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-134160: Use PyModuleDef.m_free in the example module xxlimited (GH-135174)
authorPetr Viktorin <encukou@gmail.com>
Fri, 6 Jun 2025 14:08:58 +0000 (16:08 +0200)
committerGitHub <noreply@github.com>
Fri, 6 Jun 2025 14:08:58 +0000 (14:08 +0000)
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
Modules/xxlimited.c

index 26ac35734fb0604bffe4ccae84c08afe78626ee6..0480fb0849876b023ff9e38682a4215532419c1e 100644 (file)
@@ -424,6 +424,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",
@@ -433,9 +440,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,
 };