Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow GIL to be disabled in whirlpool C extension #1344

Merged
Merged
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
46 changes: 29 additions & 17 deletions src/portage_util__whirlpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,30 +1112,42 @@ static PyTypeObject WhirlpoolType = {
.tp_methods = Whirlpool_methods,
};

static int
whirlpool_exec(PyObject *mod)
{
if (PyType_Ready(&WhirlpoolType) < 0)
return -1;

Py_INCREF(&WhirlpoolType);
if (PyModule_AddObject(mod, "Whirlpool", (PyObject *) &WhirlpoolType) < 0) {
zmedico marked this conversation as resolved.
Show resolved Hide resolved
Py_DECREF(&WhirlpoolType);
return -1;
}

return 0;
}

static PyModuleDef_Slot _whirlpoolmodule_slots[] = {
{Py_mod_exec, whirlpool_exec},
#ifdef Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
#endif
#ifdef Py_MOD_GIL_NOT_USED
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
#endif
{0, NULL},
};

static PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
.m_name = "_whirlpool",
.m_doc = "Reference Whirlpool implementation",
.m_size = -1,
.m_size = 0,
.m_slots = _whirlpoolmodule_slots,
};

PyMODINIT_FUNC
PyInit__whirlpool(void)
{
PyObject *m;
if (PyType_Ready(&WhirlpoolType) < 0)
return NULL;

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

Py_INCREF(&WhirlpoolType);
if (PyModule_AddObject(m, "Whirlpool", (PyObject *) &WhirlpoolType) < 0) {
Py_DECREF(&WhirlpoolType);
Py_DECREF(m);
return NULL;
}

return m;
return PyModuleDef_Init(&moduledef);
}