~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Modules/_multiprocessing/multiprocessing.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

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