Skip to content

Commit 1adca08

Browse files
encukouneonene
andauthored
gh-134160: Use PyModuleDef.m_free in the example module xxlimited (GH-135174)
Co-authored-by: neonene <[email protected]>
1 parent e413e26 commit 1adca08

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Modules/xxlimited.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,13 @@ xx_clear(PyObject *module)
424424
return 0;
425425
}
426426

427+
static void
428+
xx_free(void *module)
429+
{
430+
// allow xx_modexec to omit calling xx_clear on error
431+
(void)xx_clear((PyObject *)module);
432+
}
433+
427434
static struct PyModuleDef xxmodule = {
428435
PyModuleDef_HEAD_INIT,
429436
.m_name = "xxlimited",
@@ -433,9 +440,7 @@ static struct PyModuleDef xxmodule = {
433440
.m_slots = xx_slots,
434441
.m_traverse = xx_traverse,
435442
.m_clear = xx_clear,
436-
/* m_free is not necessary here: xx_clear clears all references,
437-
* and the module state is deallocated along with the module.
438-
*/
443+
.m_free = xx_free,
439444
};
440445

441446

0 commit comments

Comments
 (0)