[3.14] gh-134160: Use PyModuleDef.m_free in the example module xxlimited (GH-135174) (GH-135213)

gh-134160: Use PyModuleDef.m_free in the example module xxlimited (GH-135174)
(cherry picked from commit 1adca08d65)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2025-06-06 17:08:45 +02:00 committed by GitHub
parent f32c7b9100
commit dd4a819a82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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,
};