GH-94382: port multiprocessing static types to heap types (#94336)

This commit is contained in:
Kumar Aditya 2022-07-21 00:56:01 +05:30 committed by GitHub
parent 8ede67cdcf
commit 000a4eebe7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 64 deletions

View file

@ -196,33 +196,39 @@ multiprocessing_exec(PyObject *module)
{
#ifdef HAVE_MP_SEMAPHORE
/* Add _PyMp_SemLock type to module */
if (PyModule_AddType(module, &_PyMp_SemLockType) < 0) {
PyTypeObject *semlock_type = (PyTypeObject *)PyType_FromModuleAndSpec(
module, &_PyMp_SemLockType_spec, NULL);
if (semlock_type == NULL) {
return -1;
}
int rc = PyModule_AddType(module, semlock_type);
Py_DECREF(semlock_type);
if (rc < 0) {
return -1;
}
{
PyObject *py_sem_value_max;
/* Some systems define SEM_VALUE_MAX as an unsigned value that
* causes it to be negative when used as an int (NetBSD).
*
* Issue #28152: Use (0) instead of 0 to fix a warning on dead code
* when using clang -Wunreachable-code. */
if ((int)(SEM_VALUE_MAX) < (0))
py_sem_value_max = PyLong_FromLong(INT_MAX);
else
py_sem_value_max = PyLong_FromLong(SEM_VALUE_MAX);
if (py_sem_value_max == NULL) {
return -1;
}
if (PyDict_SetItemString(_PyMp_SemLockType.tp_dict, "SEM_VALUE_MAX",
py_sem_value_max) < 0) {
Py_DECREF(py_sem_value_max);
return -1;
}
Py_DECREF(py_sem_value_max);
PyObject *py_sem_value_max;
/* Some systems define SEM_VALUE_MAX as an unsigned value that
* causes it to be negative when used as an int (NetBSD).
*
* Issue #28152: Use (0) instead of 0 to fix a warning on dead code
* when using clang -Wunreachable-code. */
if ((int)(SEM_VALUE_MAX) < (0)) {
py_sem_value_max = PyLong_FromLong(INT_MAX);
}
else {
py_sem_value_max = PyLong_FromLong(SEM_VALUE_MAX);
}
if (py_sem_value_max == NULL) {
return -1;
}
if (PyDict_SetItemString(semlock_type->tp_dict, "SEM_VALUE_MAX",
py_sem_value_max) < 0) {
Py_DECREF(py_sem_value_max);
return -1;
}
Py_DECREF(py_sem_value_max);
#endif
@ -276,6 +282,7 @@ static PyModuleDef_Slot multiprocessing_slots[] = {
static struct PyModuleDef multiprocessing_module = {
PyModuleDef_HEAD_INIT,
.m_name = "_multiprocessing",
.m_size = 0,
.m_methods = module_methods,
.m_slots = multiprocessing_slots,
};