Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port _collections extension module to multiphase initialization (:pep:`489`).
69 changes: 37 additions & 32 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2518,55 +2518,60 @@ static struct PyMethodDef module_functions[] = {
{NULL, NULL} /* sentinel */
};

static struct PyModuleDef _collectionsmodule = {
PyModuleDef_HEAD_INIT,
"_collections",
module_doc,
-1,
module_functions,
NULL,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC
PyInit__collections(void)
static int
_collections_exec(PyObject *module)
{
PyObject *m;

m = PyModule_Create(&_collectionsmodule);
if (m == NULL)
return NULL;

if (PyType_Ready(&deque_type) < 0)
return NULL;
return -1;
Py_INCREF(&deque_type);
PyModule_AddObject(m, "deque", (PyObject *)&deque_type);
PyModule_AddObject(module, "deque", (PyObject *)&deque_type);

defdict_type.tp_base = &PyDict_Type;
if (PyType_Ready(&defdict_type) < 0)
return NULL;
return -1;
Py_INCREF(&defdict_type);
PyModule_AddObject(m, "defaultdict", (PyObject *)&defdict_type);
PyModule_AddObject(module, "defaultdict", (PyObject *)&defdict_type);

Py_INCREF(&PyODict_Type);
PyModule_AddObject(m, "OrderedDict", (PyObject *)&PyODict_Type);
PyModule_AddObject(module, "OrderedDict", (PyObject *)&PyODict_Type);

if (PyType_Ready(&dequeiter_type) < 0)
return NULL;
return -1;
Py_INCREF(&dequeiter_type);
PyModule_AddObject(m, "_deque_iterator", (PyObject *)&dequeiter_type);
PyModule_AddObject(module, "_deque_iterator", (PyObject *)&dequeiter_type);

if (PyType_Ready(&dequereviter_type) < 0)
return NULL;
return -1;
Py_INCREF(&dequereviter_type);
PyModule_AddObject(m, "_deque_reverse_iterator", (PyObject *)&dequereviter_type);
PyModule_AddObject(module, "_deque_reverse_iterator", (PyObject *)&dequereviter_type);

if (PyType_Ready(&tuplegetter_type) < 0)
return NULL;
return -1;
Py_INCREF(&tuplegetter_type);
PyModule_AddObject(m, "_tuplegetter", (PyObject *)&tuplegetter_type);
PyModule_AddObject(module, "_tuplegetter", (PyObject *)&tuplegetter_type);

return 0;
}

static PyModuleDef_Slot _collections_slots[] = {
{Py_mod_exec, _collections_exec},
{0, NULL}
};

return m;
static struct PyModuleDef _collectionsmodule = {
PyModuleDef_HEAD_INIT,
"_collections",
module_doc,
0,
module_functions,
_collections_slots,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC
PyInit__collections(void)
{
return PyModuleDef_Init(&_collectionsmodule);
}