Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 :mod:`multiprocessing` to multi-phase initialization
57 changes: 28 additions & 29 deletions Modules/_multiprocessing/multiprocessing.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,34 +139,15 @@ static PyMethodDef module_methods[] = {
* Initialize
*/

static struct PyModuleDef multiprocessing_module = {
PyModuleDef_HEAD_INIT,
"_multiprocessing",
NULL,
-1,
module_methods,
NULL,
NULL,
NULL,
NULL
};


PyMODINIT_FUNC
PyInit__multiprocessing(void)
static int multiprocessing_exec(PyObject *module)
{
PyObject *module, *temp, *value = NULL;

/* Initialize module */
module = PyModule_Create(&multiprocessing_module);
if (!module)
return NULL;
PyObject *value = NULL;

#if defined(MS_WINDOWS) || \
(defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED))
/* Add _PyMp_SemLock type to module */
if (PyType_Ready(&_PyMp_SemLockType) < 0)
return NULL;
return -1;
Py_INCREF(&_PyMp_SemLockType);
{
PyObject *py_sem_value_max;
Expand All @@ -180,23 +161,23 @@ PyInit__multiprocessing(void)
else
py_sem_value_max = PyLong_FromLong(SEM_VALUE_MAX);
if (py_sem_value_max == NULL)
return NULL;
return -1;
PyDict_SetItemString(_PyMp_SemLockType.tp_dict, "SEM_VALUE_MAX",
py_sem_value_max);
}
PyModule_AddObject(module, "SemLock", (PyObject*)&_PyMp_SemLockType);
#endif

/* Add configuration macros */
temp = PyDict_New();
PyObject *temp = PyDict_New();
if (!temp)
return NULL;
return -1;

#define ADD_FLAG(name) \
value = Py_BuildValue("i", name); \
if (value == NULL) { Py_DECREF(temp); return NULL; } \
if (value == NULL) { Py_DECREF(temp); return -1; } \
if (PyDict_SetItemString(temp, #name, value) < 0) { \
Py_DECREF(temp); Py_DECREF(value); return NULL; } \
Py_DECREF(temp); Py_DECREF(value); return -1; } \
Py_DECREF(value)

#if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
Expand All @@ -213,7 +194,25 @@ PyInit__multiprocessing(void)
#endif

if (PyModule_AddObject(module, "flags", temp) < 0)
return NULL;
return -1;

return module;
return 0;
}

static PyModuleDef_Slot multiprocessing_slots[] = {
{Py_mod_exec, multiprocessing_exec},
{0, NULL}
};

static struct PyModuleDef multiprocessing_module = {
PyModuleDef_HEAD_INIT,
.m_name = "_multiprocessing",
.m_methods = module_methods,
.m_slots = multiprocessing_slots,
};

PyMODINIT_FUNC
PyInit__multiprocessing(void)
{
return PyModuleDef_Init(&multiprocessing_module);
}