| 1 |
#ifndef MULTIPROCESSING_H |
| 2 |
#define MULTIPROCESSING_H |
| 3 |
|
| 4 |
#define PY_SSIZE_T_CLEAN |
| 5 |
|
| 6 |
#ifdef __sun |
| 7 |
/* The control message API is only available on Solaris |
| 8 |
if XPG 4.2 or later is requested. */ |
| 9 |
#define _XOPEN_SOURCE 500 |
| 10 |
#endif |
| 11 |
|
| 12 |
#include "Python.h" |
| 13 |
#include "structmember.h" |
| 14 |
#include "pythread.h" |
| 15 |
|
| 16 |
/* |
| 17 |
* Platform includes and definitions |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifdef MS_WINDOWS |
| 21 |
# define WIN32_LEAN_AND_MEAN |
| 22 |
# include <windows.h> |
| 23 |
# include <winsock2.h> |
| 24 |
# include <process.h> /* getpid() */ |
| 25 |
# ifdef Py_DEBUG |
| 26 |
# include <crtdbg.h> |
| 27 |
# endif |
| 28 |
# define SEM_HANDLE HANDLE |
| 29 |
# define SEM_VALUE_MAX LONG_MAX |
| 30 |
#else |
| 31 |
# include <fcntl.h> /* O_CREAT and O_EXCL */ |
| 32 |
# include <netinet/in.h> |
| 33 |
# include <sys/socket.h> |
| 34 |
# include <sys/uio.h> |
| 35 |
# include <arpa/inet.h> /* htonl() and ntohl() */ |
| 36 |
# if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED) |
| 37 |
# include <semaphore.h> |
| 38 |
typedef sem_t *SEM_HANDLE; |
| 39 |
# endif |
| 40 |
# define HANDLE long |
| 41 |
# define SOCKET int |
| 42 |
# define BOOL int |
| 43 |
# define UINT32 uint32_t |
| 44 |
# define INT32 int32_t |
| 45 |
# define TRUE 1 |
| 46 |
# define FALSE 0 |
| 47 |
# define INVALID_HANDLE_VALUE (-1) |
| 48 |
#endif |
| 49 |
|
| 50 |
/* |
| 51 |
* Issue 3110 - Solaris does not define SEM_VALUE_MAX |
| 52 |
*/ |
| 53 |
#ifndef SEM_VALUE_MAX |
| 54 |
#if defined(HAVE_SYSCONF) && defined(_SC_SEM_VALUE_MAX) |
| 55 |
# define SEM_VALUE_MAX sysconf(_SC_SEM_VALUE_MAX) |
| 56 |
#elif defined(_SEM_VALUE_MAX) |
| 57 |
# define SEM_VALUE_MAX _SEM_VALUE_MAX |
| 58 |
#elif defined(_POSIX_SEM_VALUE_MAX) |
| 59 |
# define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX |
| 60 |
#else |
| 61 |
# define SEM_VALUE_MAX INT_MAX |
| 62 |
#endif |
| 63 |
#endif |
| 64 |
|
| 65 |
|
| 66 |
/* |
| 67 |
* Make sure Py_ssize_t available |
| 68 |
*/ |
| 69 |
|
| 70 |
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) |
| 71 |
typedef int Py_ssize_t; |
| 72 |
# define PY_SSIZE_T_MAX INT_MAX |
| 73 |
# define PY_SSIZE_T_MIN INT_MIN |
| 74 |
# define F_PY_SSIZE_T "i" |
| 75 |
# define PyInt_FromSsize_t(n) PyInt_FromLong((long)n) |
| 76 |
#else |
| 77 |
# define F_PY_SSIZE_T "n" |
| 78 |
#endif |
| 79 |
|
| 80 |
/* |
| 81 |
* Format codes |
| 82 |
*/ |
| 83 |
|
| 84 |
#if SIZEOF_VOID_P == SIZEOF_LONG |
| 85 |
# define F_POINTER "k" |
| 86 |
# define T_POINTER T_ULONG |
| 87 |
#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P == SIZEOF_LONG_LONG) |
| 88 |
# define F_POINTER "K" |
| 89 |
# define T_POINTER T_ULONGLONG |
| 90 |
#else |
| 91 |
# error "can't find format code for unsigned integer of same size as void*" |
| 92 |
#endif |
| 93 |
|
| 94 |
#ifdef MS_WINDOWS |
| 95 |
# define F_HANDLE F_POINTER |
| 96 |
# define T_HANDLE T_POINTER |
| 97 |
# define F_SEM_HANDLE F_HANDLE |
| 98 |
# define T_SEM_HANDLE T_HANDLE |
| 99 |
# define F_DWORD "k" |
| 100 |
# define T_DWORD T_ULONG |
| 101 |
#else |
| 102 |
# define F_HANDLE "i" |
| 103 |
# define T_HANDLE T_INT |
| 104 |
# define F_SEM_HANDLE F_POINTER |
| 105 |
# define T_SEM_HANDLE T_POINTER |
| 106 |
#endif |
| 107 |
|
| 108 |
#if PY_VERSION_HEX >= 0x03000000 |
| 109 |
# define F_RBUFFER "y" |
| 110 |
#else |
| 111 |
# define F_RBUFFER "s" |
| 112 |
#endif |
| 113 |
|
| 114 |
/* |
| 115 |
* Error codes which can be returned by functions called without GIL |
| 116 |
*/ |
| 117 |
|
| 118 |
#define MP_SUCCESS (0) |
| 119 |
#define MP_STANDARD_ERROR (-1) |
| 120 |
#define MP_MEMORY_ERROR (-1001) |
| 121 |
#define MP_END_OF_FILE (-1002) |
| 122 |
#define MP_EARLY_END_OF_FILE (-1003) |
| 123 |
#define MP_BAD_MESSAGE_LENGTH (-1004) |
| 124 |
#define MP_SOCKET_ERROR (-1005) |
| 125 |
#define MP_EXCEPTION_HAS_BEEN_SET (-1006) |
| 126 |
|
| 127 |
PyObject *Billiard_SetError(PyObject *Type, int num); |
| 128 |
|
| 129 |
/* |
| 130 |
* Externs - not all will really exist on all platforms |
| 131 |
*/ |
| 132 |
|
| 133 |
extern PyObject *Billiard_BufferTooShort; |
| 134 |
extern PyTypeObject BilliardSemLockType; |
| 135 |
extern PyObject *Billiard_semlock_unlink(PyObject *ignore, PyObject *args); |
| 136 |
extern HANDLE sigint_event; |
| 137 |
|
| 138 |
/* |
| 139 |
* Py3k compatibility |
| 140 |
*/ |
| 141 |
|
| 142 |
#if PY_VERSION_HEX >= 0x03000000 |
| 143 |
# define PICKLE_MODULE "pickle" |
| 144 |
# define FROM_FORMAT PyUnicode_FromFormat |
| 145 |
# define PyInt_FromLong PyLong_FromLong |
| 146 |
# define PyInt_FromSsize_t PyLong_FromSsize_t |
| 147 |
#else |
| 148 |
# define PICKLE_MODULE "cPickle" |
| 149 |
# define FROM_FORMAT PyString_FromFormat |
| 150 |
#endif |
| 151 |
|
| 152 |
#ifndef PyVarObject_HEAD_INIT |
| 153 |
# define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size, |
| 154 |
#endif |
| 155 |
|
| 156 |
#ifndef Py_TPFLAGS_HAVE_WEAKREFS |
| 157 |
# define Py_TPFLAGS_HAVE_WEAKREFS 0 |
| 158 |
#endif |
| 159 |
|
| 160 |
/* |
| 161 |
* Connection definition |
| 162 |
*/ |
| 163 |
|
| 164 |
#define CONNECTION_BUFFER_SIZE 131072 |
| 165 |
|
| 166 |
typedef struct { |
| 167 |
PyObject_HEAD |
| 168 |
HANDLE handle; |
| 169 |
int flags; |
| 170 |
PyObject *weakreflist; |
| 171 |
char buffer[CONNECTION_BUFFER_SIZE]; |
| 172 |
} BilliardConnectionObject; |
| 173 |
|
| 174 |
/* |
| 175 |
* Miscellaneous |
| 176 |
*/ |
| 177 |
|
| 178 |
#define MAX_MESSAGE_LENGTH 0x7fffffff |
| 179 |
|
| 180 |
#ifndef Py_MIN |
| 181 |
# define Py_MIN(x, y) (((x) > (y)) ? (y) : (x)) |
| 182 |
#endif |
| 183 |
|
| 184 |
#endif /* MULTIPROCESSING_H */ |