1 #ifndef MULTIPROCESSING_H
2 #define MULTIPROCESSING_H
4 #define PY_SSIZE_T_CLEAN
7 #include "structmember.h"
11 * Platform includes and definitions
15 # define WIN32_LEAN_AND_MEAN
17 # include <winsock2.h>
18 # include <process.h> /* getpid() */
22 # define SEM_HANDLE HANDLE
23 # define SEM_VALUE_MAX LONG_MAX
25 # include <fcntl.h> /* O_CREAT and O_EXCL */
26 # include <netinet/in.h>
27 # include <sys/socket.h>
29 # include <arpa/inet.h> /* htonl() and ntohl() */
31 # include <semaphore.h>
32 typedef sem_t
*SEM_HANDLE
;
37 # define UINT32 uint32_t
38 # define INT32 int32_t
41 # define INVALID_HANDLE_VALUE (-1)
45 * Issue 3110 - Solaris does not define SEM_VALUE_MAX
48 #if defined(HAVE_SYSCONF) && defined(_SC_SEM_VALUE_MAX)
49 # define SEM_VALUE_MAX sysconf(_SC_SEM_VALUE_MAX)
50 #elif defined(_SEM_VALUE_MAX)
51 # define SEM_VALUE_MAX _SEM_VALUE_MAX
52 #elif definef(_POSIX_SEM_VALUE_MAX)
53 # define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX
55 # define SEM_VALUE_MAX INT_MAX
61 * Make sure Py_ssize_t available
64 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
65 typedef int Py_ssize_t
;
66 # define PY_SSIZE_T_MAX INT_MAX
67 # define PY_SSIZE_T_MIN INT_MIN
68 # define F_PY_SSIZE_T "i"
69 # define PyInt_FromSsize_t(n) PyInt_FromLong((long)n)
71 # define F_PY_SSIZE_T "n"
78 #if SIZEOF_VOID_P == SIZEOF_LONG
79 # define F_POINTER "k"
80 # define T_POINTER T_ULONG
81 #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P == SIZEOF_LONG_LONG)
82 # define F_POINTER "K"
83 # define T_POINTER T_ULONGLONG
85 # error "can't find format code for unsigned integer of same size as void*"
89 # define F_HANDLE F_POINTER
90 # define T_HANDLE T_POINTER
91 # define F_SEM_HANDLE F_HANDLE
92 # define T_SEM_HANDLE T_HANDLE
94 # define T_DWORD T_ULONG
97 # define T_HANDLE T_INT
98 # define F_SEM_HANDLE F_POINTER
99 # define T_SEM_HANDLE T_POINTER
102 #if PY_VERSION_HEX >= 0x03000000
103 # define F_RBUFFER "y"
105 # define F_RBUFFER "s"
109 * Error codes which can be returned by functions called without GIL
112 #define MP_SUCCESS (0)
113 #define MP_STANDARD_ERROR (-1)
114 #define MP_MEMORY_ERROR (-1001)
115 #define MP_END_OF_FILE (-1002)
116 #define MP_EARLY_END_OF_FILE (-1003)
117 #define MP_BAD_MESSAGE_LENGTH (-1004)
118 #define MP_SOCKET_ERROR (-1005)
119 #define MP_EXCEPTION_HAS_BEEN_SET (-1006)
121 PyObject
*mp_SetError(PyObject
*Type
, int num
);
124 * Externs - not all will really exist on all platforms
127 extern PyObject
*pickle_dumps
;
128 extern PyObject
*pickle_loads
;
129 extern PyObject
*pickle_protocol
;
130 extern PyObject
*BufferTooShort
;
131 extern PyTypeObject SemLockType
;
132 extern PyTypeObject ConnectionType
;
133 extern PyTypeObject PipeConnectionType
;
134 extern HANDLE sigint_event
;
140 #if PY_VERSION_HEX >= 0x03000000
141 # define PICKLE_MODULE "pickle"
142 # define FROM_FORMAT PyUnicode_FromFormat
143 # define PyInt_FromLong PyLong_FromLong
144 # define PyInt_FromSsize_t PyLong_FromSsize_t
146 # define PICKLE_MODULE "cPickle"
147 # define FROM_FORMAT PyString_FromFormat
150 #ifndef PyVarObject_HEAD_INIT
151 # define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
154 #ifndef Py_TPFLAGS_HAVE_WEAKREFS
155 # define Py_TPFLAGS_HAVE_WEAKREFS 0
159 * Connection definition
162 #define CONNECTION_BUFFER_SIZE 1024
168 PyObject
*weakreflist
;
169 char buffer
[CONNECTION_BUFFER_SIZE
];
176 #define MAX_MESSAGE_LENGTH 0x7fffffff
179 # define MIN(x, y) ((x) < (y) ? x : y)
180 # define MAX(x, y) ((x) > (y) ? x : y)
183 #endif /* MULTIPROCESSING_H */