diff options
author | Christian Heimes <christian@python.org> | 2021-11-29 11:36:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-29 10:36:10 +0100 |
commit | 4dc198dedd66e3247aa934fb91c9a158c3eea15a (patch) | |
tree | 27151d882be1906a645d392f239895a0c8c7253b | |
parent | 87d5180b7abbb8cf6213361f6bdd57cb605894d2 (diff) | |
download | cpython-git-4dc198dedd66e3247aa934fb91c9a158c3eea15a.tar.gz |
bpo-45847: Fix _multiprocessing on platforms without sem_open (GH-29833)
-rw-r--r-- | Modules/_multiprocessing/clinic/semaphore.c.h | 86 | ||||
-rw-r--r-- | Modules/_multiprocessing/multiprocessing.c | 3 | ||||
-rw-r--r-- | Modules/_multiprocessing/multiprocessing.h | 2 | ||||
-rw-r--r-- | Modules/_multiprocessing/semaphore.c | 4 |
4 files changed, 84 insertions, 11 deletions
diff --git a/Modules/_multiprocessing/clinic/semaphore.c.h b/Modules/_multiprocessing/clinic/semaphore.c.h index e1b9309e9f..018447ad13 100644 --- a/Modules/_multiprocessing/clinic/semaphore.c.h +++ b/Modules/_multiprocessing/clinic/semaphore.c.h @@ -2,7 +2,7 @@ preserve [clinic start generated code]*/ -#if defined(MS_WINDOWS) +#if defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS) PyDoc_STRVAR(_multiprocessing_SemLock_acquire__doc__, "acquire($self, /, block=True, timeout=None)\n" @@ -52,9 +52,9 @@ exit: return return_value; } -#endif /* defined(MS_WINDOWS) */ +#endif /* defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS) */ -#if defined(MS_WINDOWS) +#if defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS) PyDoc_STRVAR(_multiprocessing_SemLock_release__doc__, "release($self, /)\n" @@ -74,9 +74,9 @@ _multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignore return _multiprocessing_SemLock_release_impl(self); } -#endif /* defined(MS_WINDOWS) */ +#endif /* defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS) */ -#if !defined(MS_WINDOWS) +#if defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS) PyDoc_STRVAR(_multiprocessing_SemLock_acquire__doc__, "acquire($self, /, block=True, timeout=None)\n" @@ -126,9 +126,9 @@ exit: return return_value; } -#endif /* !defined(MS_WINDOWS) */ +#endif /* defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS) */ -#if !defined(MS_WINDOWS) +#if defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS) PyDoc_STRVAR(_multiprocessing_SemLock_release__doc__, "release($self, /)\n" @@ -148,7 +148,9 @@ _multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignore return _multiprocessing_SemLock_release_impl(self); } -#endif /* !defined(MS_WINDOWS) */ +#endif /* defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS) */ + +#if defined(HAVE_MP_SEMAPHORE) static PyObject * _multiprocessing_SemLock_impl(PyTypeObject *type, int kind, int value, @@ -208,6 +210,10 @@ exit: return return_value; } +#endif /* defined(HAVE_MP_SEMAPHORE) */ + +#if defined(HAVE_MP_SEMAPHORE) + PyDoc_STRVAR(_multiprocessing_SemLock__rebuild__doc__, "_rebuild($type, handle, kind, maxvalue, name, /)\n" "--\n" @@ -240,6 +246,10 @@ exit: return return_value; } +#endif /* defined(HAVE_MP_SEMAPHORE) */ + +#if defined(HAVE_MP_SEMAPHORE) + PyDoc_STRVAR(_multiprocessing_SemLock__count__doc__, "_count($self, /)\n" "--\n" @@ -258,6 +268,10 @@ _multiprocessing_SemLock__count(SemLockObject *self, PyObject *Py_UNUSED(ignored return _multiprocessing_SemLock__count_impl(self); } +#endif /* defined(HAVE_MP_SEMAPHORE) */ + +#if defined(HAVE_MP_SEMAPHORE) + PyDoc_STRVAR(_multiprocessing_SemLock__is_mine__doc__, "_is_mine($self, /)\n" "--\n" @@ -276,6 +290,10 @@ _multiprocessing_SemLock__is_mine(SemLockObject *self, PyObject *Py_UNUSED(ignor return _multiprocessing_SemLock__is_mine_impl(self); } +#endif /* defined(HAVE_MP_SEMAPHORE) */ + +#if defined(HAVE_MP_SEMAPHORE) + PyDoc_STRVAR(_multiprocessing_SemLock__get_value__doc__, "_get_value($self, /)\n" "--\n" @@ -294,6 +312,10 @@ _multiprocessing_SemLock__get_value(SemLockObject *self, PyObject *Py_UNUSED(ign return _multiprocessing_SemLock__get_value_impl(self); } +#endif /* defined(HAVE_MP_SEMAPHORE) */ + +#if defined(HAVE_MP_SEMAPHORE) + PyDoc_STRVAR(_multiprocessing_SemLock__is_zero__doc__, "_is_zero($self, /)\n" "--\n" @@ -312,6 +334,10 @@ _multiprocessing_SemLock__is_zero(SemLockObject *self, PyObject *Py_UNUSED(ignor return _multiprocessing_SemLock__is_zero_impl(self); } +#endif /* defined(HAVE_MP_SEMAPHORE) */ + +#if defined(HAVE_MP_SEMAPHORE) + PyDoc_STRVAR(_multiprocessing_SemLock__after_fork__doc__, "_after_fork($self, /)\n" "--\n" @@ -330,6 +356,10 @@ _multiprocessing_SemLock__after_fork(SemLockObject *self, PyObject *Py_UNUSED(ig return _multiprocessing_SemLock__after_fork_impl(self); } +#endif /* defined(HAVE_MP_SEMAPHORE) */ + +#if defined(HAVE_MP_SEMAPHORE) + PyDoc_STRVAR(_multiprocessing_SemLock___enter____doc__, "__enter__($self, /)\n" "--\n" @@ -348,6 +378,10 @@ _multiprocessing_SemLock___enter__(SemLockObject *self, PyObject *Py_UNUSED(igno return _multiprocessing_SemLock___enter___impl(self); } +#endif /* defined(HAVE_MP_SEMAPHORE) */ + +#if defined(HAVE_MP_SEMAPHORE) + PyDoc_STRVAR(_multiprocessing_SemLock___exit____doc__, "__exit__($self, exc_type=None, exc_value=None, exc_tb=None, /)\n" "--\n" @@ -392,6 +426,8 @@ exit: return return_value; } +#endif /* defined(HAVE_MP_SEMAPHORE) */ + #ifndef _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF #define _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF #endif /* !defined(_MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF) */ @@ -399,4 +435,36 @@ exit: #ifndef _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF #define _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF #endif /* !defined(_MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF) */ -/*[clinic end generated code: output=e7fd938150601fe5 input=a9049054013a1b77]*/ + +#ifndef _MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF + #define _MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF +#endif /* !defined(_MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF) */ + +#ifndef _MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF + #define _MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF +#endif /* !defined(_MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF) */ + +#ifndef _MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF + #define _MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF +#endif /* !defined(_MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF) */ + +#ifndef _MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF + #define _MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF +#endif /* !defined(_MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF) */ + +#ifndef _MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF + #define _MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF +#endif /* !defined(_MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF) */ + +#ifndef _MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF + #define _MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF +#endif /* !defined(_MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF) */ + +#ifndef _MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF + #define _MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF +#endif /* !defined(_MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF) */ + +#ifndef _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF + #define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF +#endif /* !defined(_MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF) */ +/*[clinic end generated code: output=fde05a081b5bdba4 input=a9049054013a1b77]*/ diff --git a/Modules/_multiprocessing/multiprocessing.c b/Modules/_multiprocessing/multiprocessing.c index bec23517fc..0809c2455d 100644 --- a/Modules/_multiprocessing/multiprocessing.c +++ b/Modules/_multiprocessing/multiprocessing.c @@ -186,8 +186,7 @@ static PyMethodDef module_methods[] = { static int multiprocessing_exec(PyObject *module) { -#if defined(MS_WINDOWS) || \ - (defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)) +#ifdef HAVE_MP_SEMAPHORE /* Add _PyMp_SemLock type to module */ if (PyModule_AddType(module, &_PyMp_SemLockType) < 0) { diff --git a/Modules/_multiprocessing/multiprocessing.h b/Modules/_multiprocessing/multiprocessing.h index 277963bc15..3a8314b1db 100644 --- a/Modules/_multiprocessing/multiprocessing.h +++ b/Modules/_multiprocessing/multiprocessing.h @@ -21,9 +21,11 @@ # endif # define SEM_HANDLE HANDLE # define SEM_VALUE_MAX LONG_MAX +# define HAVE_MP_SEMAPHORE #else # include <fcntl.h> /* O_CREAT and O_EXCL */ # if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED) +# define HAVE_MP_SEMAPHORE # include <semaphore.h> typedef sem_t *SEM_HANDLE; # endif diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c index 9a2d1f85c9..8607476aff 100644 --- a/Modules/_multiprocessing/semaphore.c +++ b/Modules/_multiprocessing/semaphore.c @@ -9,6 +9,8 @@ #include "multiprocessing.h" +#ifdef HAVE_MP_SEMAPHORE + enum { RECURSIVE_MUTEX, SEMAPHORE }; typedef struct { @@ -794,3 +796,5 @@ _PyMp_sem_unlink(const char *name) Py_RETURN_NONE; } + +#endif // HAVE_MP_SEMAPHORE |