diff --git a/Python/pystate.c b/Python/pystate.c --- a/Python/pystate.c +++ b/Python/pystate.c @@ -280,24 +280,26 @@ PyState_FindModule(struct PyModuleDef* m res = PyList_GET_ITEM(state->modules_by_index, index); return res==Py_None ? NULL : res; } int _PyState_AddModule(PyObject* module, struct PyModuleDef* def) { PyInterpreterState *state; + if (!def) { + assert(PyErr_Occurred()); + return -1; + } if (def->m_slots) { PyErr_SetString(PyExc_SystemError, "PyState_AddModule called on module with slots"); return -1; } state = GET_INTERP_STATE(); - if (!def) - return -1; if (!state->modules_by_index) { state->modules_by_index = PyList_New(0); if (!state->modules_by_index) return -1; } while(PyList_GET_SIZE(state->modules_by_index) <= def->m_base.m_index) if (PyList_Append(state->modules_by_index, Py_None) < 0) return -1;