1 #ifndef PROCESSING_H
2 #define PROCESSING_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>
19 #  define SEM_HANDLE HANDLE
20    HANDLE duplicate_handle(HANDLE h);
21 #else
22 #  include <unistd.h>
23 #  include <sys/socket.h>
24 #  include <arpa/inet.h>
25 #  if HAVE_SEM_OPEN
26 #    include <semaphore.h>
27 #    include <fcntl.h>
28      typedef sem_t *SEM_HANDLE;
29 #  endif
30 #  define HANDLE int
31 #  define SOCKET int
32 #  define BOOL int
33 #  define UINT32 uint32_t
34 #  define INT32 int32_t
35 #  define TRUE 1
36 #  define FALSE 0
37 #  define INVALID_HANDLE_VALUE (-1)
38 #endif
39 
40 /*
41  * Make sure Py_ssize_t available
42  */
43 
44 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
45    typedef int Py_ssize_t;
46 #  define PY_SSIZE_T_MAX INT_MAX
47 #  define PY_SSIZE_T_MIN INT_MIN
48 #  define F_PY_SSIZE_T "i"
49 #  define PY_FORMAT_SIZE_T ""
50 #  define PyInt_FromSsize_t(n) PyInt_FromLong((long)n)
51 #else
52 #  define F_PY_SSIZE_T "n"
53 #endif
54 
55 /*
56  * Format codes
57  */
58 
59 #if SIZEOF_VOID_P == SIZEOF_LONG
60 #  define F_POINTER "k"
61 #  define T_POINTER T_ULONG
62 #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P == SIZEOF_LONG_LONG)
63 #  define F_POINTER "K"
64 #  define T_POINTER T_ULONGLONG
65 #else
66 #  error "can't find format code for unsigned integer of same size as void*"
67 #endif
68 
69 #ifdef MS_WINDOWS
70 #  define F_HANDLE F_POINTER
71 #  define T_HANDLE T_POINTER
72 #  define F_SEM_HANDLE F_HANDLE
73 #  define T_SEM_HANDLE T_HANDLE
74 #  define F_DWORD "k"
75 #  define T_DWORD T_ULONG
76 #else
77 #  define F_HANDLE "i"
78 #  define T_HANDLE T_INT
79 #  define F_SEM_HANDLE F_POINTER
80 #  define T_SEM_HANDLE T_POINTER
81 #endif
82 
83 /*
84  * Message length limited to 2**31-1
85  */
86 
87 #define TOO_LONG(n) ((UINT32)n >= 0x7fffffff)
88 
89 /*
90  * Error codes which can be returned by functions called without GIL
91  */
92 
93 #define SUCCESS (0)
94 #define STANDARD_ERROR (-1)
95 #define MEMORY_ERROR (-1001)
96 #define END_OF_FILE (-1002)
97 #define EARLY_END_OF_FILE (-1003)
98 #define BAD_MESSAGE_LENGTH (-1004)
99 #define WSA_ERROR (-1005)
100 #define EXCEPTION_HAS_BEEN_SET (-1006)
101 
102 PyObject *SetException(PyObject *Type, int num);
103 
104 /*
105  * Externs
106  */
107 
108 extern PyObject *dumpsFunction;
109 extern PyObject *loadsFunction;
110 extern PyObject *protocol;
111 extern PyObject *BufferTooShort;
112 extern PyTypeObject SemLockType;
113 extern PyTypeObject ConnectionType;
114 
115 #ifdef MS_WINDOWS
116 extern PyTypeObject PipeConnectionType;
117 extern HANDLE hInterruptEvent;
118 extern long main_thread;
119 #endif
120 
121 #endif /* PROCESSING_H */
122