source: python/trunk/Modules/_multiprocessing/multiprocessing.h

Last change on this file was 391, checked in by dmik, 11 years ago

python: Merge vendor 2.7.6 to trunk.

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
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#ifndef __OS2__
37# if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
38# include <semaphore.h>
39 typedef sem_t *SEM_HANDLE;
40# endif
41#else
42# define SEM_HANDLE HANDLE
43#endif
44# define HANDLE int
45# define SOCKET int
46# define BOOL int
47# define UINT32 uint32_t
48# define INT32 int32_t
49# define TRUE 1
50# define FALSE 0
51# define INVALID_HANDLE_VALUE (-1)
52#endif
53
54/*
55 * Issue 3110 - Solaris does not define SEM_VALUE_MAX
56 */
57#ifndef SEM_VALUE_MAX
58 #if defined(HAVE_SYSCONF) && defined(_SC_SEM_VALUE_MAX)
59 # define SEM_VALUE_MAX sysconf(_SC_SEM_VALUE_MAX)
60 #elif defined(_SEM_VALUE_MAX)
61 # define SEM_VALUE_MAX _SEM_VALUE_MAX
62 #elif defined(_POSIX_SEM_VALUE_MAX)
63 # define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX
64 #else
65 # define SEM_VALUE_MAX INT_MAX
66 #endif
67#endif
68
69
70/*
71 * Make sure Py_ssize_t available
72 */
73
74#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
75 typedef int Py_ssize_t;
76# define PY_SSIZE_T_MAX INT_MAX
77# define PY_SSIZE_T_MIN INT_MIN
78# define F_PY_SSIZE_T "i"
79# define PyInt_FromSsize_t(n) PyInt_FromLong((long)n)
80#else
81# define F_PY_SSIZE_T "n"
82#endif
83
84/*
85 * Format codes
86 */
87
88#if SIZEOF_VOID_P == SIZEOF_LONG
89# define F_POINTER "k"
90# define T_POINTER T_ULONG
91#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P == SIZEOF_LONG_LONG)
92# define F_POINTER "K"
93# define T_POINTER T_ULONGLONG
94#else
95# error "can't find format code for unsigned integer of same size as void*"
96#endif
97
98#ifdef MS_WINDOWS
99# define F_HANDLE F_POINTER
100# define T_HANDLE T_POINTER
101# define F_SEM_HANDLE F_HANDLE
102# define T_SEM_HANDLE T_HANDLE
103# define F_DWORD "k"
104# define T_DWORD T_ULONG
105#else
106# define F_HANDLE "i"
107# define T_HANDLE T_INT
108# define F_SEM_HANDLE F_POINTER
109# define T_SEM_HANDLE T_POINTER
110#endif
111
112#if PY_VERSION_HEX >= 0x03000000
113# define F_RBUFFER "y"
114#else
115# define F_RBUFFER "s"
116#endif
117
118/*
119 * Error codes which can be returned by functions called without GIL
120 */
121
122#define MP_SUCCESS (0)
123#define MP_STANDARD_ERROR (-1)
124#define MP_MEMORY_ERROR (-1001)
125#define MP_END_OF_FILE (-1002)
126#define MP_EARLY_END_OF_FILE (-1003)
127#define MP_BAD_MESSAGE_LENGTH (-1004)
128#define MP_SOCKET_ERROR (-1005)
129#define MP_EXCEPTION_HAS_BEEN_SET (-1006)
130
131PyObject *mp_SetError(PyObject *Type, int num);
132
133/*
134 * Externs - not all will really exist on all platforms
135 */
136
137extern PyObject *pickle_dumps;
138extern PyObject *pickle_loads;
139extern PyObject *pickle_protocol;
140extern PyObject *BufferTooShort;
141extern PyTypeObject SemLockType;
142extern PyTypeObject ConnectionType;
143extern PyTypeObject PipeConnectionType;
144extern HANDLE sigint_event;
145
146/*
147 * Py3k compatibility
148 */
149
150#if PY_VERSION_HEX >= 0x03000000
151# define PICKLE_MODULE "pickle"
152# define FROM_FORMAT PyUnicode_FromFormat
153# define PyInt_FromLong PyLong_FromLong
154# define PyInt_FromSsize_t PyLong_FromSsize_t
155#else
156# define PICKLE_MODULE "cPickle"
157# define FROM_FORMAT PyString_FromFormat
158#endif
159
160#ifndef PyVarObject_HEAD_INIT
161# define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
162#endif
163
164#ifndef Py_TPFLAGS_HAVE_WEAKREFS
165# define Py_TPFLAGS_HAVE_WEAKREFS 0
166#endif
167
168/*
169 * Connection definition
170 */
171
172#define CONNECTION_BUFFER_SIZE 1024
173
174typedef struct {
175 PyObject_HEAD
176 HANDLE handle;
177 int flags;
178 PyObject *weakreflist;
179 char buffer[CONNECTION_BUFFER_SIZE];
180} ConnectionObject;
181
182/*
183 * Miscellaneous
184 */
185
186#define MAX_MESSAGE_LENGTH 0x7fffffff
187
188#ifndef MIN
189# define MIN(x, y) ((x) < (y) ? x : y)
190# define MAX(x, y) ((x) > (y) ? x : y)
191#endif
192
193#endif /* MULTIPROCESSING_H */
Note: See TracBrowser for help on using the repository browser.