annotate Modules/_multiprocessing/win32_functions.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 e2818b9f964b
children e38335d4df91 3b58f2441cc8
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: 47595
diff changeset
1 /*
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
2 * Win32 functions used by multiprocessing package
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
3 *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
4 * win32_functions.c
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
5 *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
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: 47595
diff changeset
7 */
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
8
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
9 #include "multiprocessing.h"
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
10
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
11
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
12 #define WIN32_FUNCTION(func) \
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
13 {#func, (PyCFunction)win32_ ## func, METH_VARARGS | METH_STATIC, ""}
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
14
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
15 #define WIN32_CONSTANT(fmt, con) \
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
16 PyDict_SetItemString(Win32Type.tp_dict, #con, Py_BuildValue(fmt, con))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
17
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
18
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
19 static PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
20 win32_CloseHandle(PyObject *self, PyObject *args)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
21 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
22 HANDLE hObject;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
23 BOOL success;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
24
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
25 if (!PyArg_ParseTuple(args, F_HANDLE, &hObject))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
26 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
27
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
28 Py_BEGIN_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
29 success = CloseHandle(hObject);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
30 Py_END_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
31
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
32 if (!success)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
33 return PyErr_SetFromWindowsErr(0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
34
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
35 Py_RETURN_NONE;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
36 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
37
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
38 static PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
39 win32_ConnectNamedPipe(PyObject *self, PyObject *args)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
40 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
41 HANDLE hNamedPipe;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
42 LPOVERLAPPED lpOverlapped;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
43 BOOL success;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
44
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
45 if (!PyArg_ParseTuple(args, F_HANDLE F_POINTER,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
46 &hNamedPipe, &lpOverlapped))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
47 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
48
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
49 Py_BEGIN_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
50 success = ConnectNamedPipe(hNamedPipe, lpOverlapped);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
51 Py_END_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
52
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
53 if (!success)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
54 return PyErr_SetFromWindowsErr(0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
55
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
56 Py_RETURN_NONE;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
57 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
58
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
59 static PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
60 win32_CreateFile(PyObject *self, PyObject *args)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
61 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
62 LPCTSTR lpFileName;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
63 DWORD dwDesiredAccess;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
64 DWORD dwShareMode;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
65 LPSECURITY_ATTRIBUTES lpSecurityAttributes;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
66 DWORD dwCreationDisposition;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
67 DWORD dwFlagsAndAttributes;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
68 HANDLE hTemplateFile;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
69 HANDLE handle;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
70
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
71 if (!PyArg_ParseTuple(args, "s" F_DWORD F_DWORD F_POINTER
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
72 F_DWORD F_DWORD F_HANDLE,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
73 &lpFileName, &dwDesiredAccess, &dwShareMode,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
74 &lpSecurityAttributes, &dwCreationDisposition,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
75 &dwFlagsAndAttributes, &hTemplateFile))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
76 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
77
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
78 Py_BEGIN_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
79 handle = CreateFile(lpFileName, dwDesiredAccess,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
80 dwShareMode, lpSecurityAttributes,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
81 dwCreationDisposition,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
82 dwFlagsAndAttributes, hTemplateFile);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
83 Py_END_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
84
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
85 if (handle == INVALID_HANDLE_VALUE)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
86 return PyErr_SetFromWindowsErr(0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
87
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
88 return Py_BuildValue(F_HANDLE, handle);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
89 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
90
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
91 static PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
92 win32_CreateNamedPipe(PyObject *self, PyObject *args)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
93 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
94 LPCTSTR lpName;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
95 DWORD dwOpenMode;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
96 DWORD dwPipeMode;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
97 DWORD nMaxInstances;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
98 DWORD nOutBufferSize;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
99 DWORD nInBufferSize;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
100 DWORD nDefaultTimeOut;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
101 LPSECURITY_ATTRIBUTES lpSecurityAttributes;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
102 HANDLE handle;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
103
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
104 if (!PyArg_ParseTuple(args, "s" F_DWORD F_DWORD F_DWORD
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
105 F_DWORD F_DWORD F_DWORD F_POINTER,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
106 &lpName, &dwOpenMode, &dwPipeMode,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
107 &nMaxInstances, &nOutBufferSize,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
108 &nInBufferSize, &nDefaultTimeOut,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
109 &lpSecurityAttributes))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
110 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
111
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
112 Py_BEGIN_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
113 handle = CreateNamedPipe(lpName, dwOpenMode, dwPipeMode,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
114 nMaxInstances, nOutBufferSize,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
115 nInBufferSize, nDefaultTimeOut,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
116 lpSecurityAttributes);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
117 Py_END_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
118
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
119 if (handle == INVALID_HANDLE_VALUE)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
120 return PyErr_SetFromWindowsErr(0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
121
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
122 return Py_BuildValue(F_HANDLE, handle);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
123 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
124
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
125 static PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
126 win32_ExitProcess(PyObject *self, PyObject *args)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
127 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
128 UINT uExitCode;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
129
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
130 if (!PyArg_ParseTuple(args, "I", &uExitCode))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
131 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
132
52605
e2818b9f964b Merged revisions 70908 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
133 #if defined(Py_DEBUG)
e2818b9f964b Merged revisions 70908 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
134 SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOALIGNMENTFAULTEXCEPT|SEM_NOGPFAULTERRORBOX|SEM_NOOPENFILEERRORBOX);
e2818b9f964b Merged revisions 70908 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
135 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
e2818b9f964b Merged revisions 70908 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
136 #endif
e2818b9f964b Merged revisions 70908 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
137
e2818b9f964b Merged revisions 70908 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents: 47694
diff changeset
138
47694
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
139 ExitProcess(uExitCode);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
140
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
141 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
142 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
143
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
144 static PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
145 win32_GetLastError(PyObject *self, PyObject *args)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
146 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
147 return Py_BuildValue(F_DWORD, GetLastError());
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
148 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
149
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
150 static PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
151 win32_OpenProcess(PyObject *self, PyObject *args)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
152 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
153 DWORD dwDesiredAccess;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
154 BOOL bInheritHandle;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
155 DWORD dwProcessId;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
156 HANDLE handle;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
157
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
158 if (!PyArg_ParseTuple(args, F_DWORD "i" F_DWORD,
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
159 &dwDesiredAccess, &bInheritHandle, &dwProcessId))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
160 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
161
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
162 handle = OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
163 if (handle == NULL)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
164 return PyErr_SetFromWindowsErr(0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
165
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
166 return Py_BuildValue(F_HANDLE, handle);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
167 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
168
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
169 static PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
170 win32_SetNamedPipeHandleState(PyObject *self, PyObject *args)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
171 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
172 HANDLE hNamedPipe;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
173 PyObject *oArgs[3];
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
174 DWORD dwArgs[3], *pArgs[3] = {NULL, NULL, NULL};
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
175 int i;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
176
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
177 if (!PyArg_ParseTuple(args, F_HANDLE "OOO",
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
178 &hNamedPipe, &oArgs[0], &oArgs[1], &oArgs[2]))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
179 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
180
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
181 PyErr_Clear();
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
182
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
183 for (i = 0 ; i < 3 ; i++) {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
184 if (oArgs[i] != Py_None) {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
185 dwArgs[i] = PyInt_AsUnsignedLongMask(oArgs[i]);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
186 if (PyErr_Occurred())
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
187 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
188 pArgs[i] = &dwArgs[i];
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
189 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
190 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
191
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
192 if (!SetNamedPipeHandleState(hNamedPipe, pArgs[0], pArgs[1], pArgs[2]))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
193 return PyErr_SetFromWindowsErr(0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
194
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
195 Py_RETURN_NONE;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
196 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
197
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
198 static PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
199 win32_WaitNamedPipe(PyObject *self, PyObject *args)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
200 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
201 LPCTSTR lpNamedPipeName;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
202 DWORD nTimeOut;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
203 BOOL success;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
204
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
205 if (!PyArg_ParseTuple(args, "s" F_DWORD, &lpNamedPipeName, &nTimeOut))
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
206 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
207
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
208 Py_BEGIN_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
209 success = WaitNamedPipe(lpNamedPipeName, nTimeOut);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
210 Py_END_ALLOW_THREADS
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
211
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
212 if (!success)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
213 return PyErr_SetFromWindowsErr(0);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
214
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
215 Py_RETURN_NONE;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
216 }
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
217
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
218 static PyMethodDef win32_methods[] = {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
219 WIN32_FUNCTION(CloseHandle),
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
220 WIN32_FUNCTION(GetLastError),
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
221 WIN32_FUNCTION(OpenProcess),
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
222 WIN32_FUNCTION(ExitProcess),
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
223 WIN32_FUNCTION(ConnectNamedPipe),
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
224 WIN32_FUNCTION(CreateFile),
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
225 WIN32_FUNCTION(CreateNamedPipe),
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
226 WIN32_FUNCTION(SetNamedPipeHandleState),
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
227 WIN32_FUNCTION(WaitNamedPipe),
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
228 {NULL}
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
229 };
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
230
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
231
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
232 PyTypeObject Win32Type = {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
233 PyVarObject_HEAD_INIT(NULL, 0)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
234 };
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
235
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
236
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
237 PyObject *
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
238 create_win32_namespace(void)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
239 {
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
240 Win32Type.tp_name = "_multiprocessing.win32";
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
241 Win32Type.tp_methods = win32_methods;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
242 if (PyType_Ready(&Win32Type) < 0)
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
243 return NULL;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
244 Py_INCREF(&Win32Type);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
245
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
246 WIN32_CONSTANT(F_DWORD, ERROR_ALREADY_EXISTS);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
247 WIN32_CONSTANT(F_DWORD, ERROR_PIPE_BUSY);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
248 WIN32_CONSTANT(F_DWORD, ERROR_PIPE_CONNECTED);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
249 WIN32_CONSTANT(F_DWORD, ERROR_SEM_TIMEOUT);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
250 WIN32_CONSTANT(F_DWORD, GENERIC_READ);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
251 WIN32_CONSTANT(F_DWORD, GENERIC_WRITE);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
252 WIN32_CONSTANT(F_DWORD, INFINITE);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
253 WIN32_CONSTANT(F_DWORD, NMPWAIT_WAIT_FOREVER);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
254 WIN32_CONSTANT(F_DWORD, OPEN_EXISTING);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
255 WIN32_CONSTANT(F_DWORD, PIPE_ACCESS_DUPLEX);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
256 WIN32_CONSTANT(F_DWORD, PIPE_ACCESS_INBOUND);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
257 WIN32_CONSTANT(F_DWORD, PIPE_READMODE_MESSAGE);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
258 WIN32_CONSTANT(F_DWORD, PIPE_TYPE_MESSAGE);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
259 WIN32_CONSTANT(F_DWORD, PIPE_UNLIMITED_INSTANCES);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
260 WIN32_CONSTANT(F_DWORD, PIPE_WAIT);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
261 WIN32_CONSTANT(F_DWORD, PROCESS_ALL_ACCESS);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
262
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
263 WIN32_CONSTANT("i", NULL);
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
264
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
265 return (PyObject*)&Win32Type;
af8873df0322 convert multiprocessing to unix line endings
Benjamin Peterson <benjamin@python.org>
parents: 47595
diff changeset
266 }