diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-05-31 21:34:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-31 21:34:21 (GMT) |
commit | 8b516668f2fea6d55edbd7054e27391cfd574d86 (patch) | |
tree | ae93e0648d4261885ca5adb633012a900f03bdd1 /Modules | |
parent | f87c6d189418850ac9c2e5f9cb08531cf004f704 (diff) | |
download | cpython-8b516668f2fea6d55edbd7054e27391cfd574d86.zip cpython-8b516668f2fea6d55edbd7054e27391cfd574d86.tar.gz cpython-8b516668f2fea6d55edbd7054e27391cfd574d86.tar.bz2 |
[3.12] gh-102251: Explicitly free state for test modules with state in test_import (GH-105085) (#105170)
(cherry picked from commit a99b9d911e0f8cb11b3436bdd8eb649b15d01a50)
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testsinglephase.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Modules/_testsinglephase.c b/Modules/_testsinglephase.c index 8e6973f..dca7abf 100644 --- a/Modules/_testsinglephase.c +++ b/Modules/_testsinglephase.c @@ -248,6 +248,25 @@ basic__clear_globals(PyObject *self, PyObject *Py_UNUSED(ignored)) basic__clear_globals_doc} +PyDoc_STRVAR(basic__clear_module_state_doc, "_clear_module_state()\n\ +\n\ +Free the module state and set it to uninitialized."); + +static PyObject * +basic__clear_module_state(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + module_state *state = get_module_state(self); + if (state != NULL) { + clear_state(state); + } + Py_RETURN_NONE; +} + +#define _CLEAR_MODULE_STATE_METHODDEF \ + {"_clear_module_state", basic__clear_module_state, METH_NOARGS, \ + basic__clear_module_state_doc} + + /*********************************************/ /* the _testsinglephase module (and aliases) */ /*********************************************/ @@ -408,7 +427,7 @@ finally: /* the _testsinglephase_with_state module */ /******************************************/ -/* This ia less typical of legacy extensions in the wild: +/* This is less typical of legacy extensions in the wild: - single-phase init (same as _testsinglephase above) - has some module state - supports repeated initialization @@ -424,6 +443,7 @@ static PyMethodDef TestMethods_WithState[] = { LOOK_UP_SELF_METHODDEF, SUM_METHODDEF, STATE_INITIALIZED_METHODDEF, + _CLEAR_MODULE_STATE_METHODDEF, {NULL, NULL} /* sentinel */ }; |