Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 1 | #ifndef MULTIPROCESSING_H |
| 2 | #define MULTIPROCESSING_H |
| 3 | |
| 4 | #define PY_SSIZE_T_CLEAN |
| 5 | |
Martin v. Löwis | ec78d0a | 2010-06-04 17:20:56 +0000 | [diff] [blame] | 6 | #ifdef __sun |
Brett Cannon | b94767f | 2011-02-22 20:15:44 +0000 | [diff] [blame] | 7 | /* The control message API is only available on Solaris |
Martin v. Löwis | ec78d0a | 2010-06-04 17:20:56 +0000 | [diff] [blame] | 8 | if XPG 4.2 or later is requested. */ |
| 9 | #define _XOPEN_SOURCE 500 |
| 10 | #endif |
| 11 | |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 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> |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 24 | # include <process.h> /* getpid() */ |
Jesse Noller | 4b413d3 | 2009-04-01 20:51:28 +0000 | [diff] [blame] | 25 | # ifdef Py_DEBUG |
| 26 | # include <crtdbg.h> |
| 27 | # endif |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 28 | # define SEM_HANDLE HANDLE |
| 29 | # define SEM_VALUE_MAX LONG_MAX |
| 30 | #else |
| 31 | # include <fcntl.h> /* O_CREAT and O_EXCL */ |
Martin v. Löwis | b37509b | 2008-11-04 20:45:29 +0000 | [diff] [blame] | 32 | # include <netinet/in.h> |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 33 | # include <sys/socket.h> |
Martin v. Löwis | b37509b | 2008-11-04 20:45:29 +0000 | [diff] [blame] | 34 | # include <sys/uio.h> |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 35 | # include <arpa/inet.h> /* htonl() and ntohl() */ |
Mark Dickinson | a614f04 | 2009-11-28 12:48:43 +0000 | [diff] [blame] | 36 | # if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED) |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 37 | # include <semaphore.h> |
| 38 | typedef sem_t *SEM_HANDLE; |
| 39 | # endif |
| 40 | # define HANDLE int |
| 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 | /* |
Jesse Noller | 338f578 | 2008-09-03 18:22:19 +0000 | [diff] [blame] | 51 | * Issue 3110 - Solaris does not define SEM_VALUE_MAX |
| 52 | */ |
| 53 | #ifndef SEM_VALUE_MAX |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 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 |
Jesse Noller | 338f578 | 2008-09-03 18:22:19 +0000 | [diff] [blame] | 63 | #endif |
| 64 | |
Benjamin Peterson | 965ce87 | 2009-04-05 21:24:58 +0000 | [diff] [blame] | 65 | |
Jesse Noller | 338f578 | 2008-09-03 18:22:19 +0000 | [diff] [blame] | 66 | /* |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 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 | |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 94 | /* |
| 95 | * Error codes which can be returned by functions called without GIL |
| 96 | */ |
| 97 | |
| 98 | #define MP_SUCCESS (0) |
| 99 | #define MP_STANDARD_ERROR (-1) |
| 100 | #define MP_MEMORY_ERROR (-1001) |
Antoine Pitrou | 87cf220 | 2011-05-09 17:04:27 +0200 | [diff] [blame] | 101 | #define MP_SOCKET_ERROR (-1002) |
| 102 | #define MP_EXCEPTION_HAS_BEEN_SET (-1003) |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 103 | |
| 104 | PyObject *mp_SetError(PyObject *Type, int num); |
| 105 | |
| 106 | /* |
| 107 | * Externs - not all will really exist on all platforms |
| 108 | */ |
| 109 | |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 110 | extern PyObject *BufferTooShort; |
| 111 | extern PyTypeObject SemLockType; |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 112 | extern PyTypeObject PipeConnectionType; |
| 113 | extern HANDLE sigint_event; |
| 114 | |
| 115 | /* |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 116 | * Miscellaneous |
| 117 | */ |
| 118 | |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 119 | #ifndef MIN |
| 120 | # define MIN(x, y) ((x) < (y) ? x : y) |
| 121 | # define MAX(x, y) ((x) > (y) ? x : y) |
| 122 | #endif |
| 123 | |
| 124 | #endif /* MULTIPROCESSING_H */ |