• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 #  include "pycore_gc.h"          // PyGC_Head
7 #  include "pycore_runtime.h"     // _Py_ID()
8 #endif
9 #include "pycore_long.h"          // _PyLong_Size_t_Converter()
10 #include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
11 
12 PyDoc_STRVAR(_winapi_Overlapped_GetOverlappedResult__doc__,
13 "GetOverlappedResult($self, wait, /)\n"
14 "--\n"
15 "\n");
16 
17 #define _WINAPI_OVERLAPPED_GETOVERLAPPEDRESULT_METHODDEF    \
18     {"GetOverlappedResult", (PyCFunction)_winapi_Overlapped_GetOverlappedResult, METH_O, _winapi_Overlapped_GetOverlappedResult__doc__},
19 
20 static PyObject *
21 _winapi_Overlapped_GetOverlappedResult_impl(OverlappedObject *self, int wait);
22 
23 static PyObject *
_winapi_Overlapped_GetOverlappedResult(OverlappedObject * self,PyObject * arg)24 _winapi_Overlapped_GetOverlappedResult(OverlappedObject *self, PyObject *arg)
25 {
26     PyObject *return_value = NULL;
27     int wait;
28 
29     wait = PyObject_IsTrue(arg);
30     if (wait < 0) {
31         goto exit;
32     }
33     return_value = _winapi_Overlapped_GetOverlappedResult_impl(self, wait);
34 
35 exit:
36     return return_value;
37 }
38 
39 PyDoc_STRVAR(_winapi_Overlapped_getbuffer__doc__,
40 "getbuffer($self, /)\n"
41 "--\n"
42 "\n");
43 
44 #define _WINAPI_OVERLAPPED_GETBUFFER_METHODDEF    \
45     {"getbuffer", (PyCFunction)_winapi_Overlapped_getbuffer, METH_NOARGS, _winapi_Overlapped_getbuffer__doc__},
46 
47 static PyObject *
48 _winapi_Overlapped_getbuffer_impl(OverlappedObject *self);
49 
50 static PyObject *
_winapi_Overlapped_getbuffer(OverlappedObject * self,PyObject * Py_UNUSED (ignored))51 _winapi_Overlapped_getbuffer(OverlappedObject *self, PyObject *Py_UNUSED(ignored))
52 {
53     return _winapi_Overlapped_getbuffer_impl(self);
54 }
55 
56 PyDoc_STRVAR(_winapi_Overlapped_cancel__doc__,
57 "cancel($self, /)\n"
58 "--\n"
59 "\n");
60 
61 #define _WINAPI_OVERLAPPED_CANCEL_METHODDEF    \
62     {"cancel", (PyCFunction)_winapi_Overlapped_cancel, METH_NOARGS, _winapi_Overlapped_cancel__doc__},
63 
64 static PyObject *
65 _winapi_Overlapped_cancel_impl(OverlappedObject *self);
66 
67 static PyObject *
_winapi_Overlapped_cancel(OverlappedObject * self,PyObject * Py_UNUSED (ignored))68 _winapi_Overlapped_cancel(OverlappedObject *self, PyObject *Py_UNUSED(ignored))
69 {
70     return _winapi_Overlapped_cancel_impl(self);
71 }
72 
73 PyDoc_STRVAR(_winapi_CloseHandle__doc__,
74 "CloseHandle($module, handle, /)\n"
75 "--\n"
76 "\n"
77 "Close handle.");
78 
79 #define _WINAPI_CLOSEHANDLE_METHODDEF    \
80     {"CloseHandle", (PyCFunction)_winapi_CloseHandle, METH_O, _winapi_CloseHandle__doc__},
81 
82 static PyObject *
83 _winapi_CloseHandle_impl(PyObject *module, HANDLE handle);
84 
85 static PyObject *
_winapi_CloseHandle(PyObject * module,PyObject * arg)86 _winapi_CloseHandle(PyObject *module, PyObject *arg)
87 {
88     PyObject *return_value = NULL;
89     HANDLE handle;
90 
91     if (!PyArg_Parse(arg, "" F_HANDLE ":CloseHandle", &handle)) {
92         goto exit;
93     }
94     return_value = _winapi_CloseHandle_impl(module, handle);
95 
96 exit:
97     return return_value;
98 }
99 
100 PyDoc_STRVAR(_winapi_ConnectNamedPipe__doc__,
101 "ConnectNamedPipe($module, /, handle, overlapped=False)\n"
102 "--\n"
103 "\n");
104 
105 #define _WINAPI_CONNECTNAMEDPIPE_METHODDEF    \
106     {"ConnectNamedPipe", _PyCFunction_CAST(_winapi_ConnectNamedPipe), METH_FASTCALL|METH_KEYWORDS, _winapi_ConnectNamedPipe__doc__},
107 
108 static PyObject *
109 _winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle,
110                               int use_overlapped);
111 
112 static PyObject *
_winapi_ConnectNamedPipe(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)113 _winapi_ConnectNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
114 {
115     PyObject *return_value = NULL;
116     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
117 
118     #define NUM_KEYWORDS 2
119     static struct {
120         PyGC_Head _this_is_not_used;
121         PyObject_VAR_HEAD
122         PyObject *ob_item[NUM_KEYWORDS];
123     } _kwtuple = {
124         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
125         .ob_item = { &_Py_ID(handle), &_Py_ID(overlapped), },
126     };
127     #undef NUM_KEYWORDS
128     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
129 
130     #else  // !Py_BUILD_CORE
131     #  define KWTUPLE NULL
132     #endif  // !Py_BUILD_CORE
133 
134     static const char * const _keywords[] = {"handle", "overlapped", NULL};
135     static _PyArg_Parser _parser = {
136         .keywords = _keywords,
137         .format = "" F_HANDLE "|p:ConnectNamedPipe",
138         .kwtuple = KWTUPLE,
139     };
140     #undef KWTUPLE
141     HANDLE handle;
142     int use_overlapped = 0;
143 
144     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
145         &handle, &use_overlapped)) {
146         goto exit;
147     }
148     return_value = _winapi_ConnectNamedPipe_impl(module, handle, use_overlapped);
149 
150 exit:
151     return return_value;
152 }
153 
154 PyDoc_STRVAR(_winapi_CreateEventW__doc__,
155 "CreateEventW($module, /, security_attributes, manual_reset,\n"
156 "             initial_state, name)\n"
157 "--\n"
158 "\n");
159 
160 #define _WINAPI_CREATEEVENTW_METHODDEF    \
161     {"CreateEventW", _PyCFunction_CAST(_winapi_CreateEventW), METH_FASTCALL|METH_KEYWORDS, _winapi_CreateEventW__doc__},
162 
163 static HANDLE
164 _winapi_CreateEventW_impl(PyObject *module,
165                           LPSECURITY_ATTRIBUTES security_attributes,
166                           BOOL manual_reset, BOOL initial_state,
167                           LPCWSTR name);
168 
169 static PyObject *
_winapi_CreateEventW(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)170 _winapi_CreateEventW(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
171 {
172     PyObject *return_value = NULL;
173     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
174 
175     #define NUM_KEYWORDS 4
176     static struct {
177         PyGC_Head _this_is_not_used;
178         PyObject_VAR_HEAD
179         PyObject *ob_item[NUM_KEYWORDS];
180     } _kwtuple = {
181         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
182         .ob_item = { &_Py_ID(security_attributes), &_Py_ID(manual_reset), &_Py_ID(initial_state), &_Py_ID(name), },
183     };
184     #undef NUM_KEYWORDS
185     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
186 
187     #else  // !Py_BUILD_CORE
188     #  define KWTUPLE NULL
189     #endif  // !Py_BUILD_CORE
190 
191     static const char * const _keywords[] = {"security_attributes", "manual_reset", "initial_state", "name", NULL};
192     static _PyArg_Parser _parser = {
193         .keywords = _keywords,
194         .format = "" F_POINTER "iiO&:CreateEventW",
195         .kwtuple = KWTUPLE,
196     };
197     #undef KWTUPLE
198     LPSECURITY_ATTRIBUTES security_attributes;
199     BOOL manual_reset;
200     BOOL initial_state;
201     LPCWSTR name = NULL;
202     HANDLE _return_value;
203 
204     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
205         &security_attributes, &manual_reset, &initial_state, _PyUnicode_WideCharString_Opt_Converter, &name)) {
206         goto exit;
207     }
208     _return_value = _winapi_CreateEventW_impl(module, security_attributes, manual_reset, initial_state, name);
209     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
210         goto exit;
211     }
212     if (_return_value == NULL) {
213         Py_RETURN_NONE;
214     }
215     return_value = HANDLE_TO_PYNUM(_return_value);
216 
217 exit:
218     /* Cleanup for name */
219     PyMem_Free((void *)name);
220 
221     return return_value;
222 }
223 
224 PyDoc_STRVAR(_winapi_CreateFile__doc__,
225 "CreateFile($module, file_name, desired_access, share_mode,\n"
226 "           security_attributes, creation_disposition,\n"
227 "           flags_and_attributes, template_file, /)\n"
228 "--\n"
229 "\n");
230 
231 #define _WINAPI_CREATEFILE_METHODDEF    \
232     {"CreateFile", _PyCFunction_CAST(_winapi_CreateFile), METH_FASTCALL, _winapi_CreateFile__doc__},
233 
234 static HANDLE
235 _winapi_CreateFile_impl(PyObject *module, LPCWSTR file_name,
236                         DWORD desired_access, DWORD share_mode,
237                         LPSECURITY_ATTRIBUTES security_attributes,
238                         DWORD creation_disposition,
239                         DWORD flags_and_attributes, HANDLE template_file);
240 
241 static PyObject *
_winapi_CreateFile(PyObject * module,PyObject * const * args,Py_ssize_t nargs)242 _winapi_CreateFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
243 {
244     PyObject *return_value = NULL;
245     LPCWSTR file_name = NULL;
246     DWORD desired_access;
247     DWORD share_mode;
248     LPSECURITY_ATTRIBUTES security_attributes;
249     DWORD creation_disposition;
250     DWORD flags_and_attributes;
251     HANDLE template_file;
252     HANDLE _return_value;
253 
254     if (!_PyArg_ParseStack(args, nargs, "O&kk" F_POINTER "kk" F_HANDLE ":CreateFile",
255         _PyUnicode_WideCharString_Converter, &file_name, &desired_access, &share_mode, &security_attributes, &creation_disposition, &flags_and_attributes, &template_file)) {
256         goto exit;
257     }
258     _return_value = _winapi_CreateFile_impl(module, file_name, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, template_file);
259     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
260         goto exit;
261     }
262     if (_return_value == NULL) {
263         Py_RETURN_NONE;
264     }
265     return_value = HANDLE_TO_PYNUM(_return_value);
266 
267 exit:
268     /* Cleanup for file_name */
269     PyMem_Free((void *)file_name);
270 
271     return return_value;
272 }
273 
274 PyDoc_STRVAR(_winapi_CreateFileMapping__doc__,
275 "CreateFileMapping($module, file_handle, security_attributes, protect,\n"
276 "                  max_size_high, max_size_low, name, /)\n"
277 "--\n"
278 "\n");
279 
280 #define _WINAPI_CREATEFILEMAPPING_METHODDEF    \
281     {"CreateFileMapping", _PyCFunction_CAST(_winapi_CreateFileMapping), METH_FASTCALL, _winapi_CreateFileMapping__doc__},
282 
283 static HANDLE
284 _winapi_CreateFileMapping_impl(PyObject *module, HANDLE file_handle,
285                                LPSECURITY_ATTRIBUTES security_attributes,
286                                DWORD protect, DWORD max_size_high,
287                                DWORD max_size_low, LPCWSTR name);
288 
289 static PyObject *
_winapi_CreateFileMapping(PyObject * module,PyObject * const * args,Py_ssize_t nargs)290 _winapi_CreateFileMapping(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
291 {
292     PyObject *return_value = NULL;
293     HANDLE file_handle;
294     LPSECURITY_ATTRIBUTES security_attributes;
295     DWORD protect;
296     DWORD max_size_high;
297     DWORD max_size_low;
298     LPCWSTR name = NULL;
299     HANDLE _return_value;
300 
301     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_POINTER "kkkO&:CreateFileMapping",
302         &file_handle, &security_attributes, &protect, &max_size_high, &max_size_low, _PyUnicode_WideCharString_Converter, &name)) {
303         goto exit;
304     }
305     _return_value = _winapi_CreateFileMapping_impl(module, file_handle, security_attributes, protect, max_size_high, max_size_low, name);
306     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
307         goto exit;
308     }
309     if (_return_value == NULL) {
310         Py_RETURN_NONE;
311     }
312     return_value = HANDLE_TO_PYNUM(_return_value);
313 
314 exit:
315     /* Cleanup for name */
316     PyMem_Free((void *)name);
317 
318     return return_value;
319 }
320 
321 PyDoc_STRVAR(_winapi_CreateJunction__doc__,
322 "CreateJunction($module, src_path, dst_path, /)\n"
323 "--\n"
324 "\n");
325 
326 #define _WINAPI_CREATEJUNCTION_METHODDEF    \
327     {"CreateJunction", _PyCFunction_CAST(_winapi_CreateJunction), METH_FASTCALL, _winapi_CreateJunction__doc__},
328 
329 static PyObject *
330 _winapi_CreateJunction_impl(PyObject *module, LPCWSTR src_path,
331                             LPCWSTR dst_path);
332 
333 static PyObject *
_winapi_CreateJunction(PyObject * module,PyObject * const * args,Py_ssize_t nargs)334 _winapi_CreateJunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
335 {
336     PyObject *return_value = NULL;
337     LPCWSTR src_path = NULL;
338     LPCWSTR dst_path = NULL;
339 
340     if (!_PyArg_CheckPositional("CreateJunction", nargs, 2, 2)) {
341         goto exit;
342     }
343     if (!PyUnicode_Check(args[0])) {
344         _PyArg_BadArgument("CreateJunction", "argument 1", "str", args[0]);
345         goto exit;
346     }
347     src_path = PyUnicode_AsWideCharString(args[0], NULL);
348     if (src_path == NULL) {
349         goto exit;
350     }
351     if (!PyUnicode_Check(args[1])) {
352         _PyArg_BadArgument("CreateJunction", "argument 2", "str", args[1]);
353         goto exit;
354     }
355     dst_path = PyUnicode_AsWideCharString(args[1], NULL);
356     if (dst_path == NULL) {
357         goto exit;
358     }
359     return_value = _winapi_CreateJunction_impl(module, src_path, dst_path);
360 
361 exit:
362     /* Cleanup for src_path */
363     PyMem_Free((void *)src_path);
364     /* Cleanup for dst_path */
365     PyMem_Free((void *)dst_path);
366 
367     return return_value;
368 }
369 
370 PyDoc_STRVAR(_winapi_CreateMutexW__doc__,
371 "CreateMutexW($module, /, security_attributes, initial_owner, name)\n"
372 "--\n"
373 "\n");
374 
375 #define _WINAPI_CREATEMUTEXW_METHODDEF    \
376     {"CreateMutexW", _PyCFunction_CAST(_winapi_CreateMutexW), METH_FASTCALL|METH_KEYWORDS, _winapi_CreateMutexW__doc__},
377 
378 static HANDLE
379 _winapi_CreateMutexW_impl(PyObject *module,
380                           LPSECURITY_ATTRIBUTES security_attributes,
381                           BOOL initial_owner, LPCWSTR name);
382 
383 static PyObject *
_winapi_CreateMutexW(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)384 _winapi_CreateMutexW(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
385 {
386     PyObject *return_value = NULL;
387     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
388 
389     #define NUM_KEYWORDS 3
390     static struct {
391         PyGC_Head _this_is_not_used;
392         PyObject_VAR_HEAD
393         PyObject *ob_item[NUM_KEYWORDS];
394     } _kwtuple = {
395         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
396         .ob_item = { &_Py_ID(security_attributes), &_Py_ID(initial_owner), &_Py_ID(name), },
397     };
398     #undef NUM_KEYWORDS
399     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
400 
401     #else  // !Py_BUILD_CORE
402     #  define KWTUPLE NULL
403     #endif  // !Py_BUILD_CORE
404 
405     static const char * const _keywords[] = {"security_attributes", "initial_owner", "name", NULL};
406     static _PyArg_Parser _parser = {
407         .keywords = _keywords,
408         .format = "" F_POINTER "iO&:CreateMutexW",
409         .kwtuple = KWTUPLE,
410     };
411     #undef KWTUPLE
412     LPSECURITY_ATTRIBUTES security_attributes;
413     BOOL initial_owner;
414     LPCWSTR name = NULL;
415     HANDLE _return_value;
416 
417     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
418         &security_attributes, &initial_owner, _PyUnicode_WideCharString_Opt_Converter, &name)) {
419         goto exit;
420     }
421     _return_value = _winapi_CreateMutexW_impl(module, security_attributes, initial_owner, name);
422     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
423         goto exit;
424     }
425     if (_return_value == NULL) {
426         Py_RETURN_NONE;
427     }
428     return_value = HANDLE_TO_PYNUM(_return_value);
429 
430 exit:
431     /* Cleanup for name */
432     PyMem_Free((void *)name);
433 
434     return return_value;
435 }
436 
437 PyDoc_STRVAR(_winapi_CreateNamedPipe__doc__,
438 "CreateNamedPipe($module, name, open_mode, pipe_mode, max_instances,\n"
439 "                out_buffer_size, in_buffer_size, default_timeout,\n"
440 "                security_attributes, /)\n"
441 "--\n"
442 "\n");
443 
444 #define _WINAPI_CREATENAMEDPIPE_METHODDEF    \
445     {"CreateNamedPipe", _PyCFunction_CAST(_winapi_CreateNamedPipe), METH_FASTCALL, _winapi_CreateNamedPipe__doc__},
446 
447 static HANDLE
448 _winapi_CreateNamedPipe_impl(PyObject *module, LPCWSTR name, DWORD open_mode,
449                              DWORD pipe_mode, DWORD max_instances,
450                              DWORD out_buffer_size, DWORD in_buffer_size,
451                              DWORD default_timeout,
452                              LPSECURITY_ATTRIBUTES security_attributes);
453 
454 static PyObject *
_winapi_CreateNamedPipe(PyObject * module,PyObject * const * args,Py_ssize_t nargs)455 _winapi_CreateNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
456 {
457     PyObject *return_value = NULL;
458     LPCWSTR name = NULL;
459     DWORD open_mode;
460     DWORD pipe_mode;
461     DWORD max_instances;
462     DWORD out_buffer_size;
463     DWORD in_buffer_size;
464     DWORD default_timeout;
465     LPSECURITY_ATTRIBUTES security_attributes;
466     HANDLE _return_value;
467 
468     if (!_PyArg_ParseStack(args, nargs, "O&kkkkkk" F_POINTER ":CreateNamedPipe",
469         _PyUnicode_WideCharString_Converter, &name, &open_mode, &pipe_mode, &max_instances, &out_buffer_size, &in_buffer_size, &default_timeout, &security_attributes)) {
470         goto exit;
471     }
472     _return_value = _winapi_CreateNamedPipe_impl(module, name, open_mode, pipe_mode, max_instances, out_buffer_size, in_buffer_size, default_timeout, security_attributes);
473     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
474         goto exit;
475     }
476     if (_return_value == NULL) {
477         Py_RETURN_NONE;
478     }
479     return_value = HANDLE_TO_PYNUM(_return_value);
480 
481 exit:
482     /* Cleanup for name */
483     PyMem_Free((void *)name);
484 
485     return return_value;
486 }
487 
488 PyDoc_STRVAR(_winapi_CreatePipe__doc__,
489 "CreatePipe($module, pipe_attrs, size, /)\n"
490 "--\n"
491 "\n"
492 "Create an anonymous pipe.\n"
493 "\n"
494 "  pipe_attrs\n"
495 "    Ignored internally, can be None.\n"
496 "\n"
497 "Returns a 2-tuple of handles, to the read and write ends of the pipe.");
498 
499 #define _WINAPI_CREATEPIPE_METHODDEF    \
500     {"CreatePipe", _PyCFunction_CAST(_winapi_CreatePipe), METH_FASTCALL, _winapi_CreatePipe__doc__},
501 
502 static PyObject *
503 _winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, DWORD size);
504 
505 static PyObject *
_winapi_CreatePipe(PyObject * module,PyObject * const * args,Py_ssize_t nargs)506 _winapi_CreatePipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
507 {
508     PyObject *return_value = NULL;
509     PyObject *pipe_attrs;
510     DWORD size;
511 
512     if (!_PyArg_ParseStack(args, nargs, "Ok:CreatePipe",
513         &pipe_attrs, &size)) {
514         goto exit;
515     }
516     return_value = _winapi_CreatePipe_impl(module, pipe_attrs, size);
517 
518 exit:
519     return return_value;
520 }
521 
522 PyDoc_STRVAR(_winapi_CreateProcess__doc__,
523 "CreateProcess($module, application_name, command_line, proc_attrs,\n"
524 "              thread_attrs, inherit_handles, creation_flags,\n"
525 "              env_mapping, current_directory, startup_info, /)\n"
526 "--\n"
527 "\n"
528 "Create a new process and its primary thread.\n"
529 "\n"
530 "  command_line\n"
531 "    Can be str or None\n"
532 "  proc_attrs\n"
533 "    Ignored internally, can be None.\n"
534 "  thread_attrs\n"
535 "    Ignored internally, can be None.\n"
536 "\n"
537 "The return value is a tuple of the process handle, thread handle,\n"
538 "process ID, and thread ID.");
539 
540 #define _WINAPI_CREATEPROCESS_METHODDEF    \
541     {"CreateProcess", _PyCFunction_CAST(_winapi_CreateProcess), METH_FASTCALL, _winapi_CreateProcess__doc__},
542 
543 static PyObject *
544 _winapi_CreateProcess_impl(PyObject *module, const wchar_t *application_name,
545                            PyObject *command_line, PyObject *proc_attrs,
546                            PyObject *thread_attrs, BOOL inherit_handles,
547                            DWORD creation_flags, PyObject *env_mapping,
548                            const wchar_t *current_directory,
549                            PyObject *startup_info);
550 
551 static PyObject *
_winapi_CreateProcess(PyObject * module,PyObject * const * args,Py_ssize_t nargs)552 _winapi_CreateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
553 {
554     PyObject *return_value = NULL;
555     const wchar_t *application_name = NULL;
556     PyObject *command_line;
557     PyObject *proc_attrs;
558     PyObject *thread_attrs;
559     BOOL inherit_handles;
560     DWORD creation_flags;
561     PyObject *env_mapping;
562     const wchar_t *current_directory = NULL;
563     PyObject *startup_info;
564 
565     if (!_PyArg_ParseStack(args, nargs, "O&OOOikOO&O:CreateProcess",
566         _PyUnicode_WideCharString_Opt_Converter, &application_name, &command_line, &proc_attrs, &thread_attrs, &inherit_handles, &creation_flags, &env_mapping, _PyUnicode_WideCharString_Opt_Converter, &current_directory, &startup_info)) {
567         goto exit;
568     }
569     return_value = _winapi_CreateProcess_impl(module, application_name, command_line, proc_attrs, thread_attrs, inherit_handles, creation_flags, env_mapping, current_directory, startup_info);
570 
571 exit:
572     /* Cleanup for application_name */
573     PyMem_Free((void *)application_name);
574     /* Cleanup for current_directory */
575     PyMem_Free((void *)current_directory);
576 
577     return return_value;
578 }
579 
580 PyDoc_STRVAR(_winapi_DuplicateHandle__doc__,
581 "DuplicateHandle($module, source_process_handle, source_handle,\n"
582 "                target_process_handle, desired_access, inherit_handle,\n"
583 "                options=0, /)\n"
584 "--\n"
585 "\n"
586 "Return a duplicate handle object.\n"
587 "\n"
588 "The duplicate handle refers to the same object as the original\n"
589 "handle. Therefore, any changes to the object are reflected\n"
590 "through both handles.");
591 
592 #define _WINAPI_DUPLICATEHANDLE_METHODDEF    \
593     {"DuplicateHandle", _PyCFunction_CAST(_winapi_DuplicateHandle), METH_FASTCALL, _winapi_DuplicateHandle__doc__},
594 
595 static HANDLE
596 _winapi_DuplicateHandle_impl(PyObject *module, HANDLE source_process_handle,
597                              HANDLE source_handle,
598                              HANDLE target_process_handle,
599                              DWORD desired_access, BOOL inherit_handle,
600                              DWORD options);
601 
602 static PyObject *
_winapi_DuplicateHandle(PyObject * module,PyObject * const * args,Py_ssize_t nargs)603 _winapi_DuplicateHandle(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
604 {
605     PyObject *return_value = NULL;
606     HANDLE source_process_handle;
607     HANDLE source_handle;
608     HANDLE target_process_handle;
609     DWORD desired_access;
610     BOOL inherit_handle;
611     DWORD options = 0;
612     HANDLE _return_value;
613 
614     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_HANDLE "" F_HANDLE "ki|k:DuplicateHandle",
615         &source_process_handle, &source_handle, &target_process_handle, &desired_access, &inherit_handle, &options)) {
616         goto exit;
617     }
618     _return_value = _winapi_DuplicateHandle_impl(module, source_process_handle, source_handle, target_process_handle, desired_access, inherit_handle, options);
619     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
620         goto exit;
621     }
622     if (_return_value == NULL) {
623         Py_RETURN_NONE;
624     }
625     return_value = HANDLE_TO_PYNUM(_return_value);
626 
627 exit:
628     return return_value;
629 }
630 
631 PyDoc_STRVAR(_winapi_ExitProcess__doc__,
632 "ExitProcess($module, ExitCode, /)\n"
633 "--\n"
634 "\n");
635 
636 #define _WINAPI_EXITPROCESS_METHODDEF    \
637     {"ExitProcess", (PyCFunction)_winapi_ExitProcess, METH_O, _winapi_ExitProcess__doc__},
638 
639 static PyObject *
640 _winapi_ExitProcess_impl(PyObject *module, UINT ExitCode);
641 
642 static PyObject *
_winapi_ExitProcess(PyObject * module,PyObject * arg)643 _winapi_ExitProcess(PyObject *module, PyObject *arg)
644 {
645     PyObject *return_value = NULL;
646     UINT ExitCode;
647 
648     if (!PyArg_Parse(arg, "I:ExitProcess", &ExitCode)) {
649         goto exit;
650     }
651     return_value = _winapi_ExitProcess_impl(module, ExitCode);
652 
653 exit:
654     return return_value;
655 }
656 
657 PyDoc_STRVAR(_winapi_GetCurrentProcess__doc__,
658 "GetCurrentProcess($module, /)\n"
659 "--\n"
660 "\n"
661 "Return a handle object for the current process.");
662 
663 #define _WINAPI_GETCURRENTPROCESS_METHODDEF    \
664     {"GetCurrentProcess", (PyCFunction)_winapi_GetCurrentProcess, METH_NOARGS, _winapi_GetCurrentProcess__doc__},
665 
666 static HANDLE
667 _winapi_GetCurrentProcess_impl(PyObject *module);
668 
669 static PyObject *
_winapi_GetCurrentProcess(PyObject * module,PyObject * Py_UNUSED (ignored))670 _winapi_GetCurrentProcess(PyObject *module, PyObject *Py_UNUSED(ignored))
671 {
672     PyObject *return_value = NULL;
673     HANDLE _return_value;
674 
675     _return_value = _winapi_GetCurrentProcess_impl(module);
676     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
677         goto exit;
678     }
679     if (_return_value == NULL) {
680         Py_RETURN_NONE;
681     }
682     return_value = HANDLE_TO_PYNUM(_return_value);
683 
684 exit:
685     return return_value;
686 }
687 
688 PyDoc_STRVAR(_winapi_GetExitCodeProcess__doc__,
689 "GetExitCodeProcess($module, process, /)\n"
690 "--\n"
691 "\n"
692 "Return the termination status of the specified process.");
693 
694 #define _WINAPI_GETEXITCODEPROCESS_METHODDEF    \
695     {"GetExitCodeProcess", (PyCFunction)_winapi_GetExitCodeProcess, METH_O, _winapi_GetExitCodeProcess__doc__},
696 
697 static DWORD
698 _winapi_GetExitCodeProcess_impl(PyObject *module, HANDLE process);
699 
700 static PyObject *
_winapi_GetExitCodeProcess(PyObject * module,PyObject * arg)701 _winapi_GetExitCodeProcess(PyObject *module, PyObject *arg)
702 {
703     PyObject *return_value = NULL;
704     HANDLE process;
705     DWORD _return_value;
706 
707     if (!PyArg_Parse(arg, "" F_HANDLE ":GetExitCodeProcess", &process)) {
708         goto exit;
709     }
710     _return_value = _winapi_GetExitCodeProcess_impl(module, process);
711     if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
712         goto exit;
713     }
714     return_value = PyLong_FromUnsignedLong(_return_value);
715 
716 exit:
717     return return_value;
718 }
719 
720 PyDoc_STRVAR(_winapi_GetLastError__doc__,
721 "GetLastError($module, /)\n"
722 "--\n"
723 "\n");
724 
725 #define _WINAPI_GETLASTERROR_METHODDEF    \
726     {"GetLastError", (PyCFunction)_winapi_GetLastError, METH_NOARGS, _winapi_GetLastError__doc__},
727 
728 static DWORD
729 _winapi_GetLastError_impl(PyObject *module);
730 
731 static PyObject *
_winapi_GetLastError(PyObject * module,PyObject * Py_UNUSED (ignored))732 _winapi_GetLastError(PyObject *module, PyObject *Py_UNUSED(ignored))
733 {
734     PyObject *return_value = NULL;
735     DWORD _return_value;
736 
737     _return_value = _winapi_GetLastError_impl(module);
738     if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
739         goto exit;
740     }
741     return_value = PyLong_FromUnsignedLong(_return_value);
742 
743 exit:
744     return return_value;
745 }
746 
747 PyDoc_STRVAR(_winapi_GetLongPathName__doc__,
748 "GetLongPathName($module, /, path)\n"
749 "--\n"
750 "\n"
751 "Return the long version of the provided path.\n"
752 "\n"
753 "If the path is already in its long form, returns the same value.\n"
754 "\n"
755 "The path must already be a \'str\'. If the type is not known, use\n"
756 "os.fsdecode before calling this function.");
757 
758 #define _WINAPI_GETLONGPATHNAME_METHODDEF    \
759     {"GetLongPathName", _PyCFunction_CAST(_winapi_GetLongPathName), METH_FASTCALL|METH_KEYWORDS, _winapi_GetLongPathName__doc__},
760 
761 static PyObject *
762 _winapi_GetLongPathName_impl(PyObject *module, LPCWSTR path);
763 
764 static PyObject *
_winapi_GetLongPathName(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)765 _winapi_GetLongPathName(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
766 {
767     PyObject *return_value = NULL;
768     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
769 
770     #define NUM_KEYWORDS 1
771     static struct {
772         PyGC_Head _this_is_not_used;
773         PyObject_VAR_HEAD
774         PyObject *ob_item[NUM_KEYWORDS];
775     } _kwtuple = {
776         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
777         .ob_item = { &_Py_ID(path), },
778     };
779     #undef NUM_KEYWORDS
780     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
781 
782     #else  // !Py_BUILD_CORE
783     #  define KWTUPLE NULL
784     #endif  // !Py_BUILD_CORE
785 
786     static const char * const _keywords[] = {"path", NULL};
787     static _PyArg_Parser _parser = {
788         .keywords = _keywords,
789         .fname = "GetLongPathName",
790         .kwtuple = KWTUPLE,
791     };
792     #undef KWTUPLE
793     PyObject *argsbuf[1];
794     LPCWSTR path = NULL;
795 
796     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
797     if (!args) {
798         goto exit;
799     }
800     if (!PyUnicode_Check(args[0])) {
801         _PyArg_BadArgument("GetLongPathName", "argument 'path'", "str", args[0]);
802         goto exit;
803     }
804     path = PyUnicode_AsWideCharString(args[0], NULL);
805     if (path == NULL) {
806         goto exit;
807     }
808     return_value = _winapi_GetLongPathName_impl(module, path);
809 
810 exit:
811     /* Cleanup for path */
812     PyMem_Free((void *)path);
813 
814     return return_value;
815 }
816 
817 PyDoc_STRVAR(_winapi_GetModuleFileName__doc__,
818 "GetModuleFileName($module, module_handle, /)\n"
819 "--\n"
820 "\n"
821 "Return the fully-qualified path for the file that contains module.\n"
822 "\n"
823 "The module must have been loaded by the current process.\n"
824 "\n"
825 "The module parameter should be a handle to the loaded module\n"
826 "whose path is being requested. If this parameter is 0,\n"
827 "GetModuleFileName retrieves the path of the executable file\n"
828 "of the current process.");
829 
830 #define _WINAPI_GETMODULEFILENAME_METHODDEF    \
831     {"GetModuleFileName", (PyCFunction)_winapi_GetModuleFileName, METH_O, _winapi_GetModuleFileName__doc__},
832 
833 static PyObject *
834 _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle);
835 
836 static PyObject *
_winapi_GetModuleFileName(PyObject * module,PyObject * arg)837 _winapi_GetModuleFileName(PyObject *module, PyObject *arg)
838 {
839     PyObject *return_value = NULL;
840     HMODULE module_handle;
841 
842     if (!PyArg_Parse(arg, "" F_HANDLE ":GetModuleFileName", &module_handle)) {
843         goto exit;
844     }
845     return_value = _winapi_GetModuleFileName_impl(module, module_handle);
846 
847 exit:
848     return return_value;
849 }
850 
851 PyDoc_STRVAR(_winapi_GetShortPathName__doc__,
852 "GetShortPathName($module, /, path)\n"
853 "--\n"
854 "\n"
855 "Return the short version of the provided path.\n"
856 "\n"
857 "If the path is already in its short form, returns the same value.\n"
858 "\n"
859 "The path must already be a \'str\'. If the type is not known, use\n"
860 "os.fsdecode before calling this function.");
861 
862 #define _WINAPI_GETSHORTPATHNAME_METHODDEF    \
863     {"GetShortPathName", _PyCFunction_CAST(_winapi_GetShortPathName), METH_FASTCALL|METH_KEYWORDS, _winapi_GetShortPathName__doc__},
864 
865 static PyObject *
866 _winapi_GetShortPathName_impl(PyObject *module, LPCWSTR path);
867 
868 static PyObject *
_winapi_GetShortPathName(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)869 _winapi_GetShortPathName(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
870 {
871     PyObject *return_value = NULL;
872     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
873 
874     #define NUM_KEYWORDS 1
875     static struct {
876         PyGC_Head _this_is_not_used;
877         PyObject_VAR_HEAD
878         PyObject *ob_item[NUM_KEYWORDS];
879     } _kwtuple = {
880         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
881         .ob_item = { &_Py_ID(path), },
882     };
883     #undef NUM_KEYWORDS
884     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
885 
886     #else  // !Py_BUILD_CORE
887     #  define KWTUPLE NULL
888     #endif  // !Py_BUILD_CORE
889 
890     static const char * const _keywords[] = {"path", NULL};
891     static _PyArg_Parser _parser = {
892         .keywords = _keywords,
893         .fname = "GetShortPathName",
894         .kwtuple = KWTUPLE,
895     };
896     #undef KWTUPLE
897     PyObject *argsbuf[1];
898     LPCWSTR path = NULL;
899 
900     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
901     if (!args) {
902         goto exit;
903     }
904     if (!PyUnicode_Check(args[0])) {
905         _PyArg_BadArgument("GetShortPathName", "argument 'path'", "str", args[0]);
906         goto exit;
907     }
908     path = PyUnicode_AsWideCharString(args[0], NULL);
909     if (path == NULL) {
910         goto exit;
911     }
912     return_value = _winapi_GetShortPathName_impl(module, path);
913 
914 exit:
915     /* Cleanup for path */
916     PyMem_Free((void *)path);
917 
918     return return_value;
919 }
920 
921 PyDoc_STRVAR(_winapi_GetStdHandle__doc__,
922 "GetStdHandle($module, std_handle, /)\n"
923 "--\n"
924 "\n"
925 "Return a handle to the specified standard device.\n"
926 "\n"
927 "  std_handle\n"
928 "    One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE.\n"
929 "\n"
930 "The integer associated with the handle object is returned.");
931 
932 #define _WINAPI_GETSTDHANDLE_METHODDEF    \
933     {"GetStdHandle", (PyCFunction)_winapi_GetStdHandle, METH_O, _winapi_GetStdHandle__doc__},
934 
935 static HANDLE
936 _winapi_GetStdHandle_impl(PyObject *module, DWORD std_handle);
937 
938 static PyObject *
_winapi_GetStdHandle(PyObject * module,PyObject * arg)939 _winapi_GetStdHandle(PyObject *module, PyObject *arg)
940 {
941     PyObject *return_value = NULL;
942     DWORD std_handle;
943     HANDLE _return_value;
944 
945     if (!PyArg_Parse(arg, "k:GetStdHandle", &std_handle)) {
946         goto exit;
947     }
948     _return_value = _winapi_GetStdHandle_impl(module, std_handle);
949     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
950         goto exit;
951     }
952     if (_return_value == NULL) {
953         Py_RETURN_NONE;
954     }
955     return_value = HANDLE_TO_PYNUM(_return_value);
956 
957 exit:
958     return return_value;
959 }
960 
961 PyDoc_STRVAR(_winapi_GetVersion__doc__,
962 "GetVersion($module, /)\n"
963 "--\n"
964 "\n"
965 "Return the version number of the current operating system.");
966 
967 #define _WINAPI_GETVERSION_METHODDEF    \
968     {"GetVersion", (PyCFunction)_winapi_GetVersion, METH_NOARGS, _winapi_GetVersion__doc__},
969 
970 static long
971 _winapi_GetVersion_impl(PyObject *module);
972 
973 static PyObject *
_winapi_GetVersion(PyObject * module,PyObject * Py_UNUSED (ignored))974 _winapi_GetVersion(PyObject *module, PyObject *Py_UNUSED(ignored))
975 {
976     PyObject *return_value = NULL;
977     long _return_value;
978 
979     _return_value = _winapi_GetVersion_impl(module);
980     if ((_return_value == -1) && PyErr_Occurred()) {
981         goto exit;
982     }
983     return_value = PyLong_FromLong(_return_value);
984 
985 exit:
986     return return_value;
987 }
988 
989 PyDoc_STRVAR(_winapi_MapViewOfFile__doc__,
990 "MapViewOfFile($module, file_map, desired_access, file_offset_high,\n"
991 "              file_offset_low, number_bytes, /)\n"
992 "--\n"
993 "\n");
994 
995 #define _WINAPI_MAPVIEWOFFILE_METHODDEF    \
996     {"MapViewOfFile", _PyCFunction_CAST(_winapi_MapViewOfFile), METH_FASTCALL, _winapi_MapViewOfFile__doc__},
997 
998 static LPVOID
999 _winapi_MapViewOfFile_impl(PyObject *module, HANDLE file_map,
1000                            DWORD desired_access, DWORD file_offset_high,
1001                            DWORD file_offset_low, size_t number_bytes);
1002 
1003 static PyObject *
_winapi_MapViewOfFile(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1004 _winapi_MapViewOfFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1005 {
1006     PyObject *return_value = NULL;
1007     HANDLE file_map;
1008     DWORD desired_access;
1009     DWORD file_offset_high;
1010     DWORD file_offset_low;
1011     size_t number_bytes;
1012     LPVOID _return_value;
1013 
1014     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "kkkO&:MapViewOfFile",
1015         &file_map, &desired_access, &file_offset_high, &file_offset_low, _PyLong_Size_t_Converter, &number_bytes)) {
1016         goto exit;
1017     }
1018     _return_value = _winapi_MapViewOfFile_impl(module, file_map, desired_access, file_offset_high, file_offset_low, number_bytes);
1019     if ((_return_value == NULL) && PyErr_Occurred()) {
1020         goto exit;
1021     }
1022     return_value = HANDLE_TO_PYNUM(_return_value);
1023 
1024 exit:
1025     return return_value;
1026 }
1027 
1028 PyDoc_STRVAR(_winapi_UnmapViewOfFile__doc__,
1029 "UnmapViewOfFile($module, address, /)\n"
1030 "--\n"
1031 "\n");
1032 
1033 #define _WINAPI_UNMAPVIEWOFFILE_METHODDEF    \
1034     {"UnmapViewOfFile", (PyCFunction)_winapi_UnmapViewOfFile, METH_O, _winapi_UnmapViewOfFile__doc__},
1035 
1036 static PyObject *
1037 _winapi_UnmapViewOfFile_impl(PyObject *module, LPCVOID address);
1038 
1039 static PyObject *
_winapi_UnmapViewOfFile(PyObject * module,PyObject * arg)1040 _winapi_UnmapViewOfFile(PyObject *module, PyObject *arg)
1041 {
1042     PyObject *return_value = NULL;
1043     LPCVOID address;
1044 
1045     if (!PyArg_Parse(arg, "" F_POINTER ":UnmapViewOfFile", &address)) {
1046         goto exit;
1047     }
1048     return_value = _winapi_UnmapViewOfFile_impl(module, address);
1049 
1050 exit:
1051     return return_value;
1052 }
1053 
1054 PyDoc_STRVAR(_winapi_OpenEventW__doc__,
1055 "OpenEventW($module, /, desired_access, inherit_handle, name)\n"
1056 "--\n"
1057 "\n");
1058 
1059 #define _WINAPI_OPENEVENTW_METHODDEF    \
1060     {"OpenEventW", _PyCFunction_CAST(_winapi_OpenEventW), METH_FASTCALL|METH_KEYWORDS, _winapi_OpenEventW__doc__},
1061 
1062 static HANDLE
1063 _winapi_OpenEventW_impl(PyObject *module, DWORD desired_access,
1064                         BOOL inherit_handle, LPCWSTR name);
1065 
1066 static PyObject *
_winapi_OpenEventW(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1067 _winapi_OpenEventW(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1068 {
1069     PyObject *return_value = NULL;
1070     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1071 
1072     #define NUM_KEYWORDS 3
1073     static struct {
1074         PyGC_Head _this_is_not_used;
1075         PyObject_VAR_HEAD
1076         PyObject *ob_item[NUM_KEYWORDS];
1077     } _kwtuple = {
1078         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1079         .ob_item = { &_Py_ID(desired_access), &_Py_ID(inherit_handle), &_Py_ID(name), },
1080     };
1081     #undef NUM_KEYWORDS
1082     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1083 
1084     #else  // !Py_BUILD_CORE
1085     #  define KWTUPLE NULL
1086     #endif  // !Py_BUILD_CORE
1087 
1088     static const char * const _keywords[] = {"desired_access", "inherit_handle", "name", NULL};
1089     static _PyArg_Parser _parser = {
1090         .keywords = _keywords,
1091         .format = "kiO&:OpenEventW",
1092         .kwtuple = KWTUPLE,
1093     };
1094     #undef KWTUPLE
1095     DWORD desired_access;
1096     BOOL inherit_handle;
1097     LPCWSTR name = NULL;
1098     HANDLE _return_value;
1099 
1100     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1101         &desired_access, &inherit_handle, _PyUnicode_WideCharString_Converter, &name)) {
1102         goto exit;
1103     }
1104     _return_value = _winapi_OpenEventW_impl(module, desired_access, inherit_handle, name);
1105     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
1106         goto exit;
1107     }
1108     if (_return_value == NULL) {
1109         Py_RETURN_NONE;
1110     }
1111     return_value = HANDLE_TO_PYNUM(_return_value);
1112 
1113 exit:
1114     /* Cleanup for name */
1115     PyMem_Free((void *)name);
1116 
1117     return return_value;
1118 }
1119 
1120 PyDoc_STRVAR(_winapi_OpenMutexW__doc__,
1121 "OpenMutexW($module, /, desired_access, inherit_handle, name)\n"
1122 "--\n"
1123 "\n");
1124 
1125 #define _WINAPI_OPENMUTEXW_METHODDEF    \
1126     {"OpenMutexW", _PyCFunction_CAST(_winapi_OpenMutexW), METH_FASTCALL|METH_KEYWORDS, _winapi_OpenMutexW__doc__},
1127 
1128 static HANDLE
1129 _winapi_OpenMutexW_impl(PyObject *module, DWORD desired_access,
1130                         BOOL inherit_handle, LPCWSTR name);
1131 
1132 static PyObject *
_winapi_OpenMutexW(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1133 _winapi_OpenMutexW(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1134 {
1135     PyObject *return_value = NULL;
1136     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1137 
1138     #define NUM_KEYWORDS 3
1139     static struct {
1140         PyGC_Head _this_is_not_used;
1141         PyObject_VAR_HEAD
1142         PyObject *ob_item[NUM_KEYWORDS];
1143     } _kwtuple = {
1144         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1145         .ob_item = { &_Py_ID(desired_access), &_Py_ID(inherit_handle), &_Py_ID(name), },
1146     };
1147     #undef NUM_KEYWORDS
1148     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1149 
1150     #else  // !Py_BUILD_CORE
1151     #  define KWTUPLE NULL
1152     #endif  // !Py_BUILD_CORE
1153 
1154     static const char * const _keywords[] = {"desired_access", "inherit_handle", "name", NULL};
1155     static _PyArg_Parser _parser = {
1156         .keywords = _keywords,
1157         .format = "kiO&:OpenMutexW",
1158         .kwtuple = KWTUPLE,
1159     };
1160     #undef KWTUPLE
1161     DWORD desired_access;
1162     BOOL inherit_handle;
1163     LPCWSTR name = NULL;
1164     HANDLE _return_value;
1165 
1166     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1167         &desired_access, &inherit_handle, _PyUnicode_WideCharString_Converter, &name)) {
1168         goto exit;
1169     }
1170     _return_value = _winapi_OpenMutexW_impl(module, desired_access, inherit_handle, name);
1171     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
1172         goto exit;
1173     }
1174     if (_return_value == NULL) {
1175         Py_RETURN_NONE;
1176     }
1177     return_value = HANDLE_TO_PYNUM(_return_value);
1178 
1179 exit:
1180     /* Cleanup for name */
1181     PyMem_Free((void *)name);
1182 
1183     return return_value;
1184 }
1185 
1186 PyDoc_STRVAR(_winapi_OpenFileMapping__doc__,
1187 "OpenFileMapping($module, desired_access, inherit_handle, name, /)\n"
1188 "--\n"
1189 "\n");
1190 
1191 #define _WINAPI_OPENFILEMAPPING_METHODDEF    \
1192     {"OpenFileMapping", _PyCFunction_CAST(_winapi_OpenFileMapping), METH_FASTCALL, _winapi_OpenFileMapping__doc__},
1193 
1194 static HANDLE
1195 _winapi_OpenFileMapping_impl(PyObject *module, DWORD desired_access,
1196                              BOOL inherit_handle, LPCWSTR name);
1197 
1198 static PyObject *
_winapi_OpenFileMapping(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1199 _winapi_OpenFileMapping(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1200 {
1201     PyObject *return_value = NULL;
1202     DWORD desired_access;
1203     BOOL inherit_handle;
1204     LPCWSTR name = NULL;
1205     HANDLE _return_value;
1206 
1207     if (!_PyArg_ParseStack(args, nargs, "kiO&:OpenFileMapping",
1208         &desired_access, &inherit_handle, _PyUnicode_WideCharString_Converter, &name)) {
1209         goto exit;
1210     }
1211     _return_value = _winapi_OpenFileMapping_impl(module, desired_access, inherit_handle, name);
1212     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
1213         goto exit;
1214     }
1215     if (_return_value == NULL) {
1216         Py_RETURN_NONE;
1217     }
1218     return_value = HANDLE_TO_PYNUM(_return_value);
1219 
1220 exit:
1221     /* Cleanup for name */
1222     PyMem_Free((void *)name);
1223 
1224     return return_value;
1225 }
1226 
1227 PyDoc_STRVAR(_winapi_OpenProcess__doc__,
1228 "OpenProcess($module, desired_access, inherit_handle, process_id, /)\n"
1229 "--\n"
1230 "\n");
1231 
1232 #define _WINAPI_OPENPROCESS_METHODDEF    \
1233     {"OpenProcess", _PyCFunction_CAST(_winapi_OpenProcess), METH_FASTCALL, _winapi_OpenProcess__doc__},
1234 
1235 static HANDLE
1236 _winapi_OpenProcess_impl(PyObject *module, DWORD desired_access,
1237                          BOOL inherit_handle, DWORD process_id);
1238 
1239 static PyObject *
_winapi_OpenProcess(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1240 _winapi_OpenProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1241 {
1242     PyObject *return_value = NULL;
1243     DWORD desired_access;
1244     BOOL inherit_handle;
1245     DWORD process_id;
1246     HANDLE _return_value;
1247 
1248     if (!_PyArg_ParseStack(args, nargs, "kik:OpenProcess",
1249         &desired_access, &inherit_handle, &process_id)) {
1250         goto exit;
1251     }
1252     _return_value = _winapi_OpenProcess_impl(module, desired_access, inherit_handle, process_id);
1253     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
1254         goto exit;
1255     }
1256     if (_return_value == NULL) {
1257         Py_RETURN_NONE;
1258     }
1259     return_value = HANDLE_TO_PYNUM(_return_value);
1260 
1261 exit:
1262     return return_value;
1263 }
1264 
1265 PyDoc_STRVAR(_winapi_PeekNamedPipe__doc__,
1266 "PeekNamedPipe($module, handle, size=0, /)\n"
1267 "--\n"
1268 "\n");
1269 
1270 #define _WINAPI_PEEKNAMEDPIPE_METHODDEF    \
1271     {"PeekNamedPipe", _PyCFunction_CAST(_winapi_PeekNamedPipe), METH_FASTCALL, _winapi_PeekNamedPipe__doc__},
1272 
1273 static PyObject *
1274 _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size);
1275 
1276 static PyObject *
_winapi_PeekNamedPipe(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1277 _winapi_PeekNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1278 {
1279     PyObject *return_value = NULL;
1280     HANDLE handle;
1281     int size = 0;
1282 
1283     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "|i:PeekNamedPipe",
1284         &handle, &size)) {
1285         goto exit;
1286     }
1287     return_value = _winapi_PeekNamedPipe_impl(module, handle, size);
1288 
1289 exit:
1290     return return_value;
1291 }
1292 
1293 PyDoc_STRVAR(_winapi_LCMapStringEx__doc__,
1294 "LCMapStringEx($module, /, locale, flags, src)\n"
1295 "--\n"
1296 "\n");
1297 
1298 #define _WINAPI_LCMAPSTRINGEX_METHODDEF    \
1299     {"LCMapStringEx", _PyCFunction_CAST(_winapi_LCMapStringEx), METH_FASTCALL|METH_KEYWORDS, _winapi_LCMapStringEx__doc__},
1300 
1301 static PyObject *
1302 _winapi_LCMapStringEx_impl(PyObject *module, LPCWSTR locale, DWORD flags,
1303                            PyObject *src);
1304 
1305 static PyObject *
_winapi_LCMapStringEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1306 _winapi_LCMapStringEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1307 {
1308     PyObject *return_value = NULL;
1309     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1310 
1311     #define NUM_KEYWORDS 3
1312     static struct {
1313         PyGC_Head _this_is_not_used;
1314         PyObject_VAR_HEAD
1315         PyObject *ob_item[NUM_KEYWORDS];
1316     } _kwtuple = {
1317         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1318         .ob_item = { &_Py_ID(locale), &_Py_ID(flags), &_Py_ID(src), },
1319     };
1320     #undef NUM_KEYWORDS
1321     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1322 
1323     #else  // !Py_BUILD_CORE
1324     #  define KWTUPLE NULL
1325     #endif  // !Py_BUILD_CORE
1326 
1327     static const char * const _keywords[] = {"locale", "flags", "src", NULL};
1328     static _PyArg_Parser _parser = {
1329         .keywords = _keywords,
1330         .format = "O&kU:LCMapStringEx",
1331         .kwtuple = KWTUPLE,
1332     };
1333     #undef KWTUPLE
1334     LPCWSTR locale = NULL;
1335     DWORD flags;
1336     PyObject *src;
1337 
1338     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1339         _PyUnicode_WideCharString_Converter, &locale, &flags, &src)) {
1340         goto exit;
1341     }
1342     return_value = _winapi_LCMapStringEx_impl(module, locale, flags, src);
1343 
1344 exit:
1345     /* Cleanup for locale */
1346     PyMem_Free((void *)locale);
1347 
1348     return return_value;
1349 }
1350 
1351 PyDoc_STRVAR(_winapi_ReadFile__doc__,
1352 "ReadFile($module, /, handle, size, overlapped=False)\n"
1353 "--\n"
1354 "\n");
1355 
1356 #define _WINAPI_READFILE_METHODDEF    \
1357     {"ReadFile", _PyCFunction_CAST(_winapi_ReadFile), METH_FASTCALL|METH_KEYWORDS, _winapi_ReadFile__doc__},
1358 
1359 static PyObject *
1360 _winapi_ReadFile_impl(PyObject *module, HANDLE handle, DWORD size,
1361                       int use_overlapped);
1362 
1363 static PyObject *
_winapi_ReadFile(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1364 _winapi_ReadFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1365 {
1366     PyObject *return_value = NULL;
1367     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1368 
1369     #define NUM_KEYWORDS 3
1370     static struct {
1371         PyGC_Head _this_is_not_used;
1372         PyObject_VAR_HEAD
1373         PyObject *ob_item[NUM_KEYWORDS];
1374     } _kwtuple = {
1375         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1376         .ob_item = { &_Py_ID(handle), &_Py_ID(size), &_Py_ID(overlapped), },
1377     };
1378     #undef NUM_KEYWORDS
1379     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1380 
1381     #else  // !Py_BUILD_CORE
1382     #  define KWTUPLE NULL
1383     #endif  // !Py_BUILD_CORE
1384 
1385     static const char * const _keywords[] = {"handle", "size", "overlapped", NULL};
1386     static _PyArg_Parser _parser = {
1387         .keywords = _keywords,
1388         .format = "" F_HANDLE "k|p:ReadFile",
1389         .kwtuple = KWTUPLE,
1390     };
1391     #undef KWTUPLE
1392     HANDLE handle;
1393     DWORD size;
1394     int use_overlapped = 0;
1395 
1396     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1397         &handle, &size, &use_overlapped)) {
1398         goto exit;
1399     }
1400     return_value = _winapi_ReadFile_impl(module, handle, size, use_overlapped);
1401 
1402 exit:
1403     return return_value;
1404 }
1405 
1406 PyDoc_STRVAR(_winapi_ReleaseMutex__doc__,
1407 "ReleaseMutex($module, /, mutex)\n"
1408 "--\n"
1409 "\n");
1410 
1411 #define _WINAPI_RELEASEMUTEX_METHODDEF    \
1412     {"ReleaseMutex", _PyCFunction_CAST(_winapi_ReleaseMutex), METH_FASTCALL|METH_KEYWORDS, _winapi_ReleaseMutex__doc__},
1413 
1414 static PyObject *
1415 _winapi_ReleaseMutex_impl(PyObject *module, HANDLE mutex);
1416 
1417 static PyObject *
_winapi_ReleaseMutex(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1418 _winapi_ReleaseMutex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1419 {
1420     PyObject *return_value = NULL;
1421     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1422 
1423     #define NUM_KEYWORDS 1
1424     static struct {
1425         PyGC_Head _this_is_not_used;
1426         PyObject_VAR_HEAD
1427         PyObject *ob_item[NUM_KEYWORDS];
1428     } _kwtuple = {
1429         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1430         .ob_item = { &_Py_ID(mutex), },
1431     };
1432     #undef NUM_KEYWORDS
1433     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1434 
1435     #else  // !Py_BUILD_CORE
1436     #  define KWTUPLE NULL
1437     #endif  // !Py_BUILD_CORE
1438 
1439     static const char * const _keywords[] = {"mutex", NULL};
1440     static _PyArg_Parser _parser = {
1441         .keywords = _keywords,
1442         .format = "" F_HANDLE ":ReleaseMutex",
1443         .kwtuple = KWTUPLE,
1444     };
1445     #undef KWTUPLE
1446     HANDLE mutex;
1447 
1448     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1449         &mutex)) {
1450         goto exit;
1451     }
1452     return_value = _winapi_ReleaseMutex_impl(module, mutex);
1453 
1454 exit:
1455     return return_value;
1456 }
1457 
1458 PyDoc_STRVAR(_winapi_ResetEvent__doc__,
1459 "ResetEvent($module, /, event)\n"
1460 "--\n"
1461 "\n");
1462 
1463 #define _WINAPI_RESETEVENT_METHODDEF    \
1464     {"ResetEvent", _PyCFunction_CAST(_winapi_ResetEvent), METH_FASTCALL|METH_KEYWORDS, _winapi_ResetEvent__doc__},
1465 
1466 static PyObject *
1467 _winapi_ResetEvent_impl(PyObject *module, HANDLE event);
1468 
1469 static PyObject *
_winapi_ResetEvent(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1470 _winapi_ResetEvent(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1471 {
1472     PyObject *return_value = NULL;
1473     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1474 
1475     #define NUM_KEYWORDS 1
1476     static struct {
1477         PyGC_Head _this_is_not_used;
1478         PyObject_VAR_HEAD
1479         PyObject *ob_item[NUM_KEYWORDS];
1480     } _kwtuple = {
1481         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1482         .ob_item = { &_Py_ID(event), },
1483     };
1484     #undef NUM_KEYWORDS
1485     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1486 
1487     #else  // !Py_BUILD_CORE
1488     #  define KWTUPLE NULL
1489     #endif  // !Py_BUILD_CORE
1490 
1491     static const char * const _keywords[] = {"event", NULL};
1492     static _PyArg_Parser _parser = {
1493         .keywords = _keywords,
1494         .format = "" F_HANDLE ":ResetEvent",
1495         .kwtuple = KWTUPLE,
1496     };
1497     #undef KWTUPLE
1498     HANDLE event;
1499 
1500     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1501         &event)) {
1502         goto exit;
1503     }
1504     return_value = _winapi_ResetEvent_impl(module, event);
1505 
1506 exit:
1507     return return_value;
1508 }
1509 
1510 PyDoc_STRVAR(_winapi_SetEvent__doc__,
1511 "SetEvent($module, /, event)\n"
1512 "--\n"
1513 "\n");
1514 
1515 #define _WINAPI_SETEVENT_METHODDEF    \
1516     {"SetEvent", _PyCFunction_CAST(_winapi_SetEvent), METH_FASTCALL|METH_KEYWORDS, _winapi_SetEvent__doc__},
1517 
1518 static PyObject *
1519 _winapi_SetEvent_impl(PyObject *module, HANDLE event);
1520 
1521 static PyObject *
_winapi_SetEvent(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1522 _winapi_SetEvent(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1523 {
1524     PyObject *return_value = NULL;
1525     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1526 
1527     #define NUM_KEYWORDS 1
1528     static struct {
1529         PyGC_Head _this_is_not_used;
1530         PyObject_VAR_HEAD
1531         PyObject *ob_item[NUM_KEYWORDS];
1532     } _kwtuple = {
1533         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1534         .ob_item = { &_Py_ID(event), },
1535     };
1536     #undef NUM_KEYWORDS
1537     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1538 
1539     #else  // !Py_BUILD_CORE
1540     #  define KWTUPLE NULL
1541     #endif  // !Py_BUILD_CORE
1542 
1543     static const char * const _keywords[] = {"event", NULL};
1544     static _PyArg_Parser _parser = {
1545         .keywords = _keywords,
1546         .format = "" F_HANDLE ":SetEvent",
1547         .kwtuple = KWTUPLE,
1548     };
1549     #undef KWTUPLE
1550     HANDLE event;
1551 
1552     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1553         &event)) {
1554         goto exit;
1555     }
1556     return_value = _winapi_SetEvent_impl(module, event);
1557 
1558 exit:
1559     return return_value;
1560 }
1561 
1562 PyDoc_STRVAR(_winapi_SetNamedPipeHandleState__doc__,
1563 "SetNamedPipeHandleState($module, named_pipe, mode,\n"
1564 "                        max_collection_count, collect_data_timeout, /)\n"
1565 "--\n"
1566 "\n");
1567 
1568 #define _WINAPI_SETNAMEDPIPEHANDLESTATE_METHODDEF    \
1569     {"SetNamedPipeHandleState", _PyCFunction_CAST(_winapi_SetNamedPipeHandleState), METH_FASTCALL, _winapi_SetNamedPipeHandleState__doc__},
1570 
1571 static PyObject *
1572 _winapi_SetNamedPipeHandleState_impl(PyObject *module, HANDLE named_pipe,
1573                                      PyObject *mode,
1574                                      PyObject *max_collection_count,
1575                                      PyObject *collect_data_timeout);
1576 
1577 static PyObject *
_winapi_SetNamedPipeHandleState(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1578 _winapi_SetNamedPipeHandleState(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1579 {
1580     PyObject *return_value = NULL;
1581     HANDLE named_pipe;
1582     PyObject *mode;
1583     PyObject *max_collection_count;
1584     PyObject *collect_data_timeout;
1585 
1586     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "OOO:SetNamedPipeHandleState",
1587         &named_pipe, &mode, &max_collection_count, &collect_data_timeout)) {
1588         goto exit;
1589     }
1590     return_value = _winapi_SetNamedPipeHandleState_impl(module, named_pipe, mode, max_collection_count, collect_data_timeout);
1591 
1592 exit:
1593     return return_value;
1594 }
1595 
1596 PyDoc_STRVAR(_winapi_TerminateProcess__doc__,
1597 "TerminateProcess($module, handle, exit_code, /)\n"
1598 "--\n"
1599 "\n"
1600 "Terminate the specified process and all of its threads.");
1601 
1602 #define _WINAPI_TERMINATEPROCESS_METHODDEF    \
1603     {"TerminateProcess", _PyCFunction_CAST(_winapi_TerminateProcess), METH_FASTCALL, _winapi_TerminateProcess__doc__},
1604 
1605 static PyObject *
1606 _winapi_TerminateProcess_impl(PyObject *module, HANDLE handle,
1607                               UINT exit_code);
1608 
1609 static PyObject *
_winapi_TerminateProcess(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1610 _winapi_TerminateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1611 {
1612     PyObject *return_value = NULL;
1613     HANDLE handle;
1614     UINT exit_code;
1615 
1616     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "I:TerminateProcess",
1617         &handle, &exit_code)) {
1618         goto exit;
1619     }
1620     return_value = _winapi_TerminateProcess_impl(module, handle, exit_code);
1621 
1622 exit:
1623     return return_value;
1624 }
1625 
1626 PyDoc_STRVAR(_winapi_VirtualQuerySize__doc__,
1627 "VirtualQuerySize($module, address, /)\n"
1628 "--\n"
1629 "\n");
1630 
1631 #define _WINAPI_VIRTUALQUERYSIZE_METHODDEF    \
1632     {"VirtualQuerySize", (PyCFunction)_winapi_VirtualQuerySize, METH_O, _winapi_VirtualQuerySize__doc__},
1633 
1634 static size_t
1635 _winapi_VirtualQuerySize_impl(PyObject *module, LPCVOID address);
1636 
1637 static PyObject *
_winapi_VirtualQuerySize(PyObject * module,PyObject * arg)1638 _winapi_VirtualQuerySize(PyObject *module, PyObject *arg)
1639 {
1640     PyObject *return_value = NULL;
1641     LPCVOID address;
1642     size_t _return_value;
1643 
1644     if (!PyArg_Parse(arg, "" F_POINTER ":VirtualQuerySize", &address)) {
1645         goto exit;
1646     }
1647     _return_value = _winapi_VirtualQuerySize_impl(module, address);
1648     if ((_return_value == (size_t)-1) && PyErr_Occurred()) {
1649         goto exit;
1650     }
1651     return_value = PyLong_FromSize_t(_return_value);
1652 
1653 exit:
1654     return return_value;
1655 }
1656 
1657 PyDoc_STRVAR(_winapi_WaitNamedPipe__doc__,
1658 "WaitNamedPipe($module, name, timeout, /)\n"
1659 "--\n"
1660 "\n");
1661 
1662 #define _WINAPI_WAITNAMEDPIPE_METHODDEF    \
1663     {"WaitNamedPipe", _PyCFunction_CAST(_winapi_WaitNamedPipe), METH_FASTCALL, _winapi_WaitNamedPipe__doc__},
1664 
1665 static PyObject *
1666 _winapi_WaitNamedPipe_impl(PyObject *module, LPCWSTR name, DWORD timeout);
1667 
1668 static PyObject *
_winapi_WaitNamedPipe(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1669 _winapi_WaitNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1670 {
1671     PyObject *return_value = NULL;
1672     LPCWSTR name = NULL;
1673     DWORD timeout;
1674 
1675     if (!_PyArg_ParseStack(args, nargs, "O&k:WaitNamedPipe",
1676         _PyUnicode_WideCharString_Converter, &name, &timeout)) {
1677         goto exit;
1678     }
1679     return_value = _winapi_WaitNamedPipe_impl(module, name, timeout);
1680 
1681 exit:
1682     /* Cleanup for name */
1683     PyMem_Free((void *)name);
1684 
1685     return return_value;
1686 }
1687 
1688 PyDoc_STRVAR(_winapi_BatchedWaitForMultipleObjects__doc__,
1689 "BatchedWaitForMultipleObjects($module, /, handle_seq, wait_all,\n"
1690 "                              milliseconds=_winapi.INFINITE)\n"
1691 "--\n"
1692 "\n"
1693 "Supports a larger number of handles than WaitForMultipleObjects\n"
1694 "\n"
1695 "Note that the handles may be waited on other threads, which could cause\n"
1696 "issues for objects like mutexes that become associated with the thread\n"
1697 "that was waiting for them. Objects may also be left signalled, even if\n"
1698 "the wait fails.\n"
1699 "\n"
1700 "It is recommended to use WaitForMultipleObjects whenever possible, and\n"
1701 "only switch to BatchedWaitForMultipleObjects for scenarios where you\n"
1702 "control all the handles involved, such as your own thread pool or\n"
1703 "files, and all wait objects are left unmodified by a wait (for example,\n"
1704 "manual reset events, threads, and files/pipes).\n"
1705 "\n"
1706 "Overlapped handles returned from this module use manual reset events.");
1707 
1708 #define _WINAPI_BATCHEDWAITFORMULTIPLEOBJECTS_METHODDEF    \
1709     {"BatchedWaitForMultipleObjects", _PyCFunction_CAST(_winapi_BatchedWaitForMultipleObjects), METH_FASTCALL|METH_KEYWORDS, _winapi_BatchedWaitForMultipleObjects__doc__},
1710 
1711 static PyObject *
1712 _winapi_BatchedWaitForMultipleObjects_impl(PyObject *module,
1713                                            PyObject *handle_seq,
1714                                            BOOL wait_all, DWORD milliseconds);
1715 
1716 static PyObject *
_winapi_BatchedWaitForMultipleObjects(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1717 _winapi_BatchedWaitForMultipleObjects(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1718 {
1719     PyObject *return_value = NULL;
1720     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1721 
1722     #define NUM_KEYWORDS 3
1723     static struct {
1724         PyGC_Head _this_is_not_used;
1725         PyObject_VAR_HEAD
1726         PyObject *ob_item[NUM_KEYWORDS];
1727     } _kwtuple = {
1728         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1729         .ob_item = { &_Py_ID(handle_seq), &_Py_ID(wait_all), &_Py_ID(milliseconds), },
1730     };
1731     #undef NUM_KEYWORDS
1732     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1733 
1734     #else  // !Py_BUILD_CORE
1735     #  define KWTUPLE NULL
1736     #endif  // !Py_BUILD_CORE
1737 
1738     static const char * const _keywords[] = {"handle_seq", "wait_all", "milliseconds", NULL};
1739     static _PyArg_Parser _parser = {
1740         .keywords = _keywords,
1741         .format = "Oi|k:BatchedWaitForMultipleObjects",
1742         .kwtuple = KWTUPLE,
1743     };
1744     #undef KWTUPLE
1745     PyObject *handle_seq;
1746     BOOL wait_all;
1747     DWORD milliseconds = INFINITE;
1748 
1749     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1750         &handle_seq, &wait_all, &milliseconds)) {
1751         goto exit;
1752     }
1753     return_value = _winapi_BatchedWaitForMultipleObjects_impl(module, handle_seq, wait_all, milliseconds);
1754 
1755 exit:
1756     return return_value;
1757 }
1758 
1759 PyDoc_STRVAR(_winapi_WaitForMultipleObjects__doc__,
1760 "WaitForMultipleObjects($module, handle_seq, wait_flag,\n"
1761 "                       milliseconds=_winapi.INFINITE, /)\n"
1762 "--\n"
1763 "\n");
1764 
1765 #define _WINAPI_WAITFORMULTIPLEOBJECTS_METHODDEF    \
1766     {"WaitForMultipleObjects", _PyCFunction_CAST(_winapi_WaitForMultipleObjects), METH_FASTCALL, _winapi_WaitForMultipleObjects__doc__},
1767 
1768 static PyObject *
1769 _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq,
1770                                     BOOL wait_flag, DWORD milliseconds);
1771 
1772 static PyObject *
_winapi_WaitForMultipleObjects(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1773 _winapi_WaitForMultipleObjects(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1774 {
1775     PyObject *return_value = NULL;
1776     PyObject *handle_seq;
1777     BOOL wait_flag;
1778     DWORD milliseconds = INFINITE;
1779 
1780     if (!_PyArg_ParseStack(args, nargs, "Oi|k:WaitForMultipleObjects",
1781         &handle_seq, &wait_flag, &milliseconds)) {
1782         goto exit;
1783     }
1784     return_value = _winapi_WaitForMultipleObjects_impl(module, handle_seq, wait_flag, milliseconds);
1785 
1786 exit:
1787     return return_value;
1788 }
1789 
1790 PyDoc_STRVAR(_winapi_WaitForSingleObject__doc__,
1791 "WaitForSingleObject($module, handle, milliseconds, /)\n"
1792 "--\n"
1793 "\n"
1794 "Wait for a single object.\n"
1795 "\n"
1796 "Wait until the specified object is in the signaled state or\n"
1797 "the time-out interval elapses. The timeout value is specified\n"
1798 "in milliseconds.");
1799 
1800 #define _WINAPI_WAITFORSINGLEOBJECT_METHODDEF    \
1801     {"WaitForSingleObject", _PyCFunction_CAST(_winapi_WaitForSingleObject), METH_FASTCALL, _winapi_WaitForSingleObject__doc__},
1802 
1803 static long
1804 _winapi_WaitForSingleObject_impl(PyObject *module, HANDLE handle,
1805                                  DWORD milliseconds);
1806 
1807 static PyObject *
_winapi_WaitForSingleObject(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1808 _winapi_WaitForSingleObject(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1809 {
1810     PyObject *return_value = NULL;
1811     HANDLE handle;
1812     DWORD milliseconds;
1813     long _return_value;
1814 
1815     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "k:WaitForSingleObject",
1816         &handle, &milliseconds)) {
1817         goto exit;
1818     }
1819     _return_value = _winapi_WaitForSingleObject_impl(module, handle, milliseconds);
1820     if ((_return_value == -1) && PyErr_Occurred()) {
1821         goto exit;
1822     }
1823     return_value = PyLong_FromLong(_return_value);
1824 
1825 exit:
1826     return return_value;
1827 }
1828 
1829 PyDoc_STRVAR(_winapi_WriteFile__doc__,
1830 "WriteFile($module, /, handle, buffer, overlapped=False)\n"
1831 "--\n"
1832 "\n");
1833 
1834 #define _WINAPI_WRITEFILE_METHODDEF    \
1835     {"WriteFile", _PyCFunction_CAST(_winapi_WriteFile), METH_FASTCALL|METH_KEYWORDS, _winapi_WriteFile__doc__},
1836 
1837 static PyObject *
1838 _winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer,
1839                        int use_overlapped);
1840 
1841 static PyObject *
_winapi_WriteFile(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1842 _winapi_WriteFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1843 {
1844     PyObject *return_value = NULL;
1845     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1846 
1847     #define NUM_KEYWORDS 3
1848     static struct {
1849         PyGC_Head _this_is_not_used;
1850         PyObject_VAR_HEAD
1851         PyObject *ob_item[NUM_KEYWORDS];
1852     } _kwtuple = {
1853         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1854         .ob_item = { &_Py_ID(handle), &_Py_ID(buffer), &_Py_ID(overlapped), },
1855     };
1856     #undef NUM_KEYWORDS
1857     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1858 
1859     #else  // !Py_BUILD_CORE
1860     #  define KWTUPLE NULL
1861     #endif  // !Py_BUILD_CORE
1862 
1863     static const char * const _keywords[] = {"handle", "buffer", "overlapped", NULL};
1864     static _PyArg_Parser _parser = {
1865         .keywords = _keywords,
1866         .format = "" F_HANDLE "O|p:WriteFile",
1867         .kwtuple = KWTUPLE,
1868     };
1869     #undef KWTUPLE
1870     HANDLE handle;
1871     PyObject *buffer;
1872     int use_overlapped = 0;
1873 
1874     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1875         &handle, &buffer, &use_overlapped)) {
1876         goto exit;
1877     }
1878     return_value = _winapi_WriteFile_impl(module, handle, buffer, use_overlapped);
1879 
1880 exit:
1881     return return_value;
1882 }
1883 
1884 PyDoc_STRVAR(_winapi_GetACP__doc__,
1885 "GetACP($module, /)\n"
1886 "--\n"
1887 "\n"
1888 "Get the current Windows ANSI code page identifier.");
1889 
1890 #define _WINAPI_GETACP_METHODDEF    \
1891     {"GetACP", (PyCFunction)_winapi_GetACP, METH_NOARGS, _winapi_GetACP__doc__},
1892 
1893 static PyObject *
1894 _winapi_GetACP_impl(PyObject *module);
1895 
1896 static PyObject *
_winapi_GetACP(PyObject * module,PyObject * Py_UNUSED (ignored))1897 _winapi_GetACP(PyObject *module, PyObject *Py_UNUSED(ignored))
1898 {
1899     return _winapi_GetACP_impl(module);
1900 }
1901 
1902 PyDoc_STRVAR(_winapi_GetFileType__doc__,
1903 "GetFileType($module, /, handle)\n"
1904 "--\n"
1905 "\n");
1906 
1907 #define _WINAPI_GETFILETYPE_METHODDEF    \
1908     {"GetFileType", _PyCFunction_CAST(_winapi_GetFileType), METH_FASTCALL|METH_KEYWORDS, _winapi_GetFileType__doc__},
1909 
1910 static DWORD
1911 _winapi_GetFileType_impl(PyObject *module, HANDLE handle);
1912 
1913 static PyObject *
_winapi_GetFileType(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1914 _winapi_GetFileType(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1915 {
1916     PyObject *return_value = NULL;
1917     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1918 
1919     #define NUM_KEYWORDS 1
1920     static struct {
1921         PyGC_Head _this_is_not_used;
1922         PyObject_VAR_HEAD
1923         PyObject *ob_item[NUM_KEYWORDS];
1924     } _kwtuple = {
1925         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1926         .ob_item = { &_Py_ID(handle), },
1927     };
1928     #undef NUM_KEYWORDS
1929     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1930 
1931     #else  // !Py_BUILD_CORE
1932     #  define KWTUPLE NULL
1933     #endif  // !Py_BUILD_CORE
1934 
1935     static const char * const _keywords[] = {"handle", NULL};
1936     static _PyArg_Parser _parser = {
1937         .keywords = _keywords,
1938         .format = "" F_HANDLE ":GetFileType",
1939         .kwtuple = KWTUPLE,
1940     };
1941     #undef KWTUPLE
1942     HANDLE handle;
1943     DWORD _return_value;
1944 
1945     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1946         &handle)) {
1947         goto exit;
1948     }
1949     _return_value = _winapi_GetFileType_impl(module, handle);
1950     if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
1951         goto exit;
1952     }
1953     return_value = PyLong_FromUnsignedLong(_return_value);
1954 
1955 exit:
1956     return return_value;
1957 }
1958 
1959 PyDoc_STRVAR(_winapi__mimetypes_read_windows_registry__doc__,
1960 "_mimetypes_read_windows_registry($module, /, on_type_read)\n"
1961 "--\n"
1962 "\n"
1963 "Optimized function for reading all known MIME types from the registry.\n"
1964 "\n"
1965 "*on_type_read* is a callable taking *type* and *ext* arguments, as for\n"
1966 "MimeTypes.add_type.");
1967 
1968 #define _WINAPI__MIMETYPES_READ_WINDOWS_REGISTRY_METHODDEF    \
1969     {"_mimetypes_read_windows_registry", _PyCFunction_CAST(_winapi__mimetypes_read_windows_registry), METH_FASTCALL|METH_KEYWORDS, _winapi__mimetypes_read_windows_registry__doc__},
1970 
1971 static PyObject *
1972 _winapi__mimetypes_read_windows_registry_impl(PyObject *module,
1973                                               PyObject *on_type_read);
1974 
1975 static PyObject *
_winapi__mimetypes_read_windows_registry(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1976 _winapi__mimetypes_read_windows_registry(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1977 {
1978     PyObject *return_value = NULL;
1979     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1980 
1981     #define NUM_KEYWORDS 1
1982     static struct {
1983         PyGC_Head _this_is_not_used;
1984         PyObject_VAR_HEAD
1985         PyObject *ob_item[NUM_KEYWORDS];
1986     } _kwtuple = {
1987         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1988         .ob_item = { &_Py_ID(on_type_read), },
1989     };
1990     #undef NUM_KEYWORDS
1991     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1992 
1993     #else  // !Py_BUILD_CORE
1994     #  define KWTUPLE NULL
1995     #endif  // !Py_BUILD_CORE
1996 
1997     static const char * const _keywords[] = {"on_type_read", NULL};
1998     static _PyArg_Parser _parser = {
1999         .keywords = _keywords,
2000         .fname = "_mimetypes_read_windows_registry",
2001         .kwtuple = KWTUPLE,
2002     };
2003     #undef KWTUPLE
2004     PyObject *argsbuf[1];
2005     PyObject *on_type_read;
2006 
2007     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
2008     if (!args) {
2009         goto exit;
2010     }
2011     on_type_read = args[0];
2012     return_value = _winapi__mimetypes_read_windows_registry_impl(module, on_type_read);
2013 
2014 exit:
2015     return return_value;
2016 }
2017 
2018 PyDoc_STRVAR(_winapi_NeedCurrentDirectoryForExePath__doc__,
2019 "NeedCurrentDirectoryForExePath($module, exe_name, /)\n"
2020 "--\n"
2021 "\n");
2022 
2023 #define _WINAPI_NEEDCURRENTDIRECTORYFOREXEPATH_METHODDEF    \
2024     {"NeedCurrentDirectoryForExePath", (PyCFunction)_winapi_NeedCurrentDirectoryForExePath, METH_O, _winapi_NeedCurrentDirectoryForExePath__doc__},
2025 
2026 static int
2027 _winapi_NeedCurrentDirectoryForExePath_impl(PyObject *module,
2028                                             LPCWSTR exe_name);
2029 
2030 static PyObject *
_winapi_NeedCurrentDirectoryForExePath(PyObject * module,PyObject * arg)2031 _winapi_NeedCurrentDirectoryForExePath(PyObject *module, PyObject *arg)
2032 {
2033     PyObject *return_value = NULL;
2034     LPCWSTR exe_name = NULL;
2035     int _return_value;
2036 
2037     if (!PyUnicode_Check(arg)) {
2038         _PyArg_BadArgument("NeedCurrentDirectoryForExePath", "argument", "str", arg);
2039         goto exit;
2040     }
2041     exe_name = PyUnicode_AsWideCharString(arg, NULL);
2042     if (exe_name == NULL) {
2043         goto exit;
2044     }
2045     _return_value = _winapi_NeedCurrentDirectoryForExePath_impl(module, exe_name);
2046     if ((_return_value == -1) && PyErr_Occurred()) {
2047         goto exit;
2048     }
2049     return_value = PyBool_FromLong((long)_return_value);
2050 
2051 exit:
2052     /* Cleanup for exe_name */
2053     PyMem_Free((void *)exe_name);
2054 
2055     return return_value;
2056 }
2057 
2058 PyDoc_STRVAR(_winapi_CopyFile2__doc__,
2059 "CopyFile2($module, /, existing_file_name, new_file_name, flags,\n"
2060 "          progress_routine=None)\n"
2061 "--\n"
2062 "\n"
2063 "Copies a file from one name to a new name.\n"
2064 "\n"
2065 "This is implemented using the CopyFile2 API, which preserves all stat\n"
2066 "and metadata information apart from security attributes.\n"
2067 "\n"
2068 "progress_routine is reserved for future use, but is currently not\n"
2069 "implemented. Its value is ignored.");
2070 
2071 #define _WINAPI_COPYFILE2_METHODDEF    \
2072     {"CopyFile2", _PyCFunction_CAST(_winapi_CopyFile2), METH_FASTCALL|METH_KEYWORDS, _winapi_CopyFile2__doc__},
2073 
2074 static PyObject *
2075 _winapi_CopyFile2_impl(PyObject *module, LPCWSTR existing_file_name,
2076                        LPCWSTR new_file_name, DWORD flags,
2077                        PyObject *progress_routine);
2078 
2079 static PyObject *
_winapi_CopyFile2(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)2080 _winapi_CopyFile2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2081 {
2082     PyObject *return_value = NULL;
2083     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2084 
2085     #define NUM_KEYWORDS 4
2086     static struct {
2087         PyGC_Head _this_is_not_used;
2088         PyObject_VAR_HEAD
2089         PyObject *ob_item[NUM_KEYWORDS];
2090     } _kwtuple = {
2091         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2092         .ob_item = { &_Py_ID(existing_file_name), &_Py_ID(new_file_name), &_Py_ID(flags), &_Py_ID(progress_routine), },
2093     };
2094     #undef NUM_KEYWORDS
2095     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2096 
2097     #else  // !Py_BUILD_CORE
2098     #  define KWTUPLE NULL
2099     #endif  // !Py_BUILD_CORE
2100 
2101     static const char * const _keywords[] = {"existing_file_name", "new_file_name", "flags", "progress_routine", NULL};
2102     static _PyArg_Parser _parser = {
2103         .keywords = _keywords,
2104         .format = "O&O&k|O:CopyFile2",
2105         .kwtuple = KWTUPLE,
2106     };
2107     #undef KWTUPLE
2108     LPCWSTR existing_file_name = NULL;
2109     LPCWSTR new_file_name = NULL;
2110     DWORD flags;
2111     PyObject *progress_routine = Py_None;
2112 
2113     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
2114         _PyUnicode_WideCharString_Converter, &existing_file_name, _PyUnicode_WideCharString_Converter, &new_file_name, &flags, &progress_routine)) {
2115         goto exit;
2116     }
2117     return_value = _winapi_CopyFile2_impl(module, existing_file_name, new_file_name, flags, progress_routine);
2118 
2119 exit:
2120     /* Cleanup for existing_file_name */
2121     PyMem_Free((void *)existing_file_name);
2122     /* Cleanup for new_file_name */
2123     PyMem_Free((void *)new_file_name);
2124 
2125     return return_value;
2126 }
2127 /*[clinic end generated code: output=2304c62187a90140 input=a9049054013a1b77]*/
2128