Kaydet (Commit) 8fb9f4cf authored tarafından Richard Oudkerk's avatar Richard Oudkerk

Get rid of circular import and eliminate unprefixed exported symbols

from _multiprocessing.
üst 81901490
...@@ -10,14 +10,12 @@ ...@@ -10,14 +10,12 @@
#include "multiprocessing.h" #include "multiprocessing.h"
PyObject *ProcessError, *BufferTooShort;
/* /*
* Function which raises exceptions based on error codes * Function which raises exceptions based on error codes
*/ */
PyObject * PyObject *
mp_SetError(PyObject *Type, int num) _PyMp_SetError(PyObject *Type, int num)
{ {
switch (num) { switch (num) {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
...@@ -159,19 +157,12 @@ PyInit__multiprocessing(void) ...@@ -159,19 +157,12 @@ PyInit__multiprocessing(void)
if (!module) if (!module)
return NULL; return NULL;
/* Get copy of BufferTooShort */
temp = PyImport_ImportModule("multiprocessing");
if (!temp)
return NULL;
BufferTooShort = PyObject_GetAttrString(temp, "BufferTooShort");
Py_XDECREF(temp);
#if defined(MS_WINDOWS) || \ #if defined(MS_WINDOWS) || \
(defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)) (defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED))
/* Add SemLock type to module */ /* Add _PyMp_SemLock type to module */
if (PyType_Ready(&SemLockType) < 0) if (PyType_Ready(&_PyMp_SemLockType) < 0)
return NULL; return NULL;
Py_INCREF(&SemLockType); Py_INCREF(&_PyMp_SemLockType);
{ {
PyObject *py_sem_value_max; PyObject *py_sem_value_max;
/* Some systems define SEM_VALUE_MAX as an unsigned value that /* Some systems define SEM_VALUE_MAX as an unsigned value that
...@@ -182,10 +173,10 @@ PyInit__multiprocessing(void) ...@@ -182,10 +173,10 @@ PyInit__multiprocessing(void)
py_sem_value_max = PyLong_FromLong(SEM_VALUE_MAX); py_sem_value_max = PyLong_FromLong(SEM_VALUE_MAX);
if (py_sem_value_max == NULL) if (py_sem_value_max == NULL)
return NULL; return NULL;
PyDict_SetItemString(SemLockType.tp_dict, "SEM_VALUE_MAX", PyDict_SetItemString(_PyMp_SemLockType.tp_dict, "SEM_VALUE_MAX",
py_sem_value_max); py_sem_value_max);
} }
PyModule_AddObject(module, "SemLock", (PyObject*)&SemLockType); PyModule_AddObject(module, "SemLock", (PyObject*)&_PyMp_SemLockType);
#endif #endif
/* Add configuration macros */ /* Add configuration macros */
......
...@@ -91,15 +91,13 @@ ...@@ -91,15 +91,13 @@
#define MP_SOCKET_ERROR (-1002) #define MP_SOCKET_ERROR (-1002)
#define MP_EXCEPTION_HAS_BEEN_SET (-1003) #define MP_EXCEPTION_HAS_BEEN_SET (-1003)
PyObject *mp_SetError(PyObject *Type, int num); PyObject *_PyMp_SetError(PyObject *Type, int num);
/* /*
* Externs - not all will really exist on all platforms * Externs - not all will really exist on all platforms
*/ */
extern PyObject *BufferTooShort; extern PyTypeObject _PyMp_SemLockType;
extern PyTypeObject SemLockType;
extern PyTypeObject PipeConnectionType;
/* /*
* Miscellaneous * Miscellaneous
......
...@@ -193,7 +193,7 @@ semlock_release(SemLockObject *self, PyObject *args) ...@@ -193,7 +193,7 @@ semlock_release(SemLockObject *self, PyObject *args)
#ifndef HAVE_SEM_TIMEDWAIT #ifndef HAVE_SEM_TIMEDWAIT
# define sem_timedwait(sem,deadline) sem_timedwait_save(sem,deadline,_save) # define sem_timedwait(sem,deadline) sem_timedwait_save(sem,deadline,_save)
int static int
sem_timedwait_save(sem_t *sem, struct timespec *deadline, PyThreadState *_save) sem_timedwait_save(sem_t *sem, struct timespec *deadline, PyThreadState *_save)
{ {
int res; int res;
...@@ -444,7 +444,7 @@ semlock_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -444,7 +444,7 @@ semlock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
failure: failure:
if (handle != SEM_FAILED) if (handle != SEM_FAILED)
SEM_CLOSE(handle); SEM_CLOSE(handle);
mp_SetError(NULL, MP_STANDARD_ERROR); _PyMp_SetError(NULL, MP_STANDARD_ERROR);
return NULL; return NULL;
} }
...@@ -491,7 +491,7 @@ semlock_getvalue(SemLockObject *self) ...@@ -491,7 +491,7 @@ semlock_getvalue(SemLockObject *self)
#else #else
int sval; int sval;
if (SEM_GETVALUE(self->handle, &sval) < 0) if (SEM_GETVALUE(self->handle, &sval) < 0)
return mp_SetError(NULL, MP_STANDARD_ERROR); return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
/* some posix implementations use negative numbers to indicate /* some posix implementations use negative numbers to indicate
the number of waiting threads */ the number of waiting threads */
if (sval < 0) if (sval < 0)
...@@ -507,16 +507,16 @@ semlock_iszero(SemLockObject *self) ...@@ -507,16 +507,16 @@ semlock_iszero(SemLockObject *self)
if (sem_trywait(self->handle) < 0) { if (sem_trywait(self->handle) < 0) {
if (errno == EAGAIN) if (errno == EAGAIN)
Py_RETURN_TRUE; Py_RETURN_TRUE;
return mp_SetError(NULL, MP_STANDARD_ERROR); return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
} else { } else {
if (sem_post(self->handle) < 0) if (sem_post(self->handle) < 0)
return mp_SetError(NULL, MP_STANDARD_ERROR); return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
Py_RETURN_FALSE; Py_RETURN_FALSE;
} }
#else #else
int sval; int sval;
if (SEM_GETVALUE(self->handle, &sval) < 0) if (SEM_GETVALUE(self->handle, &sval) < 0)
return mp_SetError(NULL, MP_STANDARD_ERROR); return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
return PyBool_FromLong((long)sval == 0); return PyBool_FromLong((long)sval == 0);
#endif #endif
} }
...@@ -574,7 +574,7 @@ static PyMemberDef semlock_members[] = { ...@@ -574,7 +574,7 @@ static PyMemberDef semlock_members[] = {
* Semaphore type * Semaphore type
*/ */
PyTypeObject SemLockType = { PyTypeObject _PyMp_SemLockType = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
/* tp_name */ "_multiprocessing.SemLock", /* tp_name */ "_multiprocessing.SemLock",
/* tp_basicsize */ sizeof(SemLockObject), /* tp_basicsize */ sizeof(SemLockObject),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment