Skip to content

Commit 8fb9f4c

Browse files
committed
Get rid of circular import and eliminate unprefixed exported symbols
from _multiprocessing.
1 parent 8190149 commit 8fb9f4c

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

Modules/_multiprocessing/multiprocessing.c

+6-15
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
#include "multiprocessing.h"
1111

1212

13-
PyObject *ProcessError, *BufferTooShort;
14-
1513
/*
1614
* Function which raises exceptions based on error codes
1715
*/
1816

1917
PyObject *
20-
mp_SetError(PyObject *Type, int num)
18+
_PyMp_SetError(PyObject *Type, int num)
2119
{
2220
switch (num) {
2321
#ifdef MS_WINDOWS
@@ -159,19 +157,12 @@ PyInit__multiprocessing(void)
159157
if (!module)
160158
return NULL;
161159

162-
/* Get copy of BufferTooShort */
163-
temp = PyImport_ImportModule("multiprocessing");
164-
if (!temp)
165-
return NULL;
166-
BufferTooShort = PyObject_GetAttrString(temp, "BufferTooShort");
167-
Py_XDECREF(temp);
168-
169160
#if defined(MS_WINDOWS) || \
170161
(defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED))
171-
/* Add SemLock type to module */
172-
if (PyType_Ready(&SemLockType) < 0)
162+
/* Add _PyMp_SemLock type to module */
163+
if (PyType_Ready(&_PyMp_SemLockType) < 0)
173164
return NULL;
174-
Py_INCREF(&SemLockType);
165+
Py_INCREF(&_PyMp_SemLockType);
175166
{
176167
PyObject *py_sem_value_max;
177168
/* Some systems define SEM_VALUE_MAX as an unsigned value that
@@ -182,10 +173,10 @@ PyInit__multiprocessing(void)
182173
py_sem_value_max = PyLong_FromLong(SEM_VALUE_MAX);
183174
if (py_sem_value_max == NULL)
184175
return NULL;
185-
PyDict_SetItemString(SemLockType.tp_dict, "SEM_VALUE_MAX",
176+
PyDict_SetItemString(_PyMp_SemLockType.tp_dict, "SEM_VALUE_MAX",
186177
py_sem_value_max);
187178
}
188-
PyModule_AddObject(module, "SemLock", (PyObject*)&SemLockType);
179+
PyModule_AddObject(module, "SemLock", (PyObject*)&_PyMp_SemLockType);
189180
#endif
190181

191182
/* Add configuration macros */

Modules/_multiprocessing/multiprocessing.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,13 @@
9191
#define MP_SOCKET_ERROR (-1002)
9292
#define MP_EXCEPTION_HAS_BEEN_SET (-1003)
9393

94-
PyObject *mp_SetError(PyObject *Type, int num);
94+
PyObject *_PyMp_SetError(PyObject *Type, int num);
9595

9696
/*
9797
* Externs - not all will really exist on all platforms
9898
*/
9999

100-
extern PyObject *BufferTooShort;
101-
extern PyTypeObject SemLockType;
102-
extern PyTypeObject PipeConnectionType;
100+
extern PyTypeObject _PyMp_SemLockType;
103101

104102
/*
105103
* Miscellaneous

Modules/_multiprocessing/semaphore.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ semlock_release(SemLockObject *self, PyObject *args)
193193
#ifndef HAVE_SEM_TIMEDWAIT
194194
# define sem_timedwait(sem,deadline) sem_timedwait_save(sem,deadline,_save)
195195

196-
int
196+
static int
197197
sem_timedwait_save(sem_t *sem, struct timespec *deadline, PyThreadState *_save)
198198
{
199199
int res;
@@ -444,7 +444,7 @@ semlock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
444444
failure:
445445
if (handle != SEM_FAILED)
446446
SEM_CLOSE(handle);
447-
mp_SetError(NULL, MP_STANDARD_ERROR);
447+
_PyMp_SetError(NULL, MP_STANDARD_ERROR);
448448
return NULL;
449449
}
450450

@@ -491,7 +491,7 @@ semlock_getvalue(SemLockObject *self)
491491
#else
492492
int sval;
493493
if (SEM_GETVALUE(self->handle, &sval) < 0)
494-
return mp_SetError(NULL, MP_STANDARD_ERROR);
494+
return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
495495
/* some posix implementations use negative numbers to indicate
496496
the number of waiting threads */
497497
if (sval < 0)
@@ -507,16 +507,16 @@ semlock_iszero(SemLockObject *self)
507507
if (sem_trywait(self->handle) < 0) {
508508
if (errno == EAGAIN)
509509
Py_RETURN_TRUE;
510-
return mp_SetError(NULL, MP_STANDARD_ERROR);
510+
return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
511511
} else {
512512
if (sem_post(self->handle) < 0)
513-
return mp_SetError(NULL, MP_STANDARD_ERROR);
513+
return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
514514
Py_RETURN_FALSE;
515515
}
516516
#else
517517
int sval;
518518
if (SEM_GETVALUE(self->handle, &sval) < 0)
519-
return mp_SetError(NULL, MP_STANDARD_ERROR);
519+
return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
520520
return PyBool_FromLong((long)sval == 0);
521521
#endif
522522
}
@@ -574,7 +574,7 @@ static PyMemberDef semlock_members[] = {
574574
* Semaphore type
575575
*/
576576

577-
PyTypeObject SemLockType = {
577+
PyTypeObject _PyMp_SemLockType = {
578578
PyVarObject_HEAD_INIT(NULL, 0)
579579
/* tp_name */ "_multiprocessing.SemLock",
580580
/* tp_basicsize */ sizeof(SemLockObject),

0 commit comments

Comments
 (0)