mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
GH-94382: port multiprocessing static types to heap types (#94336)
This commit is contained in:
parent
8ede67cdcf
commit
000a4eebe7
4 changed files with 63 additions and 64 deletions
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue