gh-119560: Drop an Invalid Assert in PyState_FindModule() (gh-119561)

The assertion was added in gh-118532 but was based on the invalid assumption that PyState_FindModule() would only be called with an already-initialized module def.  I've added a test to make sure we don't make that assumption again.
This commit is contained in:
Eric Snow 2024-05-25 15:30:48 -04:00 committed by GitHub
parent 4b7eb321bc
commit 0c5ebe13e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 100 additions and 4 deletions

View file

@ -457,7 +457,6 @@ static Py_ssize_t
_get_module_index_from_def(PyModuleDef *def)
{
Py_ssize_t index = def->m_base.m_index;
assert(index > 0);
#ifndef NDEBUG
struct extensions_cache_value *cached = _find_cached_def(def);
assert(cached == NULL || index == _get_cached_module_index(cached));
@ -489,7 +488,7 @@ _set_module_index(PyModuleDef *def, Py_ssize_t index)
static const char *
_modules_by_index_check(PyInterpreterState *interp, Py_ssize_t index)
{
if (index == 0) {
if (index <= 0) {
return "invalid module index";
}
if (MODULES_BY_INDEX(interp) == NULL) {