summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2024-05-27 19:35:30 (GMT)
committerGitHub <noreply@github.com>2024-05-27 19:35:30 (GMT)
commitae7b17673f29efe17b416cbcfbf43b5b3ff5977c (patch)
tree67d022f5a1d5b2df3c3721914c340433a79cce7d /Python/import.c
parent0bd0d4072a49df49a88e8b02c3258dbd294170f6 (diff)
downloadcpython-ae7b17673f29efe17b416cbcfbf43b5b3ff5977c.zip
cpython-ae7b17673f29efe17b416cbcfbf43b5b3ff5977c.tar.gz
cpython-ae7b17673f29efe17b416cbcfbf43b5b3ff5977c.tar.bz2
gh-119584: Fix test_import Failed Assertion (gh-119623)
The fix in gh-119561 introduced an assertion that doesn't hold true if any of the three new test extension modules are loaded more than once. This is fine normally but breaks if the new test_check_state_first() is run more than once, which happens for refleak checking and with the regrtest --forever flag. We fix that here by clearing each of the three modules after loading them. We also tweak a check in _modules_by_index_check().
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/Python/import.c b/Python/import.c
index 4f3325a..6fe6df4 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -494,7 +494,7 @@ _modules_by_index_check(PyInterpreterState *interp, Py_ssize_t index)
if (MODULES_BY_INDEX(interp) == NULL) {
return "Interpreters module-list not accessible.";
}
- if (index > PyList_GET_SIZE(MODULES_BY_INDEX(interp))) {
+ if (index >= PyList_GET_SIZE(MODULES_BY_INDEX(interp))) {
return "Module index out of bounds.";
}
return NULL;
@@ -2183,7 +2183,7 @@ clear_singlephase_extension(PyInterpreterState *interp,
/* Clear data set when the module was initially loaded. */
def->m_base.m_init = NULL;
Py_CLEAR(def->m_base.m_copy);
- // We leave m_index alone since there's no reason to reset it.
+ def->m_base.m_index = 0;
/* Clear the PyState_*Module() cache entry. */
Py_ssize_t index = _get_cached_module_index(cached);