gh-81057: Move the Extension Modules Cache to _PyRuntimeState (gh-99355)

We also move the closely related max_module_number and add comments documenting the group of struct members.

https://github.com/python/cpython/issues/81057
This commit is contained in:
Eric Snow 2022-11-11 14:16:28 -07:00 committed by GitHub
parent fe55ff3f68
commit dd36b71fa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 104 additions and 33 deletions

View file

@ -9,7 +9,6 @@
#include "pycore_moduleobject.h" // _PyModule_GetDef()
#include "structmember.h" // PyMemberDef
static Py_ssize_t max_module_number;
static PyMemberDef module_members[] = {
{"__dict__", T_OBJECT, offsetof(PyModuleObject, md_dict), READONLY},
@ -43,10 +42,10 @@ PyModuleDef_Init(PyModuleDef* def)
{
assert(PyModuleDef_Type.tp_flags & Py_TPFLAGS_READY);
if (def->m_base.m_index == 0) {
max_module_number++;
_PyRuntime.imports.last_module_index++;
Py_SET_REFCNT(def, 1);
Py_SET_TYPE(def, &PyModuleDef_Type);
def->m_base.m_index = max_module_number;
def->m_base.m_index = _PyRuntime.imports.last_module_index;
}
return (PyObject*)def;
}