Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(_winapi_Overlapped_GetOverlappedResult__doc__, |
| 6 | "GetOverlappedResult($self, wait, /)\n" |
| 7 | "--\n" |
| 8 | "\n"); |
| 9 | |
| 10 | #define _WINAPI_OVERLAPPED_GETOVERLAPPEDRESULT_METHODDEF \ |
| 11 | {"GetOverlappedResult", (PyCFunction)_winapi_Overlapped_GetOverlappedResult, METH_O, _winapi_Overlapped_GetOverlappedResult__doc__}, |
| 12 | |
| 13 | static PyObject * |
| 14 | _winapi_Overlapped_GetOverlappedResult_impl(OverlappedObject *self, int wait); |
| 15 | |
| 16 | static PyObject * |
| 17 | _winapi_Overlapped_GetOverlappedResult(OverlappedObject *self, PyObject *arg) |
| 18 | { |
| 19 | PyObject *return_value = NULL; |
| 20 | int wait; |
| 21 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 22 | if (!PyArg_Parse(arg, "p:GetOverlappedResult", &wait)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 23 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 24 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 25 | return_value = _winapi_Overlapped_GetOverlappedResult_impl(self, wait); |
| 26 | |
| 27 | exit: |
| 28 | return return_value; |
| 29 | } |
| 30 | |
| 31 | PyDoc_STRVAR(_winapi_Overlapped_getbuffer__doc__, |
| 32 | "getbuffer($self, /)\n" |
| 33 | "--\n" |
| 34 | "\n"); |
| 35 | |
| 36 | #define _WINAPI_OVERLAPPED_GETBUFFER_METHODDEF \ |
| 37 | {"getbuffer", (PyCFunction)_winapi_Overlapped_getbuffer, METH_NOARGS, _winapi_Overlapped_getbuffer__doc__}, |
| 38 | |
| 39 | static PyObject * |
| 40 | _winapi_Overlapped_getbuffer_impl(OverlappedObject *self); |
| 41 | |
| 42 | static PyObject * |
| 43 | _winapi_Overlapped_getbuffer(OverlappedObject *self, PyObject *Py_UNUSED(ignored)) |
| 44 | { |
| 45 | return _winapi_Overlapped_getbuffer_impl(self); |
| 46 | } |
| 47 | |
| 48 | PyDoc_STRVAR(_winapi_Overlapped_cancel__doc__, |
| 49 | "cancel($self, /)\n" |
| 50 | "--\n" |
| 51 | "\n"); |
| 52 | |
| 53 | #define _WINAPI_OVERLAPPED_CANCEL_METHODDEF \ |
| 54 | {"cancel", (PyCFunction)_winapi_Overlapped_cancel, METH_NOARGS, _winapi_Overlapped_cancel__doc__}, |
| 55 | |
| 56 | static PyObject * |
| 57 | _winapi_Overlapped_cancel_impl(OverlappedObject *self); |
| 58 | |
| 59 | static PyObject * |
| 60 | _winapi_Overlapped_cancel(OverlappedObject *self, PyObject *Py_UNUSED(ignored)) |
| 61 | { |
| 62 | return _winapi_Overlapped_cancel_impl(self); |
| 63 | } |
| 64 | |
| 65 | PyDoc_STRVAR(_winapi_CloseHandle__doc__, |
| 66 | "CloseHandle($module, handle, /)\n" |
| 67 | "--\n" |
| 68 | "\n" |
| 69 | "Close handle."); |
| 70 | |
| 71 | #define _WINAPI_CLOSEHANDLE_METHODDEF \ |
| 72 | {"CloseHandle", (PyCFunction)_winapi_CloseHandle, METH_O, _winapi_CloseHandle__doc__}, |
| 73 | |
| 74 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 75 | _winapi_CloseHandle_impl(PyObject *module, HANDLE handle); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 76 | |
| 77 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 78 | _winapi_CloseHandle(PyObject *module, PyObject *arg) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 79 | { |
| 80 | PyObject *return_value = NULL; |
| 81 | HANDLE handle; |
| 82 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 83 | if (!PyArg_Parse(arg, "" F_HANDLE ":CloseHandle", &handle)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 84 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 85 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 86 | return_value = _winapi_CloseHandle_impl(module, handle); |
| 87 | |
| 88 | exit: |
| 89 | return return_value; |
| 90 | } |
| 91 | |
| 92 | PyDoc_STRVAR(_winapi_ConnectNamedPipe__doc__, |
| 93 | "ConnectNamedPipe($module, /, handle, overlapped=False)\n" |
| 94 | "--\n" |
| 95 | "\n"); |
| 96 | |
| 97 | #define _WINAPI_CONNECTNAMEDPIPE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 98 | {"ConnectNamedPipe", (PyCFunction)_winapi_ConnectNamedPipe, METH_FASTCALL, _winapi_ConnectNamedPipe__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 99 | |
| 100 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 101 | _winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 102 | int use_overlapped); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 103 | |
| 104 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 105 | _winapi_ConnectNamedPipe(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 106 | { |
| 107 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 108 | static const char * const _keywords[] = {"handle", "overlapped", NULL}; |
| 109 | static _PyArg_Parser _parser = {"" F_HANDLE "|i:ConnectNamedPipe", _keywords, 0}; |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 110 | HANDLE handle; |
| 111 | int use_overlapped = 0; |
| 112 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 113 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 114 | &handle, &use_overlapped)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 115 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 116 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 117 | return_value = _winapi_ConnectNamedPipe_impl(module, handle, use_overlapped); |
| 118 | |
| 119 | exit: |
| 120 | return return_value; |
| 121 | } |
| 122 | |
| 123 | PyDoc_STRVAR(_winapi_CreateFile__doc__, |
| 124 | "CreateFile($module, file_name, desired_access, share_mode,\n" |
| 125 | " security_attributes, creation_disposition,\n" |
| 126 | " flags_and_attributes, template_file, /)\n" |
| 127 | "--\n" |
| 128 | "\n"); |
| 129 | |
| 130 | #define _WINAPI_CREATEFILE_METHODDEF \ |
| 131 | {"CreateFile", (PyCFunction)_winapi_CreateFile, METH_VARARGS, _winapi_CreateFile__doc__}, |
| 132 | |
| 133 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 134 | _winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 135 | DWORD desired_access, DWORD share_mode, |
| 136 | LPSECURITY_ATTRIBUTES security_attributes, |
| 137 | DWORD creation_disposition, |
| 138 | DWORD flags_and_attributes, HANDLE template_file); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 139 | |
| 140 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 141 | _winapi_CreateFile(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 142 | { |
| 143 | PyObject *return_value = NULL; |
| 144 | LPCTSTR file_name; |
| 145 | DWORD desired_access; |
| 146 | DWORD share_mode; |
| 147 | LPSECURITY_ATTRIBUTES security_attributes; |
| 148 | DWORD creation_disposition; |
| 149 | DWORD flags_and_attributes; |
| 150 | HANDLE template_file; |
| 151 | HANDLE _return_value; |
| 152 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 153 | if (!PyArg_ParseTuple(args, "skk" F_POINTER "kk" F_HANDLE ":CreateFile", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 154 | &file_name, &desired_access, &share_mode, &security_attributes, &creation_disposition, &flags_and_attributes, &template_file)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 155 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 156 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 157 | _return_value = _winapi_CreateFile_impl(module, file_name, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, template_file); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 158 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 159 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 160 | } |
| 161 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 162 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 163 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 164 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 165 | |
| 166 | exit: |
| 167 | return return_value; |
| 168 | } |
| 169 | |
| 170 | PyDoc_STRVAR(_winapi_CreateJunction__doc__, |
| 171 | "CreateJunction($module, src_path, dst_path, /)\n" |
| 172 | "--\n" |
| 173 | "\n"); |
| 174 | |
| 175 | #define _WINAPI_CREATEJUNCTION_METHODDEF \ |
| 176 | {"CreateJunction", (PyCFunction)_winapi_CreateJunction, METH_VARARGS, _winapi_CreateJunction__doc__}, |
| 177 | |
| 178 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 179 | _winapi_CreateJunction_impl(PyObject *module, LPWSTR src_path, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 180 | LPWSTR dst_path); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 181 | |
| 182 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 183 | _winapi_CreateJunction(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 184 | { |
| 185 | PyObject *return_value = NULL; |
| 186 | LPWSTR src_path; |
| 187 | LPWSTR dst_path; |
| 188 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 189 | if (!PyArg_ParseTuple(args, "uu:CreateJunction", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 190 | &src_path, &dst_path)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 191 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 192 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 193 | return_value = _winapi_CreateJunction_impl(module, src_path, dst_path); |
| 194 | |
| 195 | exit: |
| 196 | return return_value; |
| 197 | } |
| 198 | |
| 199 | PyDoc_STRVAR(_winapi_CreateNamedPipe__doc__, |
| 200 | "CreateNamedPipe($module, name, open_mode, pipe_mode, max_instances,\n" |
| 201 | " out_buffer_size, in_buffer_size, default_timeout,\n" |
| 202 | " security_attributes, /)\n" |
| 203 | "--\n" |
| 204 | "\n"); |
| 205 | |
| 206 | #define _WINAPI_CREATENAMEDPIPE_METHODDEF \ |
| 207 | {"CreateNamedPipe", (PyCFunction)_winapi_CreateNamedPipe, METH_VARARGS, _winapi_CreateNamedPipe__doc__}, |
| 208 | |
| 209 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 210 | _winapi_CreateNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD open_mode, |
| 211 | DWORD pipe_mode, DWORD max_instances, |
| 212 | DWORD out_buffer_size, DWORD in_buffer_size, |
| 213 | DWORD default_timeout, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 214 | LPSECURITY_ATTRIBUTES security_attributes); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 215 | |
| 216 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 217 | _winapi_CreateNamedPipe(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 218 | { |
| 219 | PyObject *return_value = NULL; |
| 220 | LPCTSTR name; |
| 221 | DWORD open_mode; |
| 222 | DWORD pipe_mode; |
| 223 | DWORD max_instances; |
| 224 | DWORD out_buffer_size; |
| 225 | DWORD in_buffer_size; |
| 226 | DWORD default_timeout; |
| 227 | LPSECURITY_ATTRIBUTES security_attributes; |
| 228 | HANDLE _return_value; |
| 229 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 230 | if (!PyArg_ParseTuple(args, "skkkkkk" F_POINTER ":CreateNamedPipe", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 231 | &name, &open_mode, &pipe_mode, &max_instances, &out_buffer_size, &in_buffer_size, &default_timeout, &security_attributes)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 232 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 233 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 234 | _return_value = _winapi_CreateNamedPipe_impl(module, name, open_mode, pipe_mode, max_instances, out_buffer_size, in_buffer_size, default_timeout, security_attributes); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 235 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 236 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 237 | } |
| 238 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 239 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 240 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 241 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 242 | |
| 243 | exit: |
| 244 | return return_value; |
| 245 | } |
| 246 | |
| 247 | PyDoc_STRVAR(_winapi_CreatePipe__doc__, |
| 248 | "CreatePipe($module, pipe_attrs, size, /)\n" |
| 249 | "--\n" |
| 250 | "\n" |
| 251 | "Create an anonymous pipe.\n" |
| 252 | "\n" |
| 253 | " pipe_attrs\n" |
| 254 | " Ignored internally, can be None.\n" |
| 255 | "\n" |
| 256 | "Returns a 2-tuple of handles, to the read and write ends of the pipe."); |
| 257 | |
| 258 | #define _WINAPI_CREATEPIPE_METHODDEF \ |
| 259 | {"CreatePipe", (PyCFunction)_winapi_CreatePipe, METH_VARARGS, _winapi_CreatePipe__doc__}, |
| 260 | |
| 261 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 262 | _winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, DWORD size); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 263 | |
| 264 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 265 | _winapi_CreatePipe(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 266 | { |
| 267 | PyObject *return_value = NULL; |
| 268 | PyObject *pipe_attrs; |
| 269 | DWORD size; |
| 270 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 271 | if (!PyArg_ParseTuple(args, "Ok:CreatePipe", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 272 | &pipe_attrs, &size)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 273 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 274 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 275 | return_value = _winapi_CreatePipe_impl(module, pipe_attrs, size); |
| 276 | |
| 277 | exit: |
| 278 | return return_value; |
| 279 | } |
| 280 | |
| 281 | PyDoc_STRVAR(_winapi_CreateProcess__doc__, |
| 282 | "CreateProcess($module, application_name, command_line, proc_attrs,\n" |
| 283 | " thread_attrs, inherit_handles, creation_flags,\n" |
| 284 | " env_mapping, current_directory, startup_info, /)\n" |
| 285 | "--\n" |
| 286 | "\n" |
| 287 | "Create a new process and its primary thread.\n" |
| 288 | "\n" |
| 289 | " proc_attrs\n" |
| 290 | " Ignored internally, can be None.\n" |
| 291 | " thread_attrs\n" |
| 292 | " Ignored internally, can be None.\n" |
| 293 | "\n" |
| 294 | "The return value is a tuple of the process handle, thread handle,\n" |
| 295 | "process ID, and thread ID."); |
| 296 | |
| 297 | #define _WINAPI_CREATEPROCESS_METHODDEF \ |
| 298 | {"CreateProcess", (PyCFunction)_winapi_CreateProcess, METH_VARARGS, _winapi_CreateProcess__doc__}, |
| 299 | |
| 300 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 301 | _winapi_CreateProcess_impl(PyObject *module, Py_UNICODE *application_name, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 302 | Py_UNICODE *command_line, PyObject *proc_attrs, |
| 303 | PyObject *thread_attrs, BOOL inherit_handles, |
| 304 | DWORD creation_flags, PyObject *env_mapping, |
| 305 | Py_UNICODE *current_directory, |
| 306 | PyObject *startup_info); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 307 | |
| 308 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 309 | _winapi_CreateProcess(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 310 | { |
| 311 | PyObject *return_value = NULL; |
| 312 | Py_UNICODE *application_name; |
| 313 | Py_UNICODE *command_line; |
| 314 | PyObject *proc_attrs; |
| 315 | PyObject *thread_attrs; |
| 316 | BOOL inherit_handles; |
| 317 | DWORD creation_flags; |
| 318 | PyObject *env_mapping; |
| 319 | Py_UNICODE *current_directory; |
| 320 | PyObject *startup_info; |
| 321 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 322 | if (!PyArg_ParseTuple(args, "ZZOOikOZO:CreateProcess", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 323 | &application_name, &command_line, &proc_attrs, &thread_attrs, &inherit_handles, &creation_flags, &env_mapping, ¤t_directory, &startup_info)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 324 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 325 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 326 | return_value = _winapi_CreateProcess_impl(module, application_name, command_line, proc_attrs, thread_attrs, inherit_handles, creation_flags, env_mapping, current_directory, startup_info); |
| 327 | |
| 328 | exit: |
| 329 | return return_value; |
| 330 | } |
| 331 | |
| 332 | PyDoc_STRVAR(_winapi_DuplicateHandle__doc__, |
| 333 | "DuplicateHandle($module, source_process_handle, source_handle,\n" |
| 334 | " target_process_handle, desired_access, inherit_handle,\n" |
| 335 | " options=0, /)\n" |
| 336 | "--\n" |
| 337 | "\n" |
| 338 | "Return a duplicate handle object.\n" |
| 339 | "\n" |
| 340 | "The duplicate handle refers to the same object as the original\n" |
| 341 | "handle. Therefore, any changes to the object are reflected\n" |
| 342 | "through both handles."); |
| 343 | |
| 344 | #define _WINAPI_DUPLICATEHANDLE_METHODDEF \ |
| 345 | {"DuplicateHandle", (PyCFunction)_winapi_DuplicateHandle, METH_VARARGS, _winapi_DuplicateHandle__doc__}, |
| 346 | |
| 347 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 348 | _winapi_DuplicateHandle_impl(PyObject *module, HANDLE source_process_handle, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 349 | HANDLE source_handle, |
| 350 | HANDLE target_process_handle, |
| 351 | DWORD desired_access, BOOL inherit_handle, |
| 352 | DWORD options); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 353 | |
| 354 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 355 | _winapi_DuplicateHandle(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 356 | { |
| 357 | PyObject *return_value = NULL; |
| 358 | HANDLE source_process_handle; |
| 359 | HANDLE source_handle; |
| 360 | HANDLE target_process_handle; |
| 361 | DWORD desired_access; |
| 362 | BOOL inherit_handle; |
| 363 | DWORD options = 0; |
| 364 | HANDLE _return_value; |
| 365 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 366 | if (!PyArg_ParseTuple(args, "" F_HANDLE "" F_HANDLE "" F_HANDLE "ki|k:DuplicateHandle", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 367 | &source_process_handle, &source_handle, &target_process_handle, &desired_access, &inherit_handle, &options)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 368 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 369 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 370 | _return_value = _winapi_DuplicateHandle_impl(module, source_process_handle, source_handle, target_process_handle, desired_access, inherit_handle, options); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 371 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 372 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 373 | } |
| 374 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 375 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 376 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 377 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 378 | |
| 379 | exit: |
| 380 | return return_value; |
| 381 | } |
| 382 | |
| 383 | PyDoc_STRVAR(_winapi_ExitProcess__doc__, |
| 384 | "ExitProcess($module, ExitCode, /)\n" |
| 385 | "--\n" |
| 386 | "\n"); |
| 387 | |
| 388 | #define _WINAPI_EXITPROCESS_METHODDEF \ |
| 389 | {"ExitProcess", (PyCFunction)_winapi_ExitProcess, METH_O, _winapi_ExitProcess__doc__}, |
| 390 | |
| 391 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 392 | _winapi_ExitProcess_impl(PyObject *module, UINT ExitCode); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 393 | |
| 394 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 395 | _winapi_ExitProcess(PyObject *module, PyObject *arg) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 396 | { |
| 397 | PyObject *return_value = NULL; |
| 398 | UINT ExitCode; |
| 399 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 400 | if (!PyArg_Parse(arg, "I:ExitProcess", &ExitCode)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 401 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 402 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 403 | return_value = _winapi_ExitProcess_impl(module, ExitCode); |
| 404 | |
| 405 | exit: |
| 406 | return return_value; |
| 407 | } |
| 408 | |
| 409 | PyDoc_STRVAR(_winapi_GetCurrentProcess__doc__, |
| 410 | "GetCurrentProcess($module, /)\n" |
| 411 | "--\n" |
| 412 | "\n" |
| 413 | "Return a handle object for the current process."); |
| 414 | |
| 415 | #define _WINAPI_GETCURRENTPROCESS_METHODDEF \ |
| 416 | {"GetCurrentProcess", (PyCFunction)_winapi_GetCurrentProcess, METH_NOARGS, _winapi_GetCurrentProcess__doc__}, |
| 417 | |
| 418 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 419 | _winapi_GetCurrentProcess_impl(PyObject *module); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 420 | |
| 421 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 422 | _winapi_GetCurrentProcess(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 423 | { |
| 424 | PyObject *return_value = NULL; |
| 425 | HANDLE _return_value; |
| 426 | |
| 427 | _return_value = _winapi_GetCurrentProcess_impl(module); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 428 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 429 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 430 | } |
| 431 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 432 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 433 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 434 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 435 | |
| 436 | exit: |
| 437 | return return_value; |
| 438 | } |
| 439 | |
| 440 | PyDoc_STRVAR(_winapi_GetExitCodeProcess__doc__, |
| 441 | "GetExitCodeProcess($module, process, /)\n" |
| 442 | "--\n" |
| 443 | "\n" |
| 444 | "Return the termination status of the specified process."); |
| 445 | |
| 446 | #define _WINAPI_GETEXITCODEPROCESS_METHODDEF \ |
| 447 | {"GetExitCodeProcess", (PyCFunction)_winapi_GetExitCodeProcess, METH_O, _winapi_GetExitCodeProcess__doc__}, |
| 448 | |
| 449 | static DWORD |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 450 | _winapi_GetExitCodeProcess_impl(PyObject *module, HANDLE process); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 451 | |
| 452 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 453 | _winapi_GetExitCodeProcess(PyObject *module, PyObject *arg) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 454 | { |
| 455 | PyObject *return_value = NULL; |
| 456 | HANDLE process; |
| 457 | DWORD _return_value; |
| 458 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 459 | if (!PyArg_Parse(arg, "" F_HANDLE ":GetExitCodeProcess", &process)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 460 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 461 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 462 | _return_value = _winapi_GetExitCodeProcess_impl(module, process); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 463 | if ((_return_value == DWORD_MAX) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 464 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 465 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 466 | return_value = Py_BuildValue("k", _return_value); |
| 467 | |
| 468 | exit: |
| 469 | return return_value; |
| 470 | } |
| 471 | |
| 472 | PyDoc_STRVAR(_winapi_GetLastError__doc__, |
| 473 | "GetLastError($module, /)\n" |
| 474 | "--\n" |
| 475 | "\n"); |
| 476 | |
| 477 | #define _WINAPI_GETLASTERROR_METHODDEF \ |
| 478 | {"GetLastError", (PyCFunction)_winapi_GetLastError, METH_NOARGS, _winapi_GetLastError__doc__}, |
| 479 | |
| 480 | static DWORD |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 481 | _winapi_GetLastError_impl(PyObject *module); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 482 | |
| 483 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 484 | _winapi_GetLastError(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 485 | { |
| 486 | PyObject *return_value = NULL; |
| 487 | DWORD _return_value; |
| 488 | |
| 489 | _return_value = _winapi_GetLastError_impl(module); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 490 | if ((_return_value == DWORD_MAX) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 491 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 492 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 493 | return_value = Py_BuildValue("k", _return_value); |
| 494 | |
| 495 | exit: |
| 496 | return return_value; |
| 497 | } |
| 498 | |
| 499 | PyDoc_STRVAR(_winapi_GetModuleFileName__doc__, |
| 500 | "GetModuleFileName($module, module_handle, /)\n" |
| 501 | "--\n" |
| 502 | "\n" |
| 503 | "Return the fully-qualified path for the file that contains module.\n" |
| 504 | "\n" |
| 505 | "The module must have been loaded by the current process.\n" |
| 506 | "\n" |
| 507 | "The module parameter should be a handle to the loaded module\n" |
| 508 | "whose path is being requested. If this parameter is 0,\n" |
| 509 | "GetModuleFileName retrieves the path of the executable file\n" |
| 510 | "of the current process."); |
| 511 | |
| 512 | #define _WINAPI_GETMODULEFILENAME_METHODDEF \ |
| 513 | {"GetModuleFileName", (PyCFunction)_winapi_GetModuleFileName, METH_O, _winapi_GetModuleFileName__doc__}, |
| 514 | |
| 515 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 516 | _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 517 | |
| 518 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 519 | _winapi_GetModuleFileName(PyObject *module, PyObject *arg) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 520 | { |
| 521 | PyObject *return_value = NULL; |
| 522 | HMODULE module_handle; |
| 523 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 524 | if (!PyArg_Parse(arg, "" F_HANDLE ":GetModuleFileName", &module_handle)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 525 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 526 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 527 | return_value = _winapi_GetModuleFileName_impl(module, module_handle); |
| 528 | |
| 529 | exit: |
| 530 | return return_value; |
| 531 | } |
| 532 | |
| 533 | PyDoc_STRVAR(_winapi_GetStdHandle__doc__, |
| 534 | "GetStdHandle($module, std_handle, /)\n" |
| 535 | "--\n" |
| 536 | "\n" |
| 537 | "Return a handle to the specified standard device.\n" |
| 538 | "\n" |
| 539 | " std_handle\n" |
| 540 | " One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE.\n" |
| 541 | "\n" |
| 542 | "The integer associated with the handle object is returned."); |
| 543 | |
| 544 | #define _WINAPI_GETSTDHANDLE_METHODDEF \ |
| 545 | {"GetStdHandle", (PyCFunction)_winapi_GetStdHandle, METH_O, _winapi_GetStdHandle__doc__}, |
| 546 | |
| 547 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 548 | _winapi_GetStdHandle_impl(PyObject *module, DWORD std_handle); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 549 | |
| 550 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 551 | _winapi_GetStdHandle(PyObject *module, PyObject *arg) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 552 | { |
| 553 | PyObject *return_value = NULL; |
| 554 | DWORD std_handle; |
| 555 | HANDLE _return_value; |
| 556 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 557 | if (!PyArg_Parse(arg, "k:GetStdHandle", &std_handle)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 558 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 559 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 560 | _return_value = _winapi_GetStdHandle_impl(module, std_handle); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 561 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 562 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 563 | } |
| 564 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 565 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 566 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 567 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 568 | |
| 569 | exit: |
| 570 | return return_value; |
| 571 | } |
| 572 | |
| 573 | PyDoc_STRVAR(_winapi_GetVersion__doc__, |
| 574 | "GetVersion($module, /)\n" |
| 575 | "--\n" |
| 576 | "\n" |
| 577 | "Return the version number of the current operating system."); |
| 578 | |
| 579 | #define _WINAPI_GETVERSION_METHODDEF \ |
| 580 | {"GetVersion", (PyCFunction)_winapi_GetVersion, METH_NOARGS, _winapi_GetVersion__doc__}, |
| 581 | |
| 582 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 583 | _winapi_GetVersion_impl(PyObject *module); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 584 | |
| 585 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 586 | _winapi_GetVersion(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 587 | { |
| 588 | PyObject *return_value = NULL; |
| 589 | long _return_value; |
| 590 | |
| 591 | _return_value = _winapi_GetVersion_impl(module); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 592 | if ((_return_value == -1) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 593 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 594 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 595 | return_value = PyLong_FromLong(_return_value); |
| 596 | |
| 597 | exit: |
| 598 | return return_value; |
| 599 | } |
| 600 | |
| 601 | PyDoc_STRVAR(_winapi_OpenProcess__doc__, |
| 602 | "OpenProcess($module, desired_access, inherit_handle, process_id, /)\n" |
| 603 | "--\n" |
| 604 | "\n"); |
| 605 | |
| 606 | #define _WINAPI_OPENPROCESS_METHODDEF \ |
| 607 | {"OpenProcess", (PyCFunction)_winapi_OpenProcess, METH_VARARGS, _winapi_OpenProcess__doc__}, |
| 608 | |
| 609 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 610 | _winapi_OpenProcess_impl(PyObject *module, DWORD desired_access, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 611 | BOOL inherit_handle, DWORD process_id); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 612 | |
| 613 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 614 | _winapi_OpenProcess(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 615 | { |
| 616 | PyObject *return_value = NULL; |
| 617 | DWORD desired_access; |
| 618 | BOOL inherit_handle; |
| 619 | DWORD process_id; |
| 620 | HANDLE _return_value; |
| 621 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 622 | if (!PyArg_ParseTuple(args, "kik:OpenProcess", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 623 | &desired_access, &inherit_handle, &process_id)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 624 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 625 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 626 | _return_value = _winapi_OpenProcess_impl(module, desired_access, inherit_handle, process_id); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 627 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 628 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 629 | } |
| 630 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 631 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 632 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 633 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 634 | |
| 635 | exit: |
| 636 | return return_value; |
| 637 | } |
| 638 | |
| 639 | PyDoc_STRVAR(_winapi_PeekNamedPipe__doc__, |
| 640 | "PeekNamedPipe($module, handle, size=0, /)\n" |
| 641 | "--\n" |
| 642 | "\n"); |
| 643 | |
| 644 | #define _WINAPI_PEEKNAMEDPIPE_METHODDEF \ |
| 645 | {"PeekNamedPipe", (PyCFunction)_winapi_PeekNamedPipe, METH_VARARGS, _winapi_PeekNamedPipe__doc__}, |
| 646 | |
| 647 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 648 | _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 649 | |
| 650 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 651 | _winapi_PeekNamedPipe(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 652 | { |
| 653 | PyObject *return_value = NULL; |
| 654 | HANDLE handle; |
| 655 | int size = 0; |
| 656 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 657 | if (!PyArg_ParseTuple(args, "" F_HANDLE "|i:PeekNamedPipe", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 658 | &handle, &size)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 659 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 660 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 661 | return_value = _winapi_PeekNamedPipe_impl(module, handle, size); |
| 662 | |
| 663 | exit: |
| 664 | return return_value; |
| 665 | } |
| 666 | |
| 667 | PyDoc_STRVAR(_winapi_ReadFile__doc__, |
| 668 | "ReadFile($module, /, handle, size, overlapped=False)\n" |
| 669 | "--\n" |
| 670 | "\n"); |
| 671 | |
| 672 | #define _WINAPI_READFILE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 673 | {"ReadFile", (PyCFunction)_winapi_ReadFile, METH_FASTCALL, _winapi_ReadFile__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 674 | |
| 675 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 676 | _winapi_ReadFile_impl(PyObject *module, HANDLE handle, int size, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 677 | int use_overlapped); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 678 | |
| 679 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 680 | _winapi_ReadFile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 681 | { |
| 682 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 683 | static const char * const _keywords[] = {"handle", "size", "overlapped", NULL}; |
| 684 | static _PyArg_Parser _parser = {"" F_HANDLE "i|i:ReadFile", _keywords, 0}; |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 685 | HANDLE handle; |
| 686 | int size; |
| 687 | int use_overlapped = 0; |
| 688 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 689 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 690 | &handle, &size, &use_overlapped)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 691 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 692 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 693 | return_value = _winapi_ReadFile_impl(module, handle, size, use_overlapped); |
| 694 | |
| 695 | exit: |
| 696 | return return_value; |
| 697 | } |
| 698 | |
| 699 | PyDoc_STRVAR(_winapi_SetNamedPipeHandleState__doc__, |
| 700 | "SetNamedPipeHandleState($module, named_pipe, mode,\n" |
| 701 | " max_collection_count, collect_data_timeout, /)\n" |
| 702 | "--\n" |
| 703 | "\n"); |
| 704 | |
| 705 | #define _WINAPI_SETNAMEDPIPEHANDLESTATE_METHODDEF \ |
| 706 | {"SetNamedPipeHandleState", (PyCFunction)_winapi_SetNamedPipeHandleState, METH_VARARGS, _winapi_SetNamedPipeHandleState__doc__}, |
| 707 | |
| 708 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 709 | _winapi_SetNamedPipeHandleState_impl(PyObject *module, HANDLE named_pipe, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 710 | PyObject *mode, |
| 711 | PyObject *max_collection_count, |
| 712 | PyObject *collect_data_timeout); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 713 | |
| 714 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 715 | _winapi_SetNamedPipeHandleState(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 716 | { |
| 717 | PyObject *return_value = NULL; |
| 718 | HANDLE named_pipe; |
| 719 | PyObject *mode; |
| 720 | PyObject *max_collection_count; |
| 721 | PyObject *collect_data_timeout; |
| 722 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 723 | if (!PyArg_ParseTuple(args, "" F_HANDLE "OOO:SetNamedPipeHandleState", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 724 | &named_pipe, &mode, &max_collection_count, &collect_data_timeout)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 725 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 726 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 727 | return_value = _winapi_SetNamedPipeHandleState_impl(module, named_pipe, mode, max_collection_count, collect_data_timeout); |
| 728 | |
| 729 | exit: |
| 730 | return return_value; |
| 731 | } |
| 732 | |
| 733 | PyDoc_STRVAR(_winapi_TerminateProcess__doc__, |
| 734 | "TerminateProcess($module, handle, exit_code, /)\n" |
| 735 | "--\n" |
| 736 | "\n" |
| 737 | "Terminate the specified process and all of its threads."); |
| 738 | |
| 739 | #define _WINAPI_TERMINATEPROCESS_METHODDEF \ |
| 740 | {"TerminateProcess", (PyCFunction)_winapi_TerminateProcess, METH_VARARGS, _winapi_TerminateProcess__doc__}, |
| 741 | |
| 742 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 743 | _winapi_TerminateProcess_impl(PyObject *module, HANDLE handle, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 744 | UINT exit_code); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 745 | |
| 746 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 747 | _winapi_TerminateProcess(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 748 | { |
| 749 | PyObject *return_value = NULL; |
| 750 | HANDLE handle; |
| 751 | UINT exit_code; |
| 752 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 753 | if (!PyArg_ParseTuple(args, "" F_HANDLE "I:TerminateProcess", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 754 | &handle, &exit_code)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 755 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 756 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 757 | return_value = _winapi_TerminateProcess_impl(module, handle, exit_code); |
| 758 | |
| 759 | exit: |
| 760 | return return_value; |
| 761 | } |
| 762 | |
| 763 | PyDoc_STRVAR(_winapi_WaitNamedPipe__doc__, |
| 764 | "WaitNamedPipe($module, name, timeout, /)\n" |
| 765 | "--\n" |
| 766 | "\n"); |
| 767 | |
| 768 | #define _WINAPI_WAITNAMEDPIPE_METHODDEF \ |
| 769 | {"WaitNamedPipe", (PyCFunction)_winapi_WaitNamedPipe, METH_VARARGS, _winapi_WaitNamedPipe__doc__}, |
| 770 | |
| 771 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 772 | _winapi_WaitNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD timeout); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 773 | |
| 774 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 775 | _winapi_WaitNamedPipe(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 776 | { |
| 777 | PyObject *return_value = NULL; |
| 778 | LPCTSTR name; |
| 779 | DWORD timeout; |
| 780 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 781 | if (!PyArg_ParseTuple(args, "sk:WaitNamedPipe", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 782 | &name, &timeout)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 783 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 784 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 785 | return_value = _winapi_WaitNamedPipe_impl(module, name, timeout); |
| 786 | |
| 787 | exit: |
| 788 | return return_value; |
| 789 | } |
| 790 | |
| 791 | PyDoc_STRVAR(_winapi_WaitForMultipleObjects__doc__, |
| 792 | "WaitForMultipleObjects($module, handle_seq, wait_flag,\n" |
| 793 | " milliseconds=_winapi.INFINITE, /)\n" |
| 794 | "--\n" |
| 795 | "\n"); |
| 796 | |
| 797 | #define _WINAPI_WAITFORMULTIPLEOBJECTS_METHODDEF \ |
| 798 | {"WaitForMultipleObjects", (PyCFunction)_winapi_WaitForMultipleObjects, METH_VARARGS, _winapi_WaitForMultipleObjects__doc__}, |
| 799 | |
| 800 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 801 | _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq, |
| 802 | BOOL wait_flag, DWORD milliseconds); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 803 | |
| 804 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 805 | _winapi_WaitForMultipleObjects(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 806 | { |
| 807 | PyObject *return_value = NULL; |
| 808 | PyObject *handle_seq; |
| 809 | BOOL wait_flag; |
| 810 | DWORD milliseconds = INFINITE; |
| 811 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 812 | if (!PyArg_ParseTuple(args, "Oi|k:WaitForMultipleObjects", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 813 | &handle_seq, &wait_flag, &milliseconds)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 814 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 815 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 816 | return_value = _winapi_WaitForMultipleObjects_impl(module, handle_seq, wait_flag, milliseconds); |
| 817 | |
| 818 | exit: |
| 819 | return return_value; |
| 820 | } |
| 821 | |
| 822 | PyDoc_STRVAR(_winapi_WaitForSingleObject__doc__, |
| 823 | "WaitForSingleObject($module, handle, milliseconds, /)\n" |
| 824 | "--\n" |
| 825 | "\n" |
| 826 | "Wait for a single object.\n" |
| 827 | "\n" |
| 828 | "Wait until the specified object is in the signaled state or\n" |
| 829 | "the time-out interval elapses. The timeout value is specified\n" |
| 830 | "in milliseconds."); |
| 831 | |
| 832 | #define _WINAPI_WAITFORSINGLEOBJECT_METHODDEF \ |
| 833 | {"WaitForSingleObject", (PyCFunction)_winapi_WaitForSingleObject, METH_VARARGS, _winapi_WaitForSingleObject__doc__}, |
| 834 | |
| 835 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 836 | _winapi_WaitForSingleObject_impl(PyObject *module, HANDLE handle, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 837 | DWORD milliseconds); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 838 | |
| 839 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 840 | _winapi_WaitForSingleObject(PyObject *module, PyObject *args) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 841 | { |
| 842 | PyObject *return_value = NULL; |
| 843 | HANDLE handle; |
| 844 | DWORD milliseconds; |
| 845 | long _return_value; |
| 846 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 847 | if (!PyArg_ParseTuple(args, "" F_HANDLE "k:WaitForSingleObject", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 848 | &handle, &milliseconds)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 849 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 850 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 851 | _return_value = _winapi_WaitForSingleObject_impl(module, handle, milliseconds); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 852 | if ((_return_value == -1) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 853 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 854 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 855 | return_value = PyLong_FromLong(_return_value); |
| 856 | |
| 857 | exit: |
| 858 | return return_value; |
| 859 | } |
| 860 | |
| 861 | PyDoc_STRVAR(_winapi_WriteFile__doc__, |
| 862 | "WriteFile($module, /, handle, buffer, overlapped=False)\n" |
| 863 | "--\n" |
| 864 | "\n"); |
| 865 | |
| 866 | #define _WINAPI_WRITEFILE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 867 | {"WriteFile", (PyCFunction)_winapi_WriteFile, METH_FASTCALL, _winapi_WriteFile__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 868 | |
| 869 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 870 | _winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 871 | int use_overlapped); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 872 | |
| 873 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 874 | _winapi_WriteFile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 875 | { |
| 876 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 877 | static const char * const _keywords[] = {"handle", "buffer", "overlapped", NULL}; |
| 878 | static _PyArg_Parser _parser = {"" F_HANDLE "O|i:WriteFile", _keywords, 0}; |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 879 | HANDLE handle; |
| 880 | PyObject *buffer; |
| 881 | int use_overlapped = 0; |
| 882 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 883 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 884 | &handle, &buffer, &use_overlapped)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 885 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 886 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 887 | return_value = _winapi_WriteFile_impl(module, handle, buffer, use_overlapped); |
| 888 | |
| 889 | exit: |
| 890 | return return_value; |
| 891 | } |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 892 | /*[clinic end generated code: output=46d6382a6662c4a9 input=a9049054013a1b77]*/ |