blob: c303447904d1216891d7de82abdb55807ec266e4 [file] [log] [blame]
Benjamin Petersonfa268032008-06-13 19:28:21 +00001#ifndef MULTIPROCESSING_H
2#define MULTIPROCESSING_H
3
4#define PY_SSIZE_T_CLEAN
5
Martin v. Löwisec78d0a2010-06-04 17:20:56 +00006#ifdef __sun
Brett Cannonb94767f2011-02-22 20:15:44 +00007/* The control message API is only available on Solaris
Martin v. Löwisec78d0a2010-06-04 17:20:56 +00008 if XPG 4.2 or later is requested. */
9#define _XOPEN_SOURCE 500
10#endif
11
Benjamin Petersonfa268032008-06-13 19:28:21 +000012#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 Pitrouf95a1b32010-05-09 15:52:27 +000024# include <process.h> /* getpid() */
Jesse Noller4b413d32009-04-01 20:51:28 +000025# ifdef Py_DEBUG
26# include <crtdbg.h>
27# endif
Benjamin Petersonfa268032008-06-13 19:28:21 +000028# 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öwisb37509b2008-11-04 20:45:29 +000032# include <netinet/in.h>
Benjamin Petersonfa268032008-06-13 19:28:21 +000033# include <sys/socket.h>
Martin v. Löwisb37509b2008-11-04 20:45:29 +000034# include <sys/uio.h>
Benjamin Petersonfa268032008-06-13 19:28:21 +000035# include <arpa/inet.h> /* htonl() and ntohl() */
Mark Dickinsona614f042009-11-28 12:48:43 +000036# if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
Benjamin Petersonfa268032008-06-13 19:28:21 +000037# 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 Noller338f5782008-09-03 18:22:19 +000051 * Issue 3110 - Solaris does not define SEM_VALUE_MAX
52 */
53#ifndef SEM_VALUE_MAX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000054 #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 Noller338f5782008-09-03 18:22:19 +000063#endif
64
Benjamin Peterson965ce872009-04-05 21:24:58 +000065
Jesse Noller338f5782008-09-03 18:22:19 +000066/*
Benjamin Petersonfa268032008-06-13 19:28:21 +000067 * 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 Petersonfa268032008-06-13 19:28:21 +000094/*
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 Pitrou87cf2202011-05-09 17:04:27 +0200101#define MP_SOCKET_ERROR (-1002)
102#define MP_EXCEPTION_HAS_BEEN_SET (-1003)
Benjamin Petersonfa268032008-06-13 19:28:21 +0000103
104PyObject *mp_SetError(PyObject *Type, int num);
105
106/*
107 * Externs - not all will really exist on all platforms
108 */
109
Benjamin Petersonfa268032008-06-13 19:28:21 +0000110extern PyObject *BufferTooShort;
111extern PyTypeObject SemLockType;
Benjamin Petersonfa268032008-06-13 19:28:21 +0000112extern PyTypeObject PipeConnectionType;
113extern HANDLE sigint_event;
114
115/*
Benjamin Petersonfa268032008-06-13 19:28:21 +0000116 * Miscellaneous
117 */
118
Benjamin Petersonfa268032008-06-13 19:28:21 +0000119#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 */