annotate Modules/_multiprocessing/multiprocessing.c @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents d343e802b276
children 2e3ec3bb4be7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47694
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
1 /*
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
2 * Extension module used by multiprocessing package
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
3 *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
4 * multiprocessing.c
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
5 *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
6 * Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
7 */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
8
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
9 #include "multiprocessing.h"
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
10
52696
d343e802b276 issue5545: Switch to Autoconf for multiprocessing; special thanks to Martin Lowis for help
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
11 #ifdef SCM_RIGHTS
d343e802b276 issue5545: Switch to Autoconf for multiprocessing; special thanks to Martin Lowis for help
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
12 #define HAVE_FD_TRANSFER 1
d343e802b276 issue5545: Switch to Autoconf for multiprocessing; special thanks to Martin Lowis for help
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
13 #else
d343e802b276 issue5545: Switch to Autoconf for multiprocessing; special thanks to Martin Lowis for help
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
14 #define HAVE_FD_TRANSFER 0
d343e802b276 issue5545: Switch to Autoconf for multiprocessing; special thanks to Martin Lowis for help
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
15 #endif
d343e802b276 issue5545: Switch to Autoconf for multiprocessing; special thanks to Martin Lowis for help
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
16
47694
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
17 PyObject *create_win32_namespace(void);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
18
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
19 PyObject *pickle_dumps, *pickle_loads, *pickle_protocol;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
20 PyObject *ProcessError, *BufferTooShort;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
21
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
22 /*
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
23 * Function which raises exceptions based on error codes
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
24 */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
25
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
26 PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
27 mp_SetError(PyObject *Type, int num)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
28 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
29 switch (num) {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
30 #ifdef MS_WINDOWS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
31 case MP_STANDARD_ERROR:
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
32 if (Type == NULL)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
33 Type = PyExc_WindowsError;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
34 PyErr_SetExcFromWindowsErr(Type, 0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
35 break;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
36 case MP_SOCKET_ERROR:
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
37 if (Type == NULL)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
38 Type = PyExc_WindowsError;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
39 PyErr_SetExcFromWindowsErr(Type, WSAGetLastError());
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
40 break;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
41 #else /* !MS_WINDOWS */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
42 case MP_STANDARD_ERROR:
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
43 case MP_SOCKET_ERROR:
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
44 if (Type == NULL)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
45 Type = PyExc_OSError;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
46 PyErr_SetFromErrno(Type);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
47 break;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
48 #endif /* !MS_WINDOWS */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
49 case MP_MEMORY_ERROR:
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
50 PyErr_NoMemory();
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
51 break;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
52 case MP_END_OF_FILE:
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
53 PyErr_SetNone(PyExc_EOFError);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
54 break;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
55 case MP_EARLY_END_OF_FILE:
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
56 PyErr_SetString(PyExc_IOError,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
57 "got end of file during message");
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
58 break;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
59 case MP_BAD_MESSAGE_LENGTH:
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
60 PyErr_SetString(PyExc_IOError, "bad message length");
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
61 break;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
62 case MP_EXCEPTION_HAS_BEEN_SET:
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
63 break;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
64 default:
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
65 PyErr_Format(PyExc_RuntimeError,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
66 "unkown error number %d", num);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
67 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
68 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
69 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
70
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
71
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
72 /*
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
73 * Windows only
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
74 */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
75
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
76 #ifdef MS_WINDOWS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
77
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
78 /* On Windows we set an event to signal Ctrl-C; compare with timemodule.c */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
79
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
80 HANDLE sigint_event = NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
81
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
82 static BOOL WINAPI
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
83 ProcessingCtrlHandler(DWORD dwCtrlType)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
84 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
85 SetEvent(sigint_event);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
86 return FALSE;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
87 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
88
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
89 /*
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
90 * Unix only
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
91 */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
92
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
93 #else /* !MS_WINDOWS */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
94
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
95 #if HAVE_FD_TRANSFER
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
96
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
97 /* Functions for transferring file descriptors between processes.
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
98 Reimplements some of the functionality of the fdcred
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
99 module at http://www.mca-ltd.com/resources/fdcred_1.tgz. */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
100
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
101 static PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
102 multiprocessing_sendfd(PyObject *self, PyObject *args)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
103 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
104 int conn, fd, res;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
105 char dummy_char;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
106 char buf[CMSG_SPACE(sizeof(int))];
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
107 struct msghdr msg = {0};
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
108 struct iovec dummy_iov;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
109 struct cmsghdr *cmsg;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
110
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
111 if (!PyArg_ParseTuple(args, "ii", &conn, &fd))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
112 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
113
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
114 dummy_iov.iov_base = &dummy_char;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
115 dummy_iov.iov_len = 1;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
116 msg.msg_control = buf;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
117 msg.msg_controllen = sizeof(buf);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
118 msg.msg_iov = &dummy_iov;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
119 msg.msg_iovlen = 1;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
120 cmsg = CMSG_FIRSTHDR(&msg);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
121 cmsg->cmsg_level = SOL_SOCKET;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
122 cmsg->cmsg_type = SCM_RIGHTS;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
123 cmsg->cmsg_len = CMSG_LEN(sizeof(int));
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
124 msg.msg_controllen = cmsg->cmsg_len;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
125 *(int*)CMSG_DATA(cmsg) = fd;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
126
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
127 Py_BEGIN_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
128 res = sendmsg(conn, &msg, 0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
129 Py_END_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
130
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
131 if (res < 0)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
132 return PyErr_SetFromErrno(PyExc_OSError);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
133 Py_RETURN_NONE;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
134 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
135
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
136 static PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
137 multiprocessing_recvfd(PyObject *self, PyObject *args)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
138 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
139 int conn, fd, res;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
140 char dummy_char;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
141 char buf[CMSG_SPACE(sizeof(int))];
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
142 struct msghdr msg = {0};
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
143 struct iovec dummy_iov;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
144 struct cmsghdr *cmsg;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
145
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
146 if (!PyArg_ParseTuple(args, "i", &conn))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
147 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
148
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
149 dummy_iov.iov_base = &dummy_char;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
150 dummy_iov.iov_len = 1;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
151 msg.msg_control = buf;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
152 msg.msg_controllen = sizeof(buf);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
153 msg.msg_iov = &dummy_iov;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
154 msg.msg_iovlen = 1;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
155 cmsg = CMSG_FIRSTHDR(&msg);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
156 cmsg->cmsg_level = SOL_SOCKET;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
157 cmsg->cmsg_type = SCM_RIGHTS;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
158 cmsg->cmsg_len = CMSG_LEN(sizeof(int));
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
159 msg.msg_controllen = cmsg->cmsg_len;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
160
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
161 Py_BEGIN_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
162 res = recvmsg(conn, &msg, 0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
163 Py_END_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
164
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
165 if (res < 0)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
166 return PyErr_SetFromErrno(PyExc_OSError);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
167
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
168 fd = *(int*)CMSG_DATA(cmsg);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
169 return Py_BuildValue("i", fd);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
170 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
171
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
172 #endif /* HAVE_FD_TRANSFER */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
173
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
174 #endif /* !MS_WINDOWS */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
175
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
176
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
177 /*
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
178 * All platforms
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
179 */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
180
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
181 static PyObject*
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
182 multiprocessing_address_of_buffer(PyObject *self, PyObject *obj)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
183 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
184 void *buffer;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
185 Py_ssize_t buffer_len;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
186
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
187 if (PyObject_AsWriteBuffer(obj, &buffer, &buffer_len) < 0)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
188 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
189
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
190 return Py_BuildValue("N" F_PY_SSIZE_T,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
191 PyLong_FromVoidPtr(buffer), buffer_len);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
192 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
193
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
194
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
195 /*
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
196 * Function table
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
197 */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
198
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
199 static PyMethodDef module_methods[] = {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
200 {"address_of_buffer", multiprocessing_address_of_buffer, METH_O,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
201 "address_of_buffer(obj) -> int\n"
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
202 "Return address of obj assuming obj supports buffer inteface"},
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
203 #if HAVE_FD_TRANSFER
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
204 {"sendfd", multiprocessing_sendfd, METH_VARARGS,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
205 "sendfd(sockfd, fd) -> None\n"
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
206 "Send file descriptor given by fd over the unix domain socket\n"
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
207 "whose file decriptor is sockfd"},
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
208 {"recvfd", multiprocessing_recvfd, METH_VARARGS,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
209 "recvfd(sockfd) -> fd\n"
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
210 "Receive a file descriptor over a unix domain socket\n"
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
211 "whose file decriptor is sockfd"},
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
212 #endif
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
213 {NULL}
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
214 };
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
215
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
216
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
217 /*
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
218 * Initialize
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
219 */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
220
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
221 PyMODINIT_FUNC
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
222 init_multiprocessing(void)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
223 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
224 PyObject *module, *temp, *value;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
225
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
226 /* Initialize module */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
227 module = Py_InitModule("_multiprocessing", module_methods);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
228 if (!module)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
229 return;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
230
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
231 /* Get copy of objects from pickle */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
232 temp = PyImport_ImportModule(PICKLE_MODULE);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
233 if (!temp)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
234 return;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
235 pickle_dumps = PyObject_GetAttrString(temp, "dumps");
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
236 pickle_loads = PyObject_GetAttrString(temp, "loads");
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
237 pickle_protocol = PyObject_GetAttrString(temp, "HIGHEST_PROTOCOL");
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
238 Py_XDECREF(temp);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
239
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
240 /* Get copy of BufferTooShort */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
241 temp = PyImport_ImportModule("multiprocessing");
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
242 if (!temp)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
243 return;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
244 BufferTooShort = PyObject_GetAttrString(temp, "BufferTooShort");
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
245 Py_XDECREF(temp);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
246
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
247 /* Add connection type to module */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
248 if (PyType_Ready(&ConnectionType) < 0)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
249 return;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
250 Py_INCREF(&ConnectionType);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
251 PyModule_AddObject(module, "Connection", (PyObject*)&ConnectionType);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
252
52696
d343e802b276 issue5545: Switch to Autoconf for multiprocessing; special thanks to Martin Lowis for help
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
253 #if defined(MS_WINDOWS) || defined(HAVE_SEM_OPEN)
47694
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
254 /* Add SemLock type to module */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
255 if (PyType_Ready(&SemLockType) < 0)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
256 return;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
257 Py_INCREF(&SemLockType);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
258 PyDict_SetItemString(SemLockType.tp_dict, "SEM_VALUE_MAX",
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
259 Py_BuildValue("i", SEM_VALUE_MAX));
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
260 PyModule_AddObject(module, "SemLock", (PyObject*)&SemLockType);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
261 #endif
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
262
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
263 #ifdef MS_WINDOWS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
264 /* Add PipeConnection to module */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
265 if (PyType_Ready(&PipeConnectionType) < 0)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
266 return;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
267 Py_INCREF(&PipeConnectionType);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
268 PyModule_AddObject(module, "PipeConnection",
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
269 (PyObject*)&PipeConnectionType);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
270
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
271 /* Initialize win32 class and add to multiprocessing */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
272 temp = create_win32_namespace();
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
273 if (!temp)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
274 return;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
275 PyModule_AddObject(module, "win32", temp);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
276
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
277 /* Initialize the event handle used to signal Ctrl-C */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
278 sigint_event = CreateEvent(NULL, TRUE, FALSE, NULL);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
279 if (!sigint_event) {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
280 PyErr_SetFromWindowsErr(0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
281 return;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
282 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
283 if (!SetConsoleCtrlHandler(ProcessingCtrlHandler, TRUE)) {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
284 PyErr_SetFromWindowsErr(0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
285 return;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
286 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
287 #endif
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
288
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
289 /* Add configuration macros */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
290 temp = PyDict_New();
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
291 if (!temp)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
292 return;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
293 #define ADD_FLAG(name) \
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
294 value = Py_BuildValue("i", name); \
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
295 if (value == NULL) { Py_DECREF(temp); return; } \
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
296 if (PyDict_SetItemString(temp, #name, value) < 0) { \
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
297 Py_DECREF(temp); Py_DECREF(value); return; } \
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
298 Py_DECREF(value)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
299
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
300 #ifdef HAVE_SEM_OPEN
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
301 ADD_FLAG(HAVE_SEM_OPEN);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
302 #endif
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
303 #ifdef HAVE_SEM_TIMEDWAIT
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
304 ADD_FLAG(HAVE_SEM_TIMEDWAIT);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
305 #endif
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
306 #ifdef HAVE_FD_TRANSFER
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
307 ADD_FLAG(HAVE_FD_TRANSFER);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
308 #endif
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
309 #ifdef HAVE_BROKEN_SEM_GETVALUE
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
310 ADD_FLAG(HAVE_BROKEN_SEM_GETVALUE);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
311 #endif
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
312 #ifdef HAVE_BROKEN_SEM_UNLINK
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
313 ADD_FLAG(HAVE_BROKEN_SEM_UNLINK);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
314 #endif
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
315 if (PyModule_AddObject(module, "flags", temp) < 0)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
316 return;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47676
diff changeset
317 }