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 | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 22 | wait = PyObject_IsTrue(arg); |
| 23 | if (wait < 0) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 24 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 25 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 26 | return_value = _winapi_Overlapped_GetOverlappedResult_impl(self, wait); |
| 27 | |
| 28 | exit: |
| 29 | return return_value; |
| 30 | } |
| 31 | |
| 32 | PyDoc_STRVAR(_winapi_Overlapped_getbuffer__doc__, |
| 33 | "getbuffer($self, /)\n" |
| 34 | "--\n" |
| 35 | "\n"); |
| 36 | |
| 37 | #define _WINAPI_OVERLAPPED_GETBUFFER_METHODDEF \ |
| 38 | {"getbuffer", (PyCFunction)_winapi_Overlapped_getbuffer, METH_NOARGS, _winapi_Overlapped_getbuffer__doc__}, |
| 39 | |
| 40 | static PyObject * |
| 41 | _winapi_Overlapped_getbuffer_impl(OverlappedObject *self); |
| 42 | |
| 43 | static PyObject * |
| 44 | _winapi_Overlapped_getbuffer(OverlappedObject *self, PyObject *Py_UNUSED(ignored)) |
| 45 | { |
| 46 | return _winapi_Overlapped_getbuffer_impl(self); |
| 47 | } |
| 48 | |
| 49 | PyDoc_STRVAR(_winapi_Overlapped_cancel__doc__, |
| 50 | "cancel($self, /)\n" |
| 51 | "--\n" |
| 52 | "\n"); |
| 53 | |
| 54 | #define _WINAPI_OVERLAPPED_CANCEL_METHODDEF \ |
| 55 | {"cancel", (PyCFunction)_winapi_Overlapped_cancel, METH_NOARGS, _winapi_Overlapped_cancel__doc__}, |
| 56 | |
| 57 | static PyObject * |
| 58 | _winapi_Overlapped_cancel_impl(OverlappedObject *self); |
| 59 | |
| 60 | static PyObject * |
| 61 | _winapi_Overlapped_cancel(OverlappedObject *self, PyObject *Py_UNUSED(ignored)) |
| 62 | { |
| 63 | return _winapi_Overlapped_cancel_impl(self); |
| 64 | } |
| 65 | |
| 66 | PyDoc_STRVAR(_winapi_CloseHandle__doc__, |
| 67 | "CloseHandle($module, handle, /)\n" |
| 68 | "--\n" |
| 69 | "\n" |
| 70 | "Close handle."); |
| 71 | |
| 72 | #define _WINAPI_CLOSEHANDLE_METHODDEF \ |
| 73 | {"CloseHandle", (PyCFunction)_winapi_CloseHandle, METH_O, _winapi_CloseHandle__doc__}, |
| 74 | |
| 75 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 76 | _winapi_CloseHandle_impl(PyObject *module, HANDLE handle); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 77 | |
| 78 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 79 | _winapi_CloseHandle(PyObject *module, PyObject *arg) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 80 | { |
| 81 | PyObject *return_value = NULL; |
| 82 | HANDLE handle; |
| 83 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 84 | if (!PyArg_Parse(arg, "" F_HANDLE ":CloseHandle", &handle)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 85 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 86 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 87 | return_value = _winapi_CloseHandle_impl(module, handle); |
| 88 | |
| 89 | exit: |
| 90 | return return_value; |
| 91 | } |
| 92 | |
| 93 | PyDoc_STRVAR(_winapi_ConnectNamedPipe__doc__, |
| 94 | "ConnectNamedPipe($module, /, handle, overlapped=False)\n" |
| 95 | "--\n" |
| 96 | "\n"); |
| 97 | |
| 98 | #define _WINAPI_CONNECTNAMEDPIPE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 99 | {"ConnectNamedPipe", (PyCFunction)(void(*)(void))_winapi_ConnectNamedPipe, METH_FASTCALL|METH_KEYWORDS, _winapi_ConnectNamedPipe__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 100 | |
| 101 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 102 | _winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 103 | int use_overlapped); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 104 | |
| 105 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 106 | _winapi_ConnectNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 107 | { |
| 108 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 109 | static const char * const _keywords[] = {"handle", "overlapped", NULL}; |
| 110 | static _PyArg_Parser _parser = {"" F_HANDLE "|i:ConnectNamedPipe", _keywords, 0}; |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 111 | HANDLE handle; |
| 112 | int use_overlapped = 0; |
| 113 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 114 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 115 | &handle, &use_overlapped)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 116 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 117 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 118 | return_value = _winapi_ConnectNamedPipe_impl(module, handle, use_overlapped); |
| 119 | |
| 120 | exit: |
| 121 | return return_value; |
| 122 | } |
| 123 | |
| 124 | PyDoc_STRVAR(_winapi_CreateFile__doc__, |
| 125 | "CreateFile($module, file_name, desired_access, share_mode,\n" |
| 126 | " security_attributes, creation_disposition,\n" |
| 127 | " flags_and_attributes, template_file, /)\n" |
| 128 | "--\n" |
| 129 | "\n"); |
| 130 | |
| 131 | #define _WINAPI_CREATEFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 132 | {"CreateFile", (PyCFunction)(void(*)(void))_winapi_CreateFile, METH_FASTCALL, _winapi_CreateFile__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 133 | |
| 134 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 135 | _winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 136 | DWORD desired_access, DWORD share_mode, |
| 137 | LPSECURITY_ATTRIBUTES security_attributes, |
| 138 | DWORD creation_disposition, |
| 139 | DWORD flags_and_attributes, HANDLE template_file); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 140 | |
| 141 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 142 | _winapi_CreateFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 143 | { |
| 144 | PyObject *return_value = NULL; |
| 145 | LPCTSTR file_name; |
| 146 | DWORD desired_access; |
| 147 | DWORD share_mode; |
| 148 | LPSECURITY_ATTRIBUTES security_attributes; |
| 149 | DWORD creation_disposition; |
| 150 | DWORD flags_and_attributes; |
| 151 | HANDLE template_file; |
| 152 | HANDLE _return_value; |
| 153 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 154 | if (!_PyArg_ParseStack(args, nargs, "skk" F_POINTER "kk" F_HANDLE ":CreateFile", |
| 155 | &file_name, &desired_access, &share_mode, &security_attributes, &creation_disposition, &flags_and_attributes, &template_file)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 156 | goto exit; |
| 157 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 158 | _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] | 159 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 160 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 161 | } |
| 162 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 163 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 164 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 165 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 166 | |
| 167 | exit: |
| 168 | return return_value; |
| 169 | } |
| 170 | |
Davin Potts | e895de3 | 2019-02-23 22:08:16 -0600 | [diff] [blame] | 171 | PyDoc_STRVAR(_winapi_CreateFileMapping__doc__, |
| 172 | "CreateFileMapping($module, file_handle, security_attributes, protect,\n" |
| 173 | " max_size_high, max_size_low, name, /)\n" |
| 174 | "--\n" |
| 175 | "\n"); |
| 176 | |
| 177 | #define _WINAPI_CREATEFILEMAPPING_METHODDEF \ |
| 178 | {"CreateFileMapping", (PyCFunction)(void(*)(void))_winapi_CreateFileMapping, METH_FASTCALL, _winapi_CreateFileMapping__doc__}, |
| 179 | |
| 180 | static HANDLE |
| 181 | _winapi_CreateFileMapping_impl(PyObject *module, HANDLE file_handle, |
| 182 | LPSECURITY_ATTRIBUTES security_attributes, |
| 183 | DWORD protect, DWORD max_size_high, |
| 184 | DWORD max_size_low, LPCWSTR name); |
| 185 | |
| 186 | static PyObject * |
| 187 | _winapi_CreateFileMapping(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 188 | { |
| 189 | PyObject *return_value = NULL; |
| 190 | HANDLE file_handle; |
| 191 | LPSECURITY_ATTRIBUTES security_attributes; |
| 192 | DWORD protect; |
| 193 | DWORD max_size_high; |
| 194 | DWORD max_size_low; |
| 195 | LPCWSTR name; |
| 196 | HANDLE _return_value; |
| 197 | |
| 198 | if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_POINTER "kkku:CreateFileMapping", |
| 199 | &file_handle, &security_attributes, &protect, &max_size_high, &max_size_low, &name)) { |
| 200 | goto exit; |
| 201 | } |
| 202 | _return_value = _winapi_CreateFileMapping_impl(module, file_handle, security_attributes, protect, max_size_high, max_size_low, name); |
| 203 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
| 204 | goto exit; |
| 205 | } |
| 206 | if (_return_value == NULL) { |
| 207 | Py_RETURN_NONE; |
| 208 | } |
| 209 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 210 | |
| 211 | exit: |
| 212 | return return_value; |
| 213 | } |
| 214 | |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 215 | PyDoc_STRVAR(_winapi_CreateJunction__doc__, |
| 216 | "CreateJunction($module, src_path, dst_path, /)\n" |
| 217 | "--\n" |
| 218 | "\n"); |
| 219 | |
| 220 | #define _WINAPI_CREATEJUNCTION_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 221 | {"CreateJunction", (PyCFunction)(void(*)(void))_winapi_CreateJunction, METH_FASTCALL, _winapi_CreateJunction__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 222 | |
| 223 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 224 | _winapi_CreateJunction_impl(PyObject *module, LPWSTR src_path, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 225 | LPWSTR dst_path); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 226 | |
| 227 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 228 | _winapi_CreateJunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 229 | { |
| 230 | PyObject *return_value = NULL; |
| 231 | LPWSTR src_path; |
| 232 | LPWSTR dst_path; |
| 233 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 234 | if (!_PyArg_ParseStack(args, nargs, "uu:CreateJunction", |
| 235 | &src_path, &dst_path)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 236 | goto exit; |
| 237 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 238 | return_value = _winapi_CreateJunction_impl(module, src_path, dst_path); |
| 239 | |
| 240 | exit: |
| 241 | return return_value; |
| 242 | } |
| 243 | |
| 244 | PyDoc_STRVAR(_winapi_CreateNamedPipe__doc__, |
| 245 | "CreateNamedPipe($module, name, open_mode, pipe_mode, max_instances,\n" |
| 246 | " out_buffer_size, in_buffer_size, default_timeout,\n" |
| 247 | " security_attributes, /)\n" |
| 248 | "--\n" |
| 249 | "\n"); |
| 250 | |
| 251 | #define _WINAPI_CREATENAMEDPIPE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 252 | {"CreateNamedPipe", (PyCFunction)(void(*)(void))_winapi_CreateNamedPipe, METH_FASTCALL, _winapi_CreateNamedPipe__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 253 | |
| 254 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 255 | _winapi_CreateNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD open_mode, |
| 256 | DWORD pipe_mode, DWORD max_instances, |
| 257 | DWORD out_buffer_size, DWORD in_buffer_size, |
| 258 | DWORD default_timeout, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 259 | LPSECURITY_ATTRIBUTES security_attributes); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 260 | |
| 261 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 262 | _winapi_CreateNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 263 | { |
| 264 | PyObject *return_value = NULL; |
| 265 | LPCTSTR name; |
| 266 | DWORD open_mode; |
| 267 | DWORD pipe_mode; |
| 268 | DWORD max_instances; |
| 269 | DWORD out_buffer_size; |
| 270 | DWORD in_buffer_size; |
| 271 | DWORD default_timeout; |
| 272 | LPSECURITY_ATTRIBUTES security_attributes; |
| 273 | HANDLE _return_value; |
| 274 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 275 | if (!_PyArg_ParseStack(args, nargs, "skkkkkk" F_POINTER ":CreateNamedPipe", |
| 276 | &name, &open_mode, &pipe_mode, &max_instances, &out_buffer_size, &in_buffer_size, &default_timeout, &security_attributes)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 277 | goto exit; |
| 278 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 279 | _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] | 280 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 281 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 282 | } |
| 283 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 284 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 285 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 286 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 287 | |
| 288 | exit: |
| 289 | return return_value; |
| 290 | } |
| 291 | |
| 292 | PyDoc_STRVAR(_winapi_CreatePipe__doc__, |
| 293 | "CreatePipe($module, pipe_attrs, size, /)\n" |
| 294 | "--\n" |
| 295 | "\n" |
| 296 | "Create an anonymous pipe.\n" |
| 297 | "\n" |
| 298 | " pipe_attrs\n" |
| 299 | " Ignored internally, can be None.\n" |
| 300 | "\n" |
| 301 | "Returns a 2-tuple of handles, to the read and write ends of the pipe."); |
| 302 | |
| 303 | #define _WINAPI_CREATEPIPE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 304 | {"CreatePipe", (PyCFunction)(void(*)(void))_winapi_CreatePipe, METH_FASTCALL, _winapi_CreatePipe__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 305 | |
| 306 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 307 | _winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, DWORD size); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 308 | |
| 309 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 310 | _winapi_CreatePipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 311 | { |
| 312 | PyObject *return_value = NULL; |
| 313 | PyObject *pipe_attrs; |
| 314 | DWORD size; |
| 315 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 316 | if (!_PyArg_ParseStack(args, nargs, "Ok:CreatePipe", |
| 317 | &pipe_attrs, &size)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 318 | goto exit; |
| 319 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 320 | return_value = _winapi_CreatePipe_impl(module, pipe_attrs, size); |
| 321 | |
| 322 | exit: |
| 323 | return return_value; |
| 324 | } |
| 325 | |
| 326 | PyDoc_STRVAR(_winapi_CreateProcess__doc__, |
| 327 | "CreateProcess($module, application_name, command_line, proc_attrs,\n" |
| 328 | " thread_attrs, inherit_handles, creation_flags,\n" |
| 329 | " env_mapping, current_directory, startup_info, /)\n" |
| 330 | "--\n" |
| 331 | "\n" |
| 332 | "Create a new process and its primary thread.\n" |
| 333 | "\n" |
Vladimir Matveev | 7b36016 | 2018-12-14 00:30:51 -0800 | [diff] [blame] | 334 | " command_line\n" |
| 335 | " Can be str or None\n" |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 336 | " proc_attrs\n" |
| 337 | " Ignored internally, can be None.\n" |
| 338 | " thread_attrs\n" |
| 339 | " Ignored internally, can be None.\n" |
| 340 | "\n" |
| 341 | "The return value is a tuple of the process handle, thread handle,\n" |
| 342 | "process ID, and thread ID."); |
| 343 | |
| 344 | #define _WINAPI_CREATEPROCESS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 345 | {"CreateProcess", (PyCFunction)(void(*)(void))_winapi_CreateProcess, METH_FASTCALL, _winapi_CreateProcess__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 346 | |
| 347 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 348 | _winapi_CreateProcess_impl(PyObject *module, |
| 349 | const Py_UNICODE *application_name, |
Vladimir Matveev | 7b36016 | 2018-12-14 00:30:51 -0800 | [diff] [blame] | 350 | PyObject *command_line, PyObject *proc_attrs, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 351 | PyObject *thread_attrs, BOOL inherit_handles, |
| 352 | DWORD creation_flags, PyObject *env_mapping, |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 353 | const Py_UNICODE *current_directory, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 354 | PyObject *startup_info); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 355 | |
| 356 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 357 | _winapi_CreateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 358 | { |
| 359 | PyObject *return_value = NULL; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 360 | const Py_UNICODE *application_name; |
Vladimir Matveev | 7b36016 | 2018-12-14 00:30:51 -0800 | [diff] [blame] | 361 | PyObject *command_line; |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 362 | PyObject *proc_attrs; |
| 363 | PyObject *thread_attrs; |
| 364 | BOOL inherit_handles; |
| 365 | DWORD creation_flags; |
| 366 | PyObject *env_mapping; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 367 | const Py_UNICODE *current_directory; |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 368 | PyObject *startup_info; |
| 369 | |
Vladimir Matveev | 7b36016 | 2018-12-14 00:30:51 -0800 | [diff] [blame] | 370 | if (!_PyArg_ParseStack(args, nargs, "ZOOOikOZO:CreateProcess", |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 371 | &application_name, &command_line, &proc_attrs, &thread_attrs, &inherit_handles, &creation_flags, &env_mapping, ¤t_directory, &startup_info)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 372 | goto exit; |
| 373 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 374 | return_value = _winapi_CreateProcess_impl(module, application_name, command_line, proc_attrs, thread_attrs, inherit_handles, creation_flags, env_mapping, current_directory, startup_info); |
| 375 | |
| 376 | exit: |
| 377 | return return_value; |
| 378 | } |
| 379 | |
| 380 | PyDoc_STRVAR(_winapi_DuplicateHandle__doc__, |
| 381 | "DuplicateHandle($module, source_process_handle, source_handle,\n" |
| 382 | " target_process_handle, desired_access, inherit_handle,\n" |
| 383 | " options=0, /)\n" |
| 384 | "--\n" |
| 385 | "\n" |
| 386 | "Return a duplicate handle object.\n" |
| 387 | "\n" |
| 388 | "The duplicate handle refers to the same object as the original\n" |
| 389 | "handle. Therefore, any changes to the object are reflected\n" |
| 390 | "through both handles."); |
| 391 | |
| 392 | #define _WINAPI_DUPLICATEHANDLE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 393 | {"DuplicateHandle", (PyCFunction)(void(*)(void))_winapi_DuplicateHandle, METH_FASTCALL, _winapi_DuplicateHandle__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 394 | |
| 395 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 396 | _winapi_DuplicateHandle_impl(PyObject *module, HANDLE source_process_handle, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 397 | HANDLE source_handle, |
| 398 | HANDLE target_process_handle, |
| 399 | DWORD desired_access, BOOL inherit_handle, |
| 400 | DWORD options); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 401 | |
| 402 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 403 | _winapi_DuplicateHandle(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 404 | { |
| 405 | PyObject *return_value = NULL; |
| 406 | HANDLE source_process_handle; |
| 407 | HANDLE source_handle; |
| 408 | HANDLE target_process_handle; |
| 409 | DWORD desired_access; |
| 410 | BOOL inherit_handle; |
| 411 | DWORD options = 0; |
| 412 | HANDLE _return_value; |
| 413 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 414 | if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_HANDLE "" F_HANDLE "ki|k:DuplicateHandle", |
| 415 | &source_process_handle, &source_handle, &target_process_handle, &desired_access, &inherit_handle, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 416 | goto exit; |
| 417 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 418 | _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] | 419 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 420 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 421 | } |
| 422 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 423 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 424 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 425 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 426 | |
| 427 | exit: |
| 428 | return return_value; |
| 429 | } |
| 430 | |
| 431 | PyDoc_STRVAR(_winapi_ExitProcess__doc__, |
| 432 | "ExitProcess($module, ExitCode, /)\n" |
| 433 | "--\n" |
| 434 | "\n"); |
| 435 | |
| 436 | #define _WINAPI_EXITPROCESS_METHODDEF \ |
| 437 | {"ExitProcess", (PyCFunction)_winapi_ExitProcess, METH_O, _winapi_ExitProcess__doc__}, |
| 438 | |
| 439 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 440 | _winapi_ExitProcess_impl(PyObject *module, UINT ExitCode); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 441 | |
| 442 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 443 | _winapi_ExitProcess(PyObject *module, PyObject *arg) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 444 | { |
| 445 | PyObject *return_value = NULL; |
| 446 | UINT ExitCode; |
| 447 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 448 | if (!PyArg_Parse(arg, "I:ExitProcess", &ExitCode)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 449 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 450 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 451 | return_value = _winapi_ExitProcess_impl(module, ExitCode); |
| 452 | |
| 453 | exit: |
| 454 | return return_value; |
| 455 | } |
| 456 | |
| 457 | PyDoc_STRVAR(_winapi_GetCurrentProcess__doc__, |
| 458 | "GetCurrentProcess($module, /)\n" |
| 459 | "--\n" |
| 460 | "\n" |
| 461 | "Return a handle object for the current process."); |
| 462 | |
| 463 | #define _WINAPI_GETCURRENTPROCESS_METHODDEF \ |
| 464 | {"GetCurrentProcess", (PyCFunction)_winapi_GetCurrentProcess, METH_NOARGS, _winapi_GetCurrentProcess__doc__}, |
| 465 | |
| 466 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 467 | _winapi_GetCurrentProcess_impl(PyObject *module); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 468 | |
| 469 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 470 | _winapi_GetCurrentProcess(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 471 | { |
| 472 | PyObject *return_value = NULL; |
| 473 | HANDLE _return_value; |
| 474 | |
| 475 | _return_value = _winapi_GetCurrentProcess_impl(module); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 476 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 477 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 478 | } |
| 479 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 480 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 481 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 482 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 483 | |
| 484 | exit: |
| 485 | return return_value; |
| 486 | } |
| 487 | |
| 488 | PyDoc_STRVAR(_winapi_GetExitCodeProcess__doc__, |
| 489 | "GetExitCodeProcess($module, process, /)\n" |
| 490 | "--\n" |
| 491 | "\n" |
| 492 | "Return the termination status of the specified process."); |
| 493 | |
| 494 | #define _WINAPI_GETEXITCODEPROCESS_METHODDEF \ |
| 495 | {"GetExitCodeProcess", (PyCFunction)_winapi_GetExitCodeProcess, METH_O, _winapi_GetExitCodeProcess__doc__}, |
| 496 | |
| 497 | static DWORD |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 498 | _winapi_GetExitCodeProcess_impl(PyObject *module, HANDLE process); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 499 | |
| 500 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 501 | _winapi_GetExitCodeProcess(PyObject *module, PyObject *arg) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 502 | { |
| 503 | PyObject *return_value = NULL; |
| 504 | HANDLE process; |
| 505 | DWORD _return_value; |
| 506 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 507 | if (!PyArg_Parse(arg, "" F_HANDLE ":GetExitCodeProcess", &process)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 508 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 509 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 510 | _return_value = _winapi_GetExitCodeProcess_impl(module, process); |
Victor Stinner | 850a18e | 2017-10-24 16:53:32 -0700 | [diff] [blame] | 511 | if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 512 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 513 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 514 | return_value = Py_BuildValue("k", _return_value); |
| 515 | |
| 516 | exit: |
| 517 | return return_value; |
| 518 | } |
| 519 | |
| 520 | PyDoc_STRVAR(_winapi_GetLastError__doc__, |
| 521 | "GetLastError($module, /)\n" |
| 522 | "--\n" |
| 523 | "\n"); |
| 524 | |
| 525 | #define _WINAPI_GETLASTERROR_METHODDEF \ |
| 526 | {"GetLastError", (PyCFunction)_winapi_GetLastError, METH_NOARGS, _winapi_GetLastError__doc__}, |
| 527 | |
| 528 | static DWORD |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 529 | _winapi_GetLastError_impl(PyObject *module); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 530 | |
| 531 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 532 | _winapi_GetLastError(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 533 | { |
| 534 | PyObject *return_value = NULL; |
| 535 | DWORD _return_value; |
| 536 | |
| 537 | _return_value = _winapi_GetLastError_impl(module); |
Victor Stinner | 850a18e | 2017-10-24 16:53:32 -0700 | [diff] [blame] | 538 | if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 539 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 540 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 541 | return_value = Py_BuildValue("k", _return_value); |
| 542 | |
| 543 | exit: |
| 544 | return return_value; |
| 545 | } |
| 546 | |
| 547 | PyDoc_STRVAR(_winapi_GetModuleFileName__doc__, |
| 548 | "GetModuleFileName($module, module_handle, /)\n" |
| 549 | "--\n" |
| 550 | "\n" |
| 551 | "Return the fully-qualified path for the file that contains module.\n" |
| 552 | "\n" |
| 553 | "The module must have been loaded by the current process.\n" |
| 554 | "\n" |
| 555 | "The module parameter should be a handle to the loaded module\n" |
| 556 | "whose path is being requested. If this parameter is 0,\n" |
| 557 | "GetModuleFileName retrieves the path of the executable file\n" |
| 558 | "of the current process."); |
| 559 | |
| 560 | #define _WINAPI_GETMODULEFILENAME_METHODDEF \ |
| 561 | {"GetModuleFileName", (PyCFunction)_winapi_GetModuleFileName, METH_O, _winapi_GetModuleFileName__doc__}, |
| 562 | |
| 563 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 564 | _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 565 | |
| 566 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 567 | _winapi_GetModuleFileName(PyObject *module, PyObject *arg) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 568 | { |
| 569 | PyObject *return_value = NULL; |
| 570 | HMODULE module_handle; |
| 571 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 572 | if (!PyArg_Parse(arg, "" F_HANDLE ":GetModuleFileName", &module_handle)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 573 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 574 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 575 | return_value = _winapi_GetModuleFileName_impl(module, module_handle); |
| 576 | |
| 577 | exit: |
| 578 | return return_value; |
| 579 | } |
| 580 | |
| 581 | PyDoc_STRVAR(_winapi_GetStdHandle__doc__, |
| 582 | "GetStdHandle($module, std_handle, /)\n" |
| 583 | "--\n" |
| 584 | "\n" |
| 585 | "Return a handle to the specified standard device.\n" |
| 586 | "\n" |
| 587 | " std_handle\n" |
| 588 | " One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE.\n" |
| 589 | "\n" |
| 590 | "The integer associated with the handle object is returned."); |
| 591 | |
| 592 | #define _WINAPI_GETSTDHANDLE_METHODDEF \ |
| 593 | {"GetStdHandle", (PyCFunction)_winapi_GetStdHandle, METH_O, _winapi_GetStdHandle__doc__}, |
| 594 | |
| 595 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 596 | _winapi_GetStdHandle_impl(PyObject *module, DWORD std_handle); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 597 | |
| 598 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 599 | _winapi_GetStdHandle(PyObject *module, PyObject *arg) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 600 | { |
| 601 | PyObject *return_value = NULL; |
| 602 | DWORD std_handle; |
| 603 | HANDLE _return_value; |
| 604 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 605 | if (!PyArg_Parse(arg, "k:GetStdHandle", &std_handle)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 606 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 607 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 608 | _return_value = _winapi_GetStdHandle_impl(module, std_handle); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 609 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 610 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 611 | } |
| 612 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 613 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 614 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 615 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 616 | |
| 617 | exit: |
| 618 | return return_value; |
| 619 | } |
| 620 | |
| 621 | PyDoc_STRVAR(_winapi_GetVersion__doc__, |
| 622 | "GetVersion($module, /)\n" |
| 623 | "--\n" |
| 624 | "\n" |
| 625 | "Return the version number of the current operating system."); |
| 626 | |
| 627 | #define _WINAPI_GETVERSION_METHODDEF \ |
| 628 | {"GetVersion", (PyCFunction)_winapi_GetVersion, METH_NOARGS, _winapi_GetVersion__doc__}, |
| 629 | |
| 630 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 631 | _winapi_GetVersion_impl(PyObject *module); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 632 | |
| 633 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 634 | _winapi_GetVersion(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 635 | { |
| 636 | PyObject *return_value = NULL; |
| 637 | long _return_value; |
| 638 | |
| 639 | _return_value = _winapi_GetVersion_impl(module); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 640 | if ((_return_value == -1) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 641 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 642 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 643 | return_value = PyLong_FromLong(_return_value); |
| 644 | |
| 645 | exit: |
| 646 | return return_value; |
| 647 | } |
| 648 | |
Davin Potts | e895de3 | 2019-02-23 22:08:16 -0600 | [diff] [blame] | 649 | PyDoc_STRVAR(_winapi_MapViewOfFile__doc__, |
| 650 | "MapViewOfFile($module, file_map, desired_access, file_offset_high,\n" |
| 651 | " file_offset_low, number_bytes, /)\n" |
| 652 | "--\n" |
| 653 | "\n"); |
| 654 | |
| 655 | #define _WINAPI_MAPVIEWOFFILE_METHODDEF \ |
| 656 | {"MapViewOfFile", (PyCFunction)(void(*)(void))_winapi_MapViewOfFile, METH_FASTCALL, _winapi_MapViewOfFile__doc__}, |
| 657 | |
| 658 | static LPVOID |
| 659 | _winapi_MapViewOfFile_impl(PyObject *module, HANDLE file_map, |
| 660 | DWORD desired_access, DWORD file_offset_high, |
| 661 | DWORD file_offset_low, size_t number_bytes); |
| 662 | |
| 663 | static PyObject * |
| 664 | _winapi_MapViewOfFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 665 | { |
| 666 | PyObject *return_value = NULL; |
| 667 | HANDLE file_map; |
| 668 | DWORD desired_access; |
| 669 | DWORD file_offset_high; |
| 670 | DWORD file_offset_low; |
| 671 | size_t number_bytes; |
| 672 | LPVOID _return_value; |
| 673 | |
| 674 | if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "kkkO&:MapViewOfFile", |
| 675 | &file_map, &desired_access, &file_offset_high, &file_offset_low, _PyLong_Size_t_Converter, &number_bytes)) { |
| 676 | goto exit; |
| 677 | } |
| 678 | _return_value = _winapi_MapViewOfFile_impl(module, file_map, desired_access, file_offset_high, file_offset_low, number_bytes); |
| 679 | if ((_return_value == NULL) && PyErr_Occurred()) { |
| 680 | goto exit; |
| 681 | } |
| 682 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 683 | |
| 684 | exit: |
| 685 | return return_value; |
| 686 | } |
| 687 | |
| 688 | PyDoc_STRVAR(_winapi_OpenFileMapping__doc__, |
| 689 | "OpenFileMapping($module, desired_access, inherit_handle, name, /)\n" |
| 690 | "--\n" |
| 691 | "\n"); |
| 692 | |
| 693 | #define _WINAPI_OPENFILEMAPPING_METHODDEF \ |
| 694 | {"OpenFileMapping", (PyCFunction)(void(*)(void))_winapi_OpenFileMapping, METH_FASTCALL, _winapi_OpenFileMapping__doc__}, |
| 695 | |
| 696 | static HANDLE |
| 697 | _winapi_OpenFileMapping_impl(PyObject *module, DWORD desired_access, |
| 698 | BOOL inherit_handle, LPCWSTR name); |
| 699 | |
| 700 | static PyObject * |
| 701 | _winapi_OpenFileMapping(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 702 | { |
| 703 | PyObject *return_value = NULL; |
| 704 | DWORD desired_access; |
| 705 | BOOL inherit_handle; |
| 706 | LPCWSTR name; |
| 707 | HANDLE _return_value; |
| 708 | |
| 709 | if (!_PyArg_ParseStack(args, nargs, "kiu:OpenFileMapping", |
| 710 | &desired_access, &inherit_handle, &name)) { |
| 711 | goto exit; |
| 712 | } |
| 713 | _return_value = _winapi_OpenFileMapping_impl(module, desired_access, inherit_handle, name); |
| 714 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
| 715 | goto exit; |
| 716 | } |
| 717 | if (_return_value == NULL) { |
| 718 | Py_RETURN_NONE; |
| 719 | } |
| 720 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 721 | |
| 722 | exit: |
| 723 | return return_value; |
| 724 | } |
| 725 | |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 726 | PyDoc_STRVAR(_winapi_OpenProcess__doc__, |
| 727 | "OpenProcess($module, desired_access, inherit_handle, process_id, /)\n" |
| 728 | "--\n" |
| 729 | "\n"); |
| 730 | |
| 731 | #define _WINAPI_OPENPROCESS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 732 | {"OpenProcess", (PyCFunction)(void(*)(void))_winapi_OpenProcess, METH_FASTCALL, _winapi_OpenProcess__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 733 | |
| 734 | static HANDLE |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 735 | _winapi_OpenProcess_impl(PyObject *module, DWORD desired_access, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 736 | BOOL inherit_handle, DWORD process_id); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 737 | |
| 738 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 739 | _winapi_OpenProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 740 | { |
| 741 | PyObject *return_value = NULL; |
| 742 | DWORD desired_access; |
| 743 | BOOL inherit_handle; |
| 744 | DWORD process_id; |
| 745 | HANDLE _return_value; |
| 746 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 747 | if (!_PyArg_ParseStack(args, nargs, "kik:OpenProcess", |
| 748 | &desired_access, &inherit_handle, &process_id)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 749 | goto exit; |
| 750 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 751 | _return_value = _winapi_OpenProcess_impl(module, desired_access, inherit_handle, process_id); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 752 | if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 753 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 754 | } |
| 755 | if (_return_value == NULL) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 756 | Py_RETURN_NONE; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 757 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 758 | return_value = HANDLE_TO_PYNUM(_return_value); |
| 759 | |
| 760 | exit: |
| 761 | return return_value; |
| 762 | } |
| 763 | |
| 764 | PyDoc_STRVAR(_winapi_PeekNamedPipe__doc__, |
| 765 | "PeekNamedPipe($module, handle, size=0, /)\n" |
| 766 | "--\n" |
| 767 | "\n"); |
| 768 | |
| 769 | #define _WINAPI_PEEKNAMEDPIPE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 770 | {"PeekNamedPipe", (PyCFunction)(void(*)(void))_winapi_PeekNamedPipe, METH_FASTCALL, _winapi_PeekNamedPipe__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 771 | |
| 772 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 773 | _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 774 | |
| 775 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 776 | _winapi_PeekNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 777 | { |
| 778 | PyObject *return_value = NULL; |
| 779 | HANDLE handle; |
| 780 | int size = 0; |
| 781 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 782 | if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "|i:PeekNamedPipe", |
| 783 | &handle, &size)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 784 | goto exit; |
| 785 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 786 | return_value = _winapi_PeekNamedPipe_impl(module, handle, size); |
| 787 | |
| 788 | exit: |
| 789 | return return_value; |
| 790 | } |
| 791 | |
| 792 | PyDoc_STRVAR(_winapi_ReadFile__doc__, |
| 793 | "ReadFile($module, /, handle, size, overlapped=False)\n" |
| 794 | "--\n" |
| 795 | "\n"); |
| 796 | |
| 797 | #define _WINAPI_READFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 798 | {"ReadFile", (PyCFunction)(void(*)(void))_winapi_ReadFile, METH_FASTCALL|METH_KEYWORDS, _winapi_ReadFile__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 799 | |
| 800 | static PyObject * |
Alexander Buchkovsky | 266f490 | 2018-09-04 19:10:28 +0300 | [diff] [blame] | 801 | _winapi_ReadFile_impl(PyObject *module, HANDLE handle, DWORD size, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 802 | int use_overlapped); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 803 | |
| 804 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 805 | _winapi_ReadFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 806 | { |
| 807 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 808 | static const char * const _keywords[] = {"handle", "size", "overlapped", NULL}; |
Alexander Buchkovsky | 266f490 | 2018-09-04 19:10:28 +0300 | [diff] [blame] | 809 | static _PyArg_Parser _parser = {"" F_HANDLE "k|i:ReadFile", _keywords, 0}; |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 810 | HANDLE handle; |
Alexander Buchkovsky | 266f490 | 2018-09-04 19:10:28 +0300 | [diff] [blame] | 811 | DWORD size; |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 812 | int use_overlapped = 0; |
| 813 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 814 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 815 | &handle, &size, &use_overlapped)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 816 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 817 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 818 | return_value = _winapi_ReadFile_impl(module, handle, size, use_overlapped); |
| 819 | |
| 820 | exit: |
| 821 | return return_value; |
| 822 | } |
| 823 | |
| 824 | PyDoc_STRVAR(_winapi_SetNamedPipeHandleState__doc__, |
| 825 | "SetNamedPipeHandleState($module, named_pipe, mode,\n" |
| 826 | " max_collection_count, collect_data_timeout, /)\n" |
| 827 | "--\n" |
| 828 | "\n"); |
| 829 | |
| 830 | #define _WINAPI_SETNAMEDPIPEHANDLESTATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 831 | {"SetNamedPipeHandleState", (PyCFunction)(void(*)(void))_winapi_SetNamedPipeHandleState, METH_FASTCALL, _winapi_SetNamedPipeHandleState__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 832 | |
| 833 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 834 | _winapi_SetNamedPipeHandleState_impl(PyObject *module, HANDLE named_pipe, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 835 | PyObject *mode, |
| 836 | PyObject *max_collection_count, |
| 837 | PyObject *collect_data_timeout); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 838 | |
| 839 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 840 | _winapi_SetNamedPipeHandleState(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 841 | { |
| 842 | PyObject *return_value = NULL; |
| 843 | HANDLE named_pipe; |
| 844 | PyObject *mode; |
| 845 | PyObject *max_collection_count; |
| 846 | PyObject *collect_data_timeout; |
| 847 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 848 | if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "OOO:SetNamedPipeHandleState", |
| 849 | &named_pipe, &mode, &max_collection_count, &collect_data_timeout)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 850 | goto exit; |
| 851 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 852 | return_value = _winapi_SetNamedPipeHandleState_impl(module, named_pipe, mode, max_collection_count, collect_data_timeout); |
| 853 | |
| 854 | exit: |
| 855 | return return_value; |
| 856 | } |
| 857 | |
| 858 | PyDoc_STRVAR(_winapi_TerminateProcess__doc__, |
| 859 | "TerminateProcess($module, handle, exit_code, /)\n" |
| 860 | "--\n" |
| 861 | "\n" |
| 862 | "Terminate the specified process and all of its threads."); |
| 863 | |
| 864 | #define _WINAPI_TERMINATEPROCESS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 865 | {"TerminateProcess", (PyCFunction)(void(*)(void))_winapi_TerminateProcess, METH_FASTCALL, _winapi_TerminateProcess__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 866 | |
| 867 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 868 | _winapi_TerminateProcess_impl(PyObject *module, HANDLE handle, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 869 | UINT exit_code); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 870 | |
| 871 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 872 | _winapi_TerminateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 873 | { |
| 874 | PyObject *return_value = NULL; |
| 875 | HANDLE handle; |
| 876 | UINT exit_code; |
| 877 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 878 | if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "I:TerminateProcess", |
| 879 | &handle, &exit_code)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 880 | goto exit; |
| 881 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 882 | return_value = _winapi_TerminateProcess_impl(module, handle, exit_code); |
| 883 | |
| 884 | exit: |
| 885 | return return_value; |
| 886 | } |
| 887 | |
Davin Potts | e895de3 | 2019-02-23 22:08:16 -0600 | [diff] [blame] | 888 | PyDoc_STRVAR(_winapi_VirtualQuerySize__doc__, |
| 889 | "VirtualQuerySize($module, address, /)\n" |
| 890 | "--\n" |
| 891 | "\n"); |
| 892 | |
| 893 | #define _WINAPI_VIRTUALQUERYSIZE_METHODDEF \ |
| 894 | {"VirtualQuerySize", (PyCFunction)_winapi_VirtualQuerySize, METH_O, _winapi_VirtualQuerySize__doc__}, |
| 895 | |
| 896 | static size_t |
| 897 | _winapi_VirtualQuerySize_impl(PyObject *module, LPCVOID address); |
| 898 | |
| 899 | static PyObject * |
| 900 | _winapi_VirtualQuerySize(PyObject *module, PyObject *arg) |
| 901 | { |
| 902 | PyObject *return_value = NULL; |
| 903 | LPCVOID address; |
| 904 | size_t _return_value; |
| 905 | |
| 906 | if (!PyArg_Parse(arg, "" F_POINTER ":VirtualQuerySize", &address)) { |
| 907 | goto exit; |
| 908 | } |
| 909 | _return_value = _winapi_VirtualQuerySize_impl(module, address); |
| 910 | if ((_return_value == (size_t)-1) && PyErr_Occurred()) { |
| 911 | goto exit; |
| 912 | } |
| 913 | return_value = PyLong_FromSize_t(_return_value); |
| 914 | |
| 915 | exit: |
| 916 | return return_value; |
| 917 | } |
| 918 | |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 919 | PyDoc_STRVAR(_winapi_WaitNamedPipe__doc__, |
| 920 | "WaitNamedPipe($module, name, timeout, /)\n" |
| 921 | "--\n" |
| 922 | "\n"); |
| 923 | |
| 924 | #define _WINAPI_WAITNAMEDPIPE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 925 | {"WaitNamedPipe", (PyCFunction)(void(*)(void))_winapi_WaitNamedPipe, METH_FASTCALL, _winapi_WaitNamedPipe__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 926 | |
| 927 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 928 | _winapi_WaitNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD timeout); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 929 | |
| 930 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 931 | _winapi_WaitNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 932 | { |
| 933 | PyObject *return_value = NULL; |
| 934 | LPCTSTR name; |
| 935 | DWORD timeout; |
| 936 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 937 | if (!_PyArg_ParseStack(args, nargs, "sk:WaitNamedPipe", |
| 938 | &name, &timeout)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 939 | goto exit; |
| 940 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 941 | return_value = _winapi_WaitNamedPipe_impl(module, name, timeout); |
| 942 | |
| 943 | exit: |
| 944 | return return_value; |
| 945 | } |
| 946 | |
| 947 | PyDoc_STRVAR(_winapi_WaitForMultipleObjects__doc__, |
| 948 | "WaitForMultipleObjects($module, handle_seq, wait_flag,\n" |
| 949 | " milliseconds=_winapi.INFINITE, /)\n" |
| 950 | "--\n" |
| 951 | "\n"); |
| 952 | |
| 953 | #define _WINAPI_WAITFORMULTIPLEOBJECTS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 954 | {"WaitForMultipleObjects", (PyCFunction)(void(*)(void))_winapi_WaitForMultipleObjects, METH_FASTCALL, _winapi_WaitForMultipleObjects__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 955 | |
| 956 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 957 | _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq, |
| 958 | BOOL wait_flag, DWORD milliseconds); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 959 | |
| 960 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 961 | _winapi_WaitForMultipleObjects(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 962 | { |
| 963 | PyObject *return_value = NULL; |
| 964 | PyObject *handle_seq; |
| 965 | BOOL wait_flag; |
| 966 | DWORD milliseconds = INFINITE; |
| 967 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 968 | if (!_PyArg_ParseStack(args, nargs, "Oi|k:WaitForMultipleObjects", |
| 969 | &handle_seq, &wait_flag, &milliseconds)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 970 | goto exit; |
| 971 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 972 | return_value = _winapi_WaitForMultipleObjects_impl(module, handle_seq, wait_flag, milliseconds); |
| 973 | |
| 974 | exit: |
| 975 | return return_value; |
| 976 | } |
| 977 | |
| 978 | PyDoc_STRVAR(_winapi_WaitForSingleObject__doc__, |
| 979 | "WaitForSingleObject($module, handle, milliseconds, /)\n" |
| 980 | "--\n" |
| 981 | "\n" |
| 982 | "Wait for a single object.\n" |
| 983 | "\n" |
| 984 | "Wait until the specified object is in the signaled state or\n" |
| 985 | "the time-out interval elapses. The timeout value is specified\n" |
| 986 | "in milliseconds."); |
| 987 | |
| 988 | #define _WINAPI_WAITFORSINGLEOBJECT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 989 | {"WaitForSingleObject", (PyCFunction)(void(*)(void))_winapi_WaitForSingleObject, METH_FASTCALL, _winapi_WaitForSingleObject__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 990 | |
| 991 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 992 | _winapi_WaitForSingleObject_impl(PyObject *module, HANDLE handle, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 993 | DWORD milliseconds); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 994 | |
| 995 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 996 | _winapi_WaitForSingleObject(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 997 | { |
| 998 | PyObject *return_value = NULL; |
| 999 | HANDLE handle; |
| 1000 | DWORD milliseconds; |
| 1001 | long _return_value; |
| 1002 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 1003 | if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "k:WaitForSingleObject", |
| 1004 | &handle, &milliseconds)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1005 | goto exit; |
| 1006 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 1007 | _return_value = _winapi_WaitForSingleObject_impl(module, handle, milliseconds); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1008 | if ((_return_value == -1) && PyErr_Occurred()) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 1009 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1010 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 1011 | return_value = PyLong_FromLong(_return_value); |
| 1012 | |
| 1013 | exit: |
| 1014 | return return_value; |
| 1015 | } |
| 1016 | |
| 1017 | PyDoc_STRVAR(_winapi_WriteFile__doc__, |
| 1018 | "WriteFile($module, /, handle, buffer, overlapped=False)\n" |
| 1019 | "--\n" |
| 1020 | "\n"); |
| 1021 | |
| 1022 | #define _WINAPI_WRITEFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1023 | {"WriteFile", (PyCFunction)(void(*)(void))_winapi_WriteFile, METH_FASTCALL|METH_KEYWORDS, _winapi_WriteFile__doc__}, |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 1024 | |
| 1025 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1026 | _winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 1027 | int use_overlapped); |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 1028 | |
| 1029 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1030 | _winapi_WriteFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 1031 | { |
| 1032 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1033 | static const char * const _keywords[] = {"handle", "buffer", "overlapped", NULL}; |
| 1034 | static _PyArg_Parser _parser = {"" F_HANDLE "O|i:WriteFile", _keywords, 0}; |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 1035 | HANDLE handle; |
| 1036 | PyObject *buffer; |
| 1037 | int use_overlapped = 0; |
| 1038 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1039 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1040 | &handle, &buffer, &use_overlapped)) { |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 1041 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1042 | } |
Zachary Ware | f2244ea | 2015-05-13 01:22:54 -0500 | [diff] [blame] | 1043 | return_value = _winapi_WriteFile_impl(module, handle, buffer, use_overlapped); |
| 1044 | |
| 1045 | exit: |
| 1046 | return return_value; |
| 1047 | } |
Victor Stinner | 91106cd | 2017-12-13 12:29:09 +0100 | [diff] [blame] | 1048 | |
| 1049 | PyDoc_STRVAR(_winapi_GetACP__doc__, |
| 1050 | "GetACP($module, /)\n" |
| 1051 | "--\n" |
| 1052 | "\n" |
| 1053 | "Get the current Windows ANSI code page identifier."); |
| 1054 | |
| 1055 | #define _WINAPI_GETACP_METHODDEF \ |
| 1056 | {"GetACP", (PyCFunction)_winapi_GetACP, METH_NOARGS, _winapi_GetACP__doc__}, |
| 1057 | |
| 1058 | static PyObject * |
| 1059 | _winapi_GetACP_impl(PyObject *module); |
| 1060 | |
| 1061 | static PyObject * |
| 1062 | _winapi_GetACP(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 1063 | { |
| 1064 | return _winapi_GetACP_impl(module); |
| 1065 | } |
Segev Finer | b2a6083 | 2017-12-18 11:28:19 +0200 | [diff] [blame] | 1066 | |
| 1067 | PyDoc_STRVAR(_winapi_GetFileType__doc__, |
| 1068 | "GetFileType($module, /, handle)\n" |
| 1069 | "--\n" |
| 1070 | "\n"); |
| 1071 | |
| 1072 | #define _WINAPI_GETFILETYPE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1073 | {"GetFileType", (PyCFunction)(void(*)(void))_winapi_GetFileType, METH_FASTCALL|METH_KEYWORDS, _winapi_GetFileType__doc__}, |
Segev Finer | b2a6083 | 2017-12-18 11:28:19 +0200 | [diff] [blame] | 1074 | |
| 1075 | static DWORD |
| 1076 | _winapi_GetFileType_impl(PyObject *module, HANDLE handle); |
| 1077 | |
| 1078 | static PyObject * |
| 1079 | _winapi_GetFileType(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1080 | { |
| 1081 | PyObject *return_value = NULL; |
| 1082 | static const char * const _keywords[] = {"handle", NULL}; |
| 1083 | static _PyArg_Parser _parser = {"" F_HANDLE ":GetFileType", _keywords, 0}; |
| 1084 | HANDLE handle; |
| 1085 | DWORD _return_value; |
| 1086 | |
| 1087 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 1088 | &handle)) { |
| 1089 | goto exit; |
| 1090 | } |
| 1091 | _return_value = _winapi_GetFileType_impl(module, handle); |
| 1092 | if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) { |
| 1093 | goto exit; |
| 1094 | } |
| 1095 | return_value = Py_BuildValue("k", _return_value); |
| 1096 | |
| 1097 | exit: |
| 1098 | return return_value; |
| 1099 | } |
Davin Potts | e895de3 | 2019-02-23 22:08:16 -0600 | [diff] [blame] | 1100 | /*[clinic end generated code: output=f3897898ea1da99d input=a9049054013a1b77]*/ |