mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
PEP 489: Multi-phase extension module initialization
Known limitations of the current implementation: - documentation changes are incomplete - there's a reference leak I haven't tracked down yet The leak is most visible by running: ./python -m test -R3:3 test_importlib However, you can also see it by running: ./python -X showrefcount Importing the array or _testmultiphase modules, and then deleting them from both sys.modules and the local namespace shows significant increases in the total number of active references each cycle. By contrast, with _testcapi (which continues to use single-phase initialisation) the global refcounts stabilise after a couple of cycles.
This commit is contained in:
parent
ec219ba1c0
commit
d5cacbb1d9
34 changed files with 4462 additions and 3124 deletions
|
@ -255,6 +255,9 @@ PyState_FindModule(struct PyModuleDef* module)
|
|||
Py_ssize_t index = module->m_base.m_index;
|
||||
PyInterpreterState *state = PyThreadState_GET()->interp;
|
||||
PyObject *res;
|
||||
if (module->m_slots) {
|
||||
return NULL;
|
||||
}
|
||||
if (index == 0)
|
||||
return NULL;
|
||||
if (state->modules_by_index == NULL)
|
||||
|
@ -268,7 +271,13 @@ PyState_FindModule(struct PyModuleDef* module)
|
|||
int
|
||||
_PyState_AddModule(PyObject* module, struct PyModuleDef* def)
|
||||
{
|
||||
PyInterpreterState *state = PyThreadState_GET()->interp;
|
||||
PyInterpreterState *state;
|
||||
if (def->m_slots) {
|
||||
PyErr_SetString(PyExc_SystemError,
|
||||
"PyState_AddModule called on module with slots");
|
||||
return -1;
|
||||
}
|
||||
state = PyThreadState_GET()->interp;
|
||||
if (!def)
|
||||
return -1;
|
||||
if (!state->modules_by_index) {
|
||||
|
@ -308,8 +317,14 @@ PyState_AddModule(PyObject* module, struct PyModuleDef* def)
|
|||
int
|
||||
PyState_RemoveModule(struct PyModuleDef* def)
|
||||
{
|
||||
PyInterpreterState *state;
|
||||
Py_ssize_t index = def->m_base.m_index;
|
||||
PyInterpreterState *state = PyThreadState_GET()->interp;
|
||||
if (def->m_slots) {
|
||||
PyErr_SetString(PyExc_SystemError,
|
||||
"PyState_RemoveModule called on module with slots");
|
||||
return -1;
|
||||
}
|
||||
state = PyThreadState_GET()->interp;
|
||||
if (index == 0) {
|
||||
Py_FatalError("PyState_RemoveModule: Module index invalid.");
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue