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 *
_winapi_Overlapped_GetOverlappedResult(OverlappedObject * self,PyObject * arg)17 _winapi_Overlapped_GetOverlappedResult(OverlappedObject *self, PyObject *arg)
18 {
19     PyObject *return_value = NULL;
20     int wait;
21 
22     wait = PyObject_IsTrue(arg);
23     if (wait < 0) {
24         goto exit;
25     }
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 *
_winapi_Overlapped_getbuffer(OverlappedObject * self,PyObject * Py_UNUSED (ignored))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 *
_winapi_Overlapped_cancel(OverlappedObject * self,PyObject * Py_UNUSED (ignored))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 *
76 _winapi_CloseHandle_impl(PyObject *module, HANDLE handle);
77 
78 static PyObject *
_winapi_CloseHandle(PyObject * module,PyObject * arg)79 _winapi_CloseHandle(PyObject *module, PyObject *arg)
80 {
81     PyObject *return_value = NULL;
82     HANDLE handle;
83 
84     if (!PyArg_Parse(arg, "" F_HANDLE ":CloseHandle", &handle)) {
85         goto exit;
86     }
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    \
99     {"ConnectNamedPipe", _PyCFunction_CAST(_winapi_ConnectNamedPipe), METH_FASTCALL|METH_KEYWORDS, _winapi_ConnectNamedPipe__doc__},
100 
101 static PyObject *
102 _winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle,
103                               int use_overlapped);
104 
105 static PyObject *
_winapi_ConnectNamedPipe(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)106 _winapi_ConnectNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
107 {
108     PyObject *return_value = NULL;
109     static const char * const _keywords[] = {"handle", "overlapped", NULL};
110     static _PyArg_Parser _parser = {"" F_HANDLE "|i:ConnectNamedPipe", _keywords, 0};
111     HANDLE handle;
112     int use_overlapped = 0;
113 
114     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
115         &handle, &use_overlapped)) {
116         goto exit;
117     }
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    \
132     {"CreateFile", _PyCFunction_CAST(_winapi_CreateFile), METH_FASTCALL, _winapi_CreateFile__doc__},
133 
134 static HANDLE
135 _winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name,
136                         DWORD desired_access, DWORD share_mode,
137                         LPSECURITY_ATTRIBUTES security_attributes,
138                         DWORD creation_disposition,
139                         DWORD flags_and_attributes, HANDLE template_file);
140 
141 static PyObject *
_winapi_CreateFile(PyObject * module,PyObject * const * args,Py_ssize_t nargs)142 _winapi_CreateFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
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 
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)) {
156         goto exit;
157     }
158     _return_value = _winapi_CreateFile_impl(module, file_name, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, template_file);
159     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
160         goto exit;
161     }
162     if (_return_value == NULL) {
163         Py_RETURN_NONE;
164     }
165     return_value = HANDLE_TO_PYNUM(_return_value);
166 
167 exit:
168     return return_value;
169 }
170 
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_CAST(_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 *
_winapi_CreateFileMapping(PyObject * module,PyObject * const * args,Py_ssize_t nargs)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 = NULL;
196     HANDLE _return_value;
197 
198     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_POINTER "kkkO&:CreateFileMapping",
199         &file_handle, &security_attributes, &protect, &max_size_high, &max_size_low, _PyUnicode_WideCharString_Converter, &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     /* Cleanup for name */
213     #if !USE_UNICODE_WCHAR_CACHE
214     PyMem_Free((void *)name);
215     #endif /* USE_UNICODE_WCHAR_CACHE */
216 
217     return return_value;
218 }
219 
220 PyDoc_STRVAR(_winapi_CreateJunction__doc__,
221 "CreateJunction($module, src_path, dst_path, /)\n"
222 "--\n"
223 "\n");
224 
225 #define _WINAPI_CREATEJUNCTION_METHODDEF    \
226     {"CreateJunction", _PyCFunction_CAST(_winapi_CreateJunction), METH_FASTCALL, _winapi_CreateJunction__doc__},
227 
228 static PyObject *
229 _winapi_CreateJunction_impl(PyObject *module, LPCWSTR src_path,
230                             LPCWSTR dst_path);
231 
232 static PyObject *
_winapi_CreateJunction(PyObject * module,PyObject * const * args,Py_ssize_t nargs)233 _winapi_CreateJunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
234 {
235     PyObject *return_value = NULL;
236     LPCWSTR src_path = NULL;
237     LPCWSTR dst_path = NULL;
238 
239     if (!_PyArg_CheckPositional("CreateJunction", nargs, 2, 2)) {
240         goto exit;
241     }
242     if (!PyUnicode_Check(args[0])) {
243         _PyArg_BadArgument("CreateJunction", "argument 1", "str", args[0]);
244         goto exit;
245     }
246     #if USE_UNICODE_WCHAR_CACHE
247     src_path = _PyUnicode_AsUnicode(args[0]);
248     #else /* USE_UNICODE_WCHAR_CACHE */
249     src_path = PyUnicode_AsWideCharString(args[0], NULL);
250     #endif /* USE_UNICODE_WCHAR_CACHE */
251     if (src_path == NULL) {
252         goto exit;
253     }
254     if (!PyUnicode_Check(args[1])) {
255         _PyArg_BadArgument("CreateJunction", "argument 2", "str", args[1]);
256         goto exit;
257     }
258     #if USE_UNICODE_WCHAR_CACHE
259     dst_path = _PyUnicode_AsUnicode(args[1]);
260     #else /* USE_UNICODE_WCHAR_CACHE */
261     dst_path = PyUnicode_AsWideCharString(args[1], NULL);
262     #endif /* USE_UNICODE_WCHAR_CACHE */
263     if (dst_path == NULL) {
264         goto exit;
265     }
266     return_value = _winapi_CreateJunction_impl(module, src_path, dst_path);
267 
268 exit:
269     /* Cleanup for src_path */
270     #if !USE_UNICODE_WCHAR_CACHE
271     PyMem_Free((void *)src_path);
272     #endif /* USE_UNICODE_WCHAR_CACHE */
273     /* Cleanup for dst_path */
274     #if !USE_UNICODE_WCHAR_CACHE
275     PyMem_Free((void *)dst_path);
276     #endif /* USE_UNICODE_WCHAR_CACHE */
277 
278     return return_value;
279 }
280 
281 PyDoc_STRVAR(_winapi_CreateNamedPipe__doc__,
282 "CreateNamedPipe($module, name, open_mode, pipe_mode, max_instances,\n"
283 "                out_buffer_size, in_buffer_size, default_timeout,\n"
284 "                security_attributes, /)\n"
285 "--\n"
286 "\n");
287 
288 #define _WINAPI_CREATENAMEDPIPE_METHODDEF    \
289     {"CreateNamedPipe", _PyCFunction_CAST(_winapi_CreateNamedPipe), METH_FASTCALL, _winapi_CreateNamedPipe__doc__},
290 
291 static HANDLE
292 _winapi_CreateNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD open_mode,
293                              DWORD pipe_mode, DWORD max_instances,
294                              DWORD out_buffer_size, DWORD in_buffer_size,
295                              DWORD default_timeout,
296                              LPSECURITY_ATTRIBUTES security_attributes);
297 
298 static PyObject *
_winapi_CreateNamedPipe(PyObject * module,PyObject * const * args,Py_ssize_t nargs)299 _winapi_CreateNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
300 {
301     PyObject *return_value = NULL;
302     LPCTSTR name;
303     DWORD open_mode;
304     DWORD pipe_mode;
305     DWORD max_instances;
306     DWORD out_buffer_size;
307     DWORD in_buffer_size;
308     DWORD default_timeout;
309     LPSECURITY_ATTRIBUTES security_attributes;
310     HANDLE _return_value;
311 
312     if (!_PyArg_ParseStack(args, nargs, "skkkkkk" F_POINTER ":CreateNamedPipe",
313         &name, &open_mode, &pipe_mode, &max_instances, &out_buffer_size, &in_buffer_size, &default_timeout, &security_attributes)) {
314         goto exit;
315     }
316     _return_value = _winapi_CreateNamedPipe_impl(module, name, open_mode, pipe_mode, max_instances, out_buffer_size, in_buffer_size, default_timeout, security_attributes);
317     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
318         goto exit;
319     }
320     if (_return_value == NULL) {
321         Py_RETURN_NONE;
322     }
323     return_value = HANDLE_TO_PYNUM(_return_value);
324 
325 exit:
326     return return_value;
327 }
328 
329 PyDoc_STRVAR(_winapi_CreatePipe__doc__,
330 "CreatePipe($module, pipe_attrs, size, /)\n"
331 "--\n"
332 "\n"
333 "Create an anonymous pipe.\n"
334 "\n"
335 "  pipe_attrs\n"
336 "    Ignored internally, can be None.\n"
337 "\n"
338 "Returns a 2-tuple of handles, to the read and write ends of the pipe.");
339 
340 #define _WINAPI_CREATEPIPE_METHODDEF    \
341     {"CreatePipe", _PyCFunction_CAST(_winapi_CreatePipe), METH_FASTCALL, _winapi_CreatePipe__doc__},
342 
343 static PyObject *
344 _winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, DWORD size);
345 
346 static PyObject *
_winapi_CreatePipe(PyObject * module,PyObject * const * args,Py_ssize_t nargs)347 _winapi_CreatePipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
348 {
349     PyObject *return_value = NULL;
350     PyObject *pipe_attrs;
351     DWORD size;
352 
353     if (!_PyArg_ParseStack(args, nargs, "Ok:CreatePipe",
354         &pipe_attrs, &size)) {
355         goto exit;
356     }
357     return_value = _winapi_CreatePipe_impl(module, pipe_attrs, size);
358 
359 exit:
360     return return_value;
361 }
362 
363 PyDoc_STRVAR(_winapi_CreateProcess__doc__,
364 "CreateProcess($module, application_name, command_line, proc_attrs,\n"
365 "              thread_attrs, inherit_handles, creation_flags,\n"
366 "              env_mapping, current_directory, startup_info, /)\n"
367 "--\n"
368 "\n"
369 "Create a new process and its primary thread.\n"
370 "\n"
371 "  command_line\n"
372 "    Can be str or None\n"
373 "  proc_attrs\n"
374 "    Ignored internally, can be None.\n"
375 "  thread_attrs\n"
376 "    Ignored internally, can be None.\n"
377 "\n"
378 "The return value is a tuple of the process handle, thread handle,\n"
379 "process ID, and thread ID.");
380 
381 #define _WINAPI_CREATEPROCESS_METHODDEF    \
382     {"CreateProcess", _PyCFunction_CAST(_winapi_CreateProcess), METH_FASTCALL, _winapi_CreateProcess__doc__},
383 
384 static PyObject *
385 _winapi_CreateProcess_impl(PyObject *module,
386                            const Py_UNICODE *application_name,
387                            PyObject *command_line, PyObject *proc_attrs,
388                            PyObject *thread_attrs, BOOL inherit_handles,
389                            DWORD creation_flags, PyObject *env_mapping,
390                            const Py_UNICODE *current_directory,
391                            PyObject *startup_info);
392 
393 static PyObject *
_winapi_CreateProcess(PyObject * module,PyObject * const * args,Py_ssize_t nargs)394 _winapi_CreateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
395 {
396     PyObject *return_value = NULL;
397     const Py_UNICODE *application_name = NULL;
398     PyObject *command_line;
399     PyObject *proc_attrs;
400     PyObject *thread_attrs;
401     BOOL inherit_handles;
402     DWORD creation_flags;
403     PyObject *env_mapping;
404     const Py_UNICODE *current_directory = NULL;
405     PyObject *startup_info;
406 
407     if (!_PyArg_ParseStack(args, nargs, "O&OOOikOO&O:CreateProcess",
408         _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)) {
409         goto exit;
410     }
411     return_value = _winapi_CreateProcess_impl(module, application_name, command_line, proc_attrs, thread_attrs, inherit_handles, creation_flags, env_mapping, current_directory, startup_info);
412 
413 exit:
414     /* Cleanup for application_name */
415     #if !USE_UNICODE_WCHAR_CACHE
416     PyMem_Free((void *)application_name);
417     #endif /* USE_UNICODE_WCHAR_CACHE */
418     /* Cleanup for current_directory */
419     #if !USE_UNICODE_WCHAR_CACHE
420     PyMem_Free((void *)current_directory);
421     #endif /* USE_UNICODE_WCHAR_CACHE */
422 
423     return return_value;
424 }
425 
426 PyDoc_STRVAR(_winapi_DuplicateHandle__doc__,
427 "DuplicateHandle($module, source_process_handle, source_handle,\n"
428 "                target_process_handle, desired_access, inherit_handle,\n"
429 "                options=0, /)\n"
430 "--\n"
431 "\n"
432 "Return a duplicate handle object.\n"
433 "\n"
434 "The duplicate handle refers to the same object as the original\n"
435 "handle. Therefore, any changes to the object are reflected\n"
436 "through both handles.");
437 
438 #define _WINAPI_DUPLICATEHANDLE_METHODDEF    \
439     {"DuplicateHandle", _PyCFunction_CAST(_winapi_DuplicateHandle), METH_FASTCALL, _winapi_DuplicateHandle__doc__},
440 
441 static HANDLE
442 _winapi_DuplicateHandle_impl(PyObject *module, HANDLE source_process_handle,
443                              HANDLE source_handle,
444                              HANDLE target_process_handle,
445                              DWORD desired_access, BOOL inherit_handle,
446                              DWORD options);
447 
448 static PyObject *
_winapi_DuplicateHandle(PyObject * module,PyObject * const * args,Py_ssize_t nargs)449 _winapi_DuplicateHandle(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
450 {
451     PyObject *return_value = NULL;
452     HANDLE source_process_handle;
453     HANDLE source_handle;
454     HANDLE target_process_handle;
455     DWORD desired_access;
456     BOOL inherit_handle;
457     DWORD options = 0;
458     HANDLE _return_value;
459 
460     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_HANDLE "" F_HANDLE "ki|k:DuplicateHandle",
461         &source_process_handle, &source_handle, &target_process_handle, &desired_access, &inherit_handle, &options)) {
462         goto exit;
463     }
464     _return_value = _winapi_DuplicateHandle_impl(module, source_process_handle, source_handle, target_process_handle, desired_access, inherit_handle, options);
465     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
466         goto exit;
467     }
468     if (_return_value == NULL) {
469         Py_RETURN_NONE;
470     }
471     return_value = HANDLE_TO_PYNUM(_return_value);
472 
473 exit:
474     return return_value;
475 }
476 
477 PyDoc_STRVAR(_winapi_ExitProcess__doc__,
478 "ExitProcess($module, ExitCode, /)\n"
479 "--\n"
480 "\n");
481 
482 #define _WINAPI_EXITPROCESS_METHODDEF    \
483     {"ExitProcess", (PyCFunction)_winapi_ExitProcess, METH_O, _winapi_ExitProcess__doc__},
484 
485 static PyObject *
486 _winapi_ExitProcess_impl(PyObject *module, UINT ExitCode);
487 
488 static PyObject *
_winapi_ExitProcess(PyObject * module,PyObject * arg)489 _winapi_ExitProcess(PyObject *module, PyObject *arg)
490 {
491     PyObject *return_value = NULL;
492     UINT ExitCode;
493 
494     if (!PyArg_Parse(arg, "I:ExitProcess", &ExitCode)) {
495         goto exit;
496     }
497     return_value = _winapi_ExitProcess_impl(module, ExitCode);
498 
499 exit:
500     return return_value;
501 }
502 
503 PyDoc_STRVAR(_winapi_GetCurrentProcess__doc__,
504 "GetCurrentProcess($module, /)\n"
505 "--\n"
506 "\n"
507 "Return a handle object for the current process.");
508 
509 #define _WINAPI_GETCURRENTPROCESS_METHODDEF    \
510     {"GetCurrentProcess", (PyCFunction)_winapi_GetCurrentProcess, METH_NOARGS, _winapi_GetCurrentProcess__doc__},
511 
512 static HANDLE
513 _winapi_GetCurrentProcess_impl(PyObject *module);
514 
515 static PyObject *
_winapi_GetCurrentProcess(PyObject * module,PyObject * Py_UNUSED (ignored))516 _winapi_GetCurrentProcess(PyObject *module, PyObject *Py_UNUSED(ignored))
517 {
518     PyObject *return_value = NULL;
519     HANDLE _return_value;
520 
521     _return_value = _winapi_GetCurrentProcess_impl(module);
522     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
523         goto exit;
524     }
525     if (_return_value == NULL) {
526         Py_RETURN_NONE;
527     }
528     return_value = HANDLE_TO_PYNUM(_return_value);
529 
530 exit:
531     return return_value;
532 }
533 
534 PyDoc_STRVAR(_winapi_GetExitCodeProcess__doc__,
535 "GetExitCodeProcess($module, process, /)\n"
536 "--\n"
537 "\n"
538 "Return the termination status of the specified process.");
539 
540 #define _WINAPI_GETEXITCODEPROCESS_METHODDEF    \
541     {"GetExitCodeProcess", (PyCFunction)_winapi_GetExitCodeProcess, METH_O, _winapi_GetExitCodeProcess__doc__},
542 
543 static DWORD
544 _winapi_GetExitCodeProcess_impl(PyObject *module, HANDLE process);
545 
546 static PyObject *
_winapi_GetExitCodeProcess(PyObject * module,PyObject * arg)547 _winapi_GetExitCodeProcess(PyObject *module, PyObject *arg)
548 {
549     PyObject *return_value = NULL;
550     HANDLE process;
551     DWORD _return_value;
552 
553     if (!PyArg_Parse(arg, "" F_HANDLE ":GetExitCodeProcess", &process)) {
554         goto exit;
555     }
556     _return_value = _winapi_GetExitCodeProcess_impl(module, process);
557     if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
558         goto exit;
559     }
560     return_value = Py_BuildValue("k", _return_value);
561 
562 exit:
563     return return_value;
564 }
565 
566 PyDoc_STRVAR(_winapi_GetLastError__doc__,
567 "GetLastError($module, /)\n"
568 "--\n"
569 "\n");
570 
571 #define _WINAPI_GETLASTERROR_METHODDEF    \
572     {"GetLastError", (PyCFunction)_winapi_GetLastError, METH_NOARGS, _winapi_GetLastError__doc__},
573 
574 static DWORD
575 _winapi_GetLastError_impl(PyObject *module);
576 
577 static PyObject *
_winapi_GetLastError(PyObject * module,PyObject * Py_UNUSED (ignored))578 _winapi_GetLastError(PyObject *module, PyObject *Py_UNUSED(ignored))
579 {
580     PyObject *return_value = NULL;
581     DWORD _return_value;
582 
583     _return_value = _winapi_GetLastError_impl(module);
584     if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
585         goto exit;
586     }
587     return_value = Py_BuildValue("k", _return_value);
588 
589 exit:
590     return return_value;
591 }
592 
593 PyDoc_STRVAR(_winapi_GetModuleFileName__doc__,
594 "GetModuleFileName($module, module_handle, /)\n"
595 "--\n"
596 "\n"
597 "Return the fully-qualified path for the file that contains module.\n"
598 "\n"
599 "The module must have been loaded by the current process.\n"
600 "\n"
601 "The module parameter should be a handle to the loaded module\n"
602 "whose path is being requested. If this parameter is 0,\n"
603 "GetModuleFileName retrieves the path of the executable file\n"
604 "of the current process.");
605 
606 #define _WINAPI_GETMODULEFILENAME_METHODDEF    \
607     {"GetModuleFileName", (PyCFunction)_winapi_GetModuleFileName, METH_O, _winapi_GetModuleFileName__doc__},
608 
609 static PyObject *
610 _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle);
611 
612 static PyObject *
_winapi_GetModuleFileName(PyObject * module,PyObject * arg)613 _winapi_GetModuleFileName(PyObject *module, PyObject *arg)
614 {
615     PyObject *return_value = NULL;
616     HMODULE module_handle;
617 
618     if (!PyArg_Parse(arg, "" F_HANDLE ":GetModuleFileName", &module_handle)) {
619         goto exit;
620     }
621     return_value = _winapi_GetModuleFileName_impl(module, module_handle);
622 
623 exit:
624     return return_value;
625 }
626 
627 PyDoc_STRVAR(_winapi_GetStdHandle__doc__,
628 "GetStdHandle($module, std_handle, /)\n"
629 "--\n"
630 "\n"
631 "Return a handle to the specified standard device.\n"
632 "\n"
633 "  std_handle\n"
634 "    One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE.\n"
635 "\n"
636 "The integer associated with the handle object is returned.");
637 
638 #define _WINAPI_GETSTDHANDLE_METHODDEF    \
639     {"GetStdHandle", (PyCFunction)_winapi_GetStdHandle, METH_O, _winapi_GetStdHandle__doc__},
640 
641 static HANDLE
642 _winapi_GetStdHandle_impl(PyObject *module, DWORD std_handle);
643 
644 static PyObject *
_winapi_GetStdHandle(PyObject * module,PyObject * arg)645 _winapi_GetStdHandle(PyObject *module, PyObject *arg)
646 {
647     PyObject *return_value = NULL;
648     DWORD std_handle;
649     HANDLE _return_value;
650 
651     if (!PyArg_Parse(arg, "k:GetStdHandle", &std_handle)) {
652         goto exit;
653     }
654     _return_value = _winapi_GetStdHandle_impl(module, std_handle);
655     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
656         goto exit;
657     }
658     if (_return_value == NULL) {
659         Py_RETURN_NONE;
660     }
661     return_value = HANDLE_TO_PYNUM(_return_value);
662 
663 exit:
664     return return_value;
665 }
666 
667 PyDoc_STRVAR(_winapi_GetVersion__doc__,
668 "GetVersion($module, /)\n"
669 "--\n"
670 "\n"
671 "Return the version number of the current operating system.");
672 
673 #define _WINAPI_GETVERSION_METHODDEF    \
674     {"GetVersion", (PyCFunction)_winapi_GetVersion, METH_NOARGS, _winapi_GetVersion__doc__},
675 
676 static long
677 _winapi_GetVersion_impl(PyObject *module);
678 
679 static PyObject *
_winapi_GetVersion(PyObject * module,PyObject * Py_UNUSED (ignored))680 _winapi_GetVersion(PyObject *module, PyObject *Py_UNUSED(ignored))
681 {
682     PyObject *return_value = NULL;
683     long _return_value;
684 
685     _return_value = _winapi_GetVersion_impl(module);
686     if ((_return_value == -1) && PyErr_Occurred()) {
687         goto exit;
688     }
689     return_value = PyLong_FromLong(_return_value);
690 
691 exit:
692     return return_value;
693 }
694 
695 PyDoc_STRVAR(_winapi_MapViewOfFile__doc__,
696 "MapViewOfFile($module, file_map, desired_access, file_offset_high,\n"
697 "              file_offset_low, number_bytes, /)\n"
698 "--\n"
699 "\n");
700 
701 #define _WINAPI_MAPVIEWOFFILE_METHODDEF    \
702     {"MapViewOfFile", _PyCFunction_CAST(_winapi_MapViewOfFile), METH_FASTCALL, _winapi_MapViewOfFile__doc__},
703 
704 static LPVOID
705 _winapi_MapViewOfFile_impl(PyObject *module, HANDLE file_map,
706                            DWORD desired_access, DWORD file_offset_high,
707                            DWORD file_offset_low, size_t number_bytes);
708 
709 static PyObject *
_winapi_MapViewOfFile(PyObject * module,PyObject * const * args,Py_ssize_t nargs)710 _winapi_MapViewOfFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
711 {
712     PyObject *return_value = NULL;
713     HANDLE file_map;
714     DWORD desired_access;
715     DWORD file_offset_high;
716     DWORD file_offset_low;
717     size_t number_bytes;
718     LPVOID _return_value;
719 
720     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "kkkO&:MapViewOfFile",
721         &file_map, &desired_access, &file_offset_high, &file_offset_low, _PyLong_Size_t_Converter, &number_bytes)) {
722         goto exit;
723     }
724     _return_value = _winapi_MapViewOfFile_impl(module, file_map, desired_access, file_offset_high, file_offset_low, number_bytes);
725     if ((_return_value == NULL) && PyErr_Occurred()) {
726         goto exit;
727     }
728     return_value = HANDLE_TO_PYNUM(_return_value);
729 
730 exit:
731     return return_value;
732 }
733 
734 PyDoc_STRVAR(_winapi_UnmapViewOfFile__doc__,
735 "UnmapViewOfFile($module, address, /)\n"
736 "--\n"
737 "\n");
738 
739 #define _WINAPI_UNMAPVIEWOFFILE_METHODDEF    \
740     {"UnmapViewOfFile", (PyCFunction)_winapi_UnmapViewOfFile, METH_O, _winapi_UnmapViewOfFile__doc__},
741 
742 static PyObject *
743 _winapi_UnmapViewOfFile_impl(PyObject *module, LPCVOID address);
744 
745 static PyObject *
_winapi_UnmapViewOfFile(PyObject * module,PyObject * arg)746 _winapi_UnmapViewOfFile(PyObject *module, PyObject *arg)
747 {
748     PyObject *return_value = NULL;
749     LPCVOID address;
750 
751     if (!PyArg_Parse(arg, "" F_POINTER ":UnmapViewOfFile", &address)) {
752         goto exit;
753     }
754     return_value = _winapi_UnmapViewOfFile_impl(module, address);
755 
756 exit:
757     return return_value;
758 }
759 
760 PyDoc_STRVAR(_winapi_OpenFileMapping__doc__,
761 "OpenFileMapping($module, desired_access, inherit_handle, name, /)\n"
762 "--\n"
763 "\n");
764 
765 #define _WINAPI_OPENFILEMAPPING_METHODDEF    \
766     {"OpenFileMapping", _PyCFunction_CAST(_winapi_OpenFileMapping), METH_FASTCALL, _winapi_OpenFileMapping__doc__},
767 
768 static HANDLE
769 _winapi_OpenFileMapping_impl(PyObject *module, DWORD desired_access,
770                              BOOL inherit_handle, LPCWSTR name);
771 
772 static PyObject *
_winapi_OpenFileMapping(PyObject * module,PyObject * const * args,Py_ssize_t nargs)773 _winapi_OpenFileMapping(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
774 {
775     PyObject *return_value = NULL;
776     DWORD desired_access;
777     BOOL inherit_handle;
778     LPCWSTR name = NULL;
779     HANDLE _return_value;
780 
781     if (!_PyArg_ParseStack(args, nargs, "kiO&:OpenFileMapping",
782         &desired_access, &inherit_handle, _PyUnicode_WideCharString_Converter, &name)) {
783         goto exit;
784     }
785     _return_value = _winapi_OpenFileMapping_impl(module, desired_access, inherit_handle, name);
786     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
787         goto exit;
788     }
789     if (_return_value == NULL) {
790         Py_RETURN_NONE;
791     }
792     return_value = HANDLE_TO_PYNUM(_return_value);
793 
794 exit:
795     /* Cleanup for name */
796     #if !USE_UNICODE_WCHAR_CACHE
797     PyMem_Free((void *)name);
798     #endif /* USE_UNICODE_WCHAR_CACHE */
799 
800     return return_value;
801 }
802 
803 PyDoc_STRVAR(_winapi_OpenProcess__doc__,
804 "OpenProcess($module, desired_access, inherit_handle, process_id, /)\n"
805 "--\n"
806 "\n");
807 
808 #define _WINAPI_OPENPROCESS_METHODDEF    \
809     {"OpenProcess", _PyCFunction_CAST(_winapi_OpenProcess), METH_FASTCALL, _winapi_OpenProcess__doc__},
810 
811 static HANDLE
812 _winapi_OpenProcess_impl(PyObject *module, DWORD desired_access,
813                          BOOL inherit_handle, DWORD process_id);
814 
815 static PyObject *
_winapi_OpenProcess(PyObject * module,PyObject * const * args,Py_ssize_t nargs)816 _winapi_OpenProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
817 {
818     PyObject *return_value = NULL;
819     DWORD desired_access;
820     BOOL inherit_handle;
821     DWORD process_id;
822     HANDLE _return_value;
823 
824     if (!_PyArg_ParseStack(args, nargs, "kik:OpenProcess",
825         &desired_access, &inherit_handle, &process_id)) {
826         goto exit;
827     }
828     _return_value = _winapi_OpenProcess_impl(module, desired_access, inherit_handle, process_id);
829     if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
830         goto exit;
831     }
832     if (_return_value == NULL) {
833         Py_RETURN_NONE;
834     }
835     return_value = HANDLE_TO_PYNUM(_return_value);
836 
837 exit:
838     return return_value;
839 }
840 
841 PyDoc_STRVAR(_winapi_PeekNamedPipe__doc__,
842 "PeekNamedPipe($module, handle, size=0, /)\n"
843 "--\n"
844 "\n");
845 
846 #define _WINAPI_PEEKNAMEDPIPE_METHODDEF    \
847     {"PeekNamedPipe", _PyCFunction_CAST(_winapi_PeekNamedPipe), METH_FASTCALL, _winapi_PeekNamedPipe__doc__},
848 
849 static PyObject *
850 _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size);
851 
852 static PyObject *
_winapi_PeekNamedPipe(PyObject * module,PyObject * const * args,Py_ssize_t nargs)853 _winapi_PeekNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
854 {
855     PyObject *return_value = NULL;
856     HANDLE handle;
857     int size = 0;
858 
859     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "|i:PeekNamedPipe",
860         &handle, &size)) {
861         goto exit;
862     }
863     return_value = _winapi_PeekNamedPipe_impl(module, handle, size);
864 
865 exit:
866     return return_value;
867 }
868 
869 PyDoc_STRVAR(_winapi_LCMapStringEx__doc__,
870 "LCMapStringEx($module, /, locale, flags, src)\n"
871 "--\n"
872 "\n");
873 
874 #define _WINAPI_LCMAPSTRINGEX_METHODDEF    \
875     {"LCMapStringEx", _PyCFunction_CAST(_winapi_LCMapStringEx), METH_FASTCALL|METH_KEYWORDS, _winapi_LCMapStringEx__doc__},
876 
877 static PyObject *
878 _winapi_LCMapStringEx_impl(PyObject *module, PyObject *locale, DWORD flags,
879                            PyObject *src);
880 
881 static PyObject *
_winapi_LCMapStringEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)882 _winapi_LCMapStringEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
883 {
884     PyObject *return_value = NULL;
885     static const char * const _keywords[] = {"locale", "flags", "src", NULL};
886     static _PyArg_Parser _parser = {"UkU:LCMapStringEx", _keywords, 0};
887     PyObject *locale;
888     DWORD flags;
889     PyObject *src;
890 
891     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
892         &locale, &flags, &src)) {
893         goto exit;
894     }
895     return_value = _winapi_LCMapStringEx_impl(module, locale, flags, src);
896 
897 exit:
898     return return_value;
899 }
900 
901 PyDoc_STRVAR(_winapi_ReadFile__doc__,
902 "ReadFile($module, /, handle, size, overlapped=False)\n"
903 "--\n"
904 "\n");
905 
906 #define _WINAPI_READFILE_METHODDEF    \
907     {"ReadFile", _PyCFunction_CAST(_winapi_ReadFile), METH_FASTCALL|METH_KEYWORDS, _winapi_ReadFile__doc__},
908 
909 static PyObject *
910 _winapi_ReadFile_impl(PyObject *module, HANDLE handle, DWORD size,
911                       int use_overlapped);
912 
913 static PyObject *
_winapi_ReadFile(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)914 _winapi_ReadFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
915 {
916     PyObject *return_value = NULL;
917     static const char * const _keywords[] = {"handle", "size", "overlapped", NULL};
918     static _PyArg_Parser _parser = {"" F_HANDLE "k|i:ReadFile", _keywords, 0};
919     HANDLE handle;
920     DWORD size;
921     int use_overlapped = 0;
922 
923     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
924         &handle, &size, &use_overlapped)) {
925         goto exit;
926     }
927     return_value = _winapi_ReadFile_impl(module, handle, size, use_overlapped);
928 
929 exit:
930     return return_value;
931 }
932 
933 PyDoc_STRVAR(_winapi_SetNamedPipeHandleState__doc__,
934 "SetNamedPipeHandleState($module, named_pipe, mode,\n"
935 "                        max_collection_count, collect_data_timeout, /)\n"
936 "--\n"
937 "\n");
938 
939 #define _WINAPI_SETNAMEDPIPEHANDLESTATE_METHODDEF    \
940     {"SetNamedPipeHandleState", _PyCFunction_CAST(_winapi_SetNamedPipeHandleState), METH_FASTCALL, _winapi_SetNamedPipeHandleState__doc__},
941 
942 static PyObject *
943 _winapi_SetNamedPipeHandleState_impl(PyObject *module, HANDLE named_pipe,
944                                      PyObject *mode,
945                                      PyObject *max_collection_count,
946                                      PyObject *collect_data_timeout);
947 
948 static PyObject *
_winapi_SetNamedPipeHandleState(PyObject * module,PyObject * const * args,Py_ssize_t nargs)949 _winapi_SetNamedPipeHandleState(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
950 {
951     PyObject *return_value = NULL;
952     HANDLE named_pipe;
953     PyObject *mode;
954     PyObject *max_collection_count;
955     PyObject *collect_data_timeout;
956 
957     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "OOO:SetNamedPipeHandleState",
958         &named_pipe, &mode, &max_collection_count, &collect_data_timeout)) {
959         goto exit;
960     }
961     return_value = _winapi_SetNamedPipeHandleState_impl(module, named_pipe, mode, max_collection_count, collect_data_timeout);
962 
963 exit:
964     return return_value;
965 }
966 
967 PyDoc_STRVAR(_winapi_TerminateProcess__doc__,
968 "TerminateProcess($module, handle, exit_code, /)\n"
969 "--\n"
970 "\n"
971 "Terminate the specified process and all of its threads.");
972 
973 #define _WINAPI_TERMINATEPROCESS_METHODDEF    \
974     {"TerminateProcess", _PyCFunction_CAST(_winapi_TerminateProcess), METH_FASTCALL, _winapi_TerminateProcess__doc__},
975 
976 static PyObject *
977 _winapi_TerminateProcess_impl(PyObject *module, HANDLE handle,
978                               UINT exit_code);
979 
980 static PyObject *
_winapi_TerminateProcess(PyObject * module,PyObject * const * args,Py_ssize_t nargs)981 _winapi_TerminateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
982 {
983     PyObject *return_value = NULL;
984     HANDLE handle;
985     UINT exit_code;
986 
987     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "I:TerminateProcess",
988         &handle, &exit_code)) {
989         goto exit;
990     }
991     return_value = _winapi_TerminateProcess_impl(module, handle, exit_code);
992 
993 exit:
994     return return_value;
995 }
996 
997 PyDoc_STRVAR(_winapi_VirtualQuerySize__doc__,
998 "VirtualQuerySize($module, address, /)\n"
999 "--\n"
1000 "\n");
1001 
1002 #define _WINAPI_VIRTUALQUERYSIZE_METHODDEF    \
1003     {"VirtualQuerySize", (PyCFunction)_winapi_VirtualQuerySize, METH_O, _winapi_VirtualQuerySize__doc__},
1004 
1005 static size_t
1006 _winapi_VirtualQuerySize_impl(PyObject *module, LPCVOID address);
1007 
1008 static PyObject *
_winapi_VirtualQuerySize(PyObject * module,PyObject * arg)1009 _winapi_VirtualQuerySize(PyObject *module, PyObject *arg)
1010 {
1011     PyObject *return_value = NULL;
1012     LPCVOID address;
1013     size_t _return_value;
1014 
1015     if (!PyArg_Parse(arg, "" F_POINTER ":VirtualQuerySize", &address)) {
1016         goto exit;
1017     }
1018     _return_value = _winapi_VirtualQuerySize_impl(module, address);
1019     if ((_return_value == (size_t)-1) && PyErr_Occurred()) {
1020         goto exit;
1021     }
1022     return_value = PyLong_FromSize_t(_return_value);
1023 
1024 exit:
1025     return return_value;
1026 }
1027 
1028 PyDoc_STRVAR(_winapi_WaitNamedPipe__doc__,
1029 "WaitNamedPipe($module, name, timeout, /)\n"
1030 "--\n"
1031 "\n");
1032 
1033 #define _WINAPI_WAITNAMEDPIPE_METHODDEF    \
1034     {"WaitNamedPipe", _PyCFunction_CAST(_winapi_WaitNamedPipe), METH_FASTCALL, _winapi_WaitNamedPipe__doc__},
1035 
1036 static PyObject *
1037 _winapi_WaitNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD timeout);
1038 
1039 static PyObject *
_winapi_WaitNamedPipe(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1040 _winapi_WaitNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1041 {
1042     PyObject *return_value = NULL;
1043     LPCTSTR name;
1044     DWORD timeout;
1045 
1046     if (!_PyArg_ParseStack(args, nargs, "sk:WaitNamedPipe",
1047         &name, &timeout)) {
1048         goto exit;
1049     }
1050     return_value = _winapi_WaitNamedPipe_impl(module, name, timeout);
1051 
1052 exit:
1053     return return_value;
1054 }
1055 
1056 PyDoc_STRVAR(_winapi_WaitForMultipleObjects__doc__,
1057 "WaitForMultipleObjects($module, handle_seq, wait_flag,\n"
1058 "                       milliseconds=_winapi.INFINITE, /)\n"
1059 "--\n"
1060 "\n");
1061 
1062 #define _WINAPI_WAITFORMULTIPLEOBJECTS_METHODDEF    \
1063     {"WaitForMultipleObjects", _PyCFunction_CAST(_winapi_WaitForMultipleObjects), METH_FASTCALL, _winapi_WaitForMultipleObjects__doc__},
1064 
1065 static PyObject *
1066 _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq,
1067                                     BOOL wait_flag, DWORD milliseconds);
1068 
1069 static PyObject *
_winapi_WaitForMultipleObjects(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1070 _winapi_WaitForMultipleObjects(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1071 {
1072     PyObject *return_value = NULL;
1073     PyObject *handle_seq;
1074     BOOL wait_flag;
1075     DWORD milliseconds = INFINITE;
1076 
1077     if (!_PyArg_ParseStack(args, nargs, "Oi|k:WaitForMultipleObjects",
1078         &handle_seq, &wait_flag, &milliseconds)) {
1079         goto exit;
1080     }
1081     return_value = _winapi_WaitForMultipleObjects_impl(module, handle_seq, wait_flag, milliseconds);
1082 
1083 exit:
1084     return return_value;
1085 }
1086 
1087 PyDoc_STRVAR(_winapi_WaitForSingleObject__doc__,
1088 "WaitForSingleObject($module, handle, milliseconds, /)\n"
1089 "--\n"
1090 "\n"
1091 "Wait for a single object.\n"
1092 "\n"
1093 "Wait until the specified object is in the signaled state or\n"
1094 "the time-out interval elapses. The timeout value is specified\n"
1095 "in milliseconds.");
1096 
1097 #define _WINAPI_WAITFORSINGLEOBJECT_METHODDEF    \
1098     {"WaitForSingleObject", _PyCFunction_CAST(_winapi_WaitForSingleObject), METH_FASTCALL, _winapi_WaitForSingleObject__doc__},
1099 
1100 static long
1101 _winapi_WaitForSingleObject_impl(PyObject *module, HANDLE handle,
1102                                  DWORD milliseconds);
1103 
1104 static PyObject *
_winapi_WaitForSingleObject(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1105 _winapi_WaitForSingleObject(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1106 {
1107     PyObject *return_value = NULL;
1108     HANDLE handle;
1109     DWORD milliseconds;
1110     long _return_value;
1111 
1112     if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "k:WaitForSingleObject",
1113         &handle, &milliseconds)) {
1114         goto exit;
1115     }
1116     _return_value = _winapi_WaitForSingleObject_impl(module, handle, milliseconds);
1117     if ((_return_value == -1) && PyErr_Occurred()) {
1118         goto exit;
1119     }
1120     return_value = PyLong_FromLong(_return_value);
1121 
1122 exit:
1123     return return_value;
1124 }
1125 
1126 PyDoc_STRVAR(_winapi_WriteFile__doc__,
1127 "WriteFile($module, /, handle, buffer, overlapped=False)\n"
1128 "--\n"
1129 "\n");
1130 
1131 #define _WINAPI_WRITEFILE_METHODDEF    \
1132     {"WriteFile", _PyCFunction_CAST(_winapi_WriteFile), METH_FASTCALL|METH_KEYWORDS, _winapi_WriteFile__doc__},
1133 
1134 static PyObject *
1135 _winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer,
1136                        int use_overlapped);
1137 
1138 static PyObject *
_winapi_WriteFile(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1139 _winapi_WriteFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1140 {
1141     PyObject *return_value = NULL;
1142     static const char * const _keywords[] = {"handle", "buffer", "overlapped", NULL};
1143     static _PyArg_Parser _parser = {"" F_HANDLE "O|i:WriteFile", _keywords, 0};
1144     HANDLE handle;
1145     PyObject *buffer;
1146     int use_overlapped = 0;
1147 
1148     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1149         &handle, &buffer, &use_overlapped)) {
1150         goto exit;
1151     }
1152     return_value = _winapi_WriteFile_impl(module, handle, buffer, use_overlapped);
1153 
1154 exit:
1155     return return_value;
1156 }
1157 
1158 PyDoc_STRVAR(_winapi_GetACP__doc__,
1159 "GetACP($module, /)\n"
1160 "--\n"
1161 "\n"
1162 "Get the current Windows ANSI code page identifier.");
1163 
1164 #define _WINAPI_GETACP_METHODDEF    \
1165     {"GetACP", (PyCFunction)_winapi_GetACP, METH_NOARGS, _winapi_GetACP__doc__},
1166 
1167 static PyObject *
1168 _winapi_GetACP_impl(PyObject *module);
1169 
1170 static PyObject *
_winapi_GetACP(PyObject * module,PyObject * Py_UNUSED (ignored))1171 _winapi_GetACP(PyObject *module, PyObject *Py_UNUSED(ignored))
1172 {
1173     return _winapi_GetACP_impl(module);
1174 }
1175 
1176 PyDoc_STRVAR(_winapi_GetFileType__doc__,
1177 "GetFileType($module, /, handle)\n"
1178 "--\n"
1179 "\n");
1180 
1181 #define _WINAPI_GETFILETYPE_METHODDEF    \
1182     {"GetFileType", _PyCFunction_CAST(_winapi_GetFileType), METH_FASTCALL|METH_KEYWORDS, _winapi_GetFileType__doc__},
1183 
1184 static DWORD
1185 _winapi_GetFileType_impl(PyObject *module, HANDLE handle);
1186 
1187 static PyObject *
_winapi_GetFileType(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1188 _winapi_GetFileType(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1189 {
1190     PyObject *return_value = NULL;
1191     static const char * const _keywords[] = {"handle", NULL};
1192     static _PyArg_Parser _parser = {"" F_HANDLE ":GetFileType", _keywords, 0};
1193     HANDLE handle;
1194     DWORD _return_value;
1195 
1196     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1197         &handle)) {
1198         goto exit;
1199     }
1200     _return_value = _winapi_GetFileType_impl(module, handle);
1201     if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
1202         goto exit;
1203     }
1204     return_value = Py_BuildValue("k", _return_value);
1205 
1206 exit:
1207     return return_value;
1208 }
1209 
1210 PyDoc_STRVAR(_winapi__mimetypes_read_windows_registry__doc__,
1211 "_mimetypes_read_windows_registry($module, /, on_type_read)\n"
1212 "--\n"
1213 "\n"
1214 "Optimized function for reading all known MIME types from the registry.\n"
1215 "\n"
1216 "*on_type_read* is a callable taking *type* and *ext* arguments, as for\n"
1217 "MimeTypes.add_type.");
1218 
1219 #define _WINAPI__MIMETYPES_READ_WINDOWS_REGISTRY_METHODDEF    \
1220     {"_mimetypes_read_windows_registry", _PyCFunction_CAST(_winapi__mimetypes_read_windows_registry), METH_FASTCALL|METH_KEYWORDS, _winapi__mimetypes_read_windows_registry__doc__},
1221 
1222 static PyObject *
1223 _winapi__mimetypes_read_windows_registry_impl(PyObject *module,
1224                                               PyObject *on_type_read);
1225 
1226 static PyObject *
_winapi__mimetypes_read_windows_registry(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1227 _winapi__mimetypes_read_windows_registry(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1228 {
1229     PyObject *return_value = NULL;
1230     static const char * const _keywords[] = {"on_type_read", NULL};
1231     static _PyArg_Parser _parser = {NULL, _keywords, "_mimetypes_read_windows_registry", 0};
1232     PyObject *argsbuf[1];
1233     PyObject *on_type_read;
1234 
1235     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1236     if (!args) {
1237         goto exit;
1238     }
1239     on_type_read = args[0];
1240     return_value = _winapi__mimetypes_read_windows_registry_impl(module, on_type_read);
1241 
1242 exit:
1243     return return_value;
1244 }
1245 /*[clinic end generated code: output=9c08a7371fcf5dd4 input=a9049054013a1b77]*/
1246