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
10
11 PyDoc_STRVAR(_winapi_Overlapped_GetOverlappedResult__doc__,
12 "GetOverlappedResult($self, wait, /)\n"
13 "--\n"
14 "\n");
15
16 #define _WINAPI_OVERLAPPED_GETOVERLAPPEDRESULT_METHODDEF \
17 {"GetOverlappedResult", (PyCFunction)_winapi_Overlapped_GetOverlappedResult, METH_O, _winapi_Overlapped_GetOverlappedResult__doc__},
18
19 static PyObject *
20 _winapi_Overlapped_GetOverlappedResult_impl(OverlappedObject *self, int wait);
21
22 static PyObject *
23 _winapi_Overlapped_GetOverlappedResult(OverlappedObject *self, PyObject *arg)
24 {
25 PyObject *return_value = NULL;
26 int wait;
27
28 wait = PyObject_IsTrue(arg);
29 if (wait < 0) {
30 goto exit;
31 }
32 return_value = _winapi_Overlapped_GetOverlappedResult_impl(self, wait);
33
34 exit:
35 return return_value;
36 }
37
38 PyDoc_STRVAR(_winapi_Overlapped_getbuffer__doc__,
39 "getbuffer($self, /)\n"
40 "--\n"
41 "\n");
42
43 #define _WINAPI_OVERLAPPED_GETBUFFER_METHODDEF \
44 {"getbuffer", (PyCFunction)_winapi_Overlapped_getbuffer, METH_NOARGS, _winapi_Overlapped_getbuffer__doc__},
45
46 static PyObject *
47 _winapi_Overlapped_getbuffer_impl(OverlappedObject *self);
48
49 static PyObject *
50 _winapi_Overlapped_getbuffer(OverlappedObject *self, PyObject *Py_UNUSED(ignored))
51 {
52 return _winapi_Overlapped_getbuffer_impl(self);
53 }
54
55 PyDoc_STRVAR(_winapi_Overlapped_cancel__doc__,
56 "cancel($self, /)\n"
57 "--\n"
58 "\n");
59
60 #define _WINAPI_OVERLAPPED_CANCEL_METHODDEF \
61 {"cancel", (PyCFunction)_winapi_Overlapped_cancel, METH_NOARGS, _winapi_Overlapped_cancel__doc__},
62
63 static PyObject *
64 _winapi_Overlapped_cancel_impl(OverlappedObject *self);
65
66 static PyObject *
67 _winapi_Overlapped_cancel(OverlappedObject *self, PyObject *Py_UNUSED(ignored))
68 {
69 return _winapi_Overlapped_cancel_impl(self);
70 }
71
72 PyDoc_STRVAR(_winapi_CloseHandle__doc__,
73 "CloseHandle($module, handle, /)\n"
74 "--\n"
75 "\n"
76 "Close handle.");
77
78 #define _WINAPI_CLOSEHANDLE_METHODDEF \
79 {"CloseHandle", (PyCFunction)_winapi_CloseHandle, METH_O, _winapi_CloseHandle__doc__},
80
81 static PyObject *
82 _winapi_CloseHandle_impl(PyObject *module, HANDLE handle);
83
84 static PyObject *
85 _winapi_CloseHandle(PyObject *module, PyObject *arg)
86 {
87 PyObject *return_value = NULL;
88 HANDLE handle;
89
90 if (!PyArg_Parse(arg, "" F_HANDLE ":CloseHandle", &handle)) {
91 goto exit;
92 }
93 return_value = _winapi_CloseHandle_impl(module, handle);
94
95 exit:
96 return return_value;
97 }
98
99 PyDoc_STRVAR(_winapi_ConnectNamedPipe__doc__,
100 "ConnectNamedPipe($module, /, handle, overlapped=False)\n"
101 "--\n"
102 "\n");
103
104 #define _WINAPI_CONNECTNAMEDPIPE_METHODDEF \
105 {"ConnectNamedPipe", _PyCFunction_CAST(_winapi_ConnectNamedPipe), METH_FASTCALL|METH_KEYWORDS, _winapi_ConnectNamedPipe__doc__},
106
107 static PyObject *
108 _winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle,
109 int use_overlapped);
110
111 static PyObject *
112 _winapi_ConnectNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
113 {
114 PyObject *return_value = NULL;
115 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
116
117 #define NUM_KEYWORDS 2
118 static struct {
119 PyGC_Head _this_is_not_used;
120 PyObject_VAR_HEAD
121 PyObject *ob_item[NUM_KEYWORDS];
122 } _kwtuple = {
123 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
124 .ob_item = { &_Py_ID(handle), &_Py_ID(overlapped), },
125 };
126 #undef NUM_KEYWORDS
127 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
128
129 #else // !Py_BUILD_CORE
130 # define KWTUPLE NULL
131 #endif // !Py_BUILD_CORE
132
133 static const char * const _keywords[] = {"handle", "overlapped", NULL};
134 static _PyArg_Parser _parser = {
135 .keywords = _keywords,
136 .format = "" F_HANDLE "|p:ConnectNamedPipe",
137 .kwtuple = KWTUPLE,
138 };
139 #undef KWTUPLE
140 HANDLE handle;
141 int use_overlapped = 0;
142
143 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
144 &handle, &use_overlapped)) {
145 goto exit;
146 }
147 return_value = _winapi_ConnectNamedPipe_impl(module, handle, use_overlapped);
148
149 exit:
150 return return_value;
151 }
152
153 PyDoc_STRVAR(_winapi_CreateFile__doc__,
154 "CreateFile($module, file_name, desired_access, share_mode,\n"
155 " security_attributes, creation_disposition,\n"
156 " flags_and_attributes, template_file, /)\n"
157 "--\n"
158 "\n");
159
160 #define _WINAPI_CREATEFILE_METHODDEF \
161 {"CreateFile", _PyCFunction_CAST(_winapi_CreateFile), METH_FASTCALL, _winapi_CreateFile__doc__},
162
163 static HANDLE
164 _winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name,
165 DWORD desired_access, DWORD share_mode,
166 LPSECURITY_ATTRIBUTES security_attributes,
167 DWORD creation_disposition,
168 DWORD flags_and_attributes, HANDLE template_file);
169
170 static PyObject *
171 _winapi_CreateFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
172 {
173 PyObject *return_value = NULL;
174 LPCTSTR file_name;
175 DWORD desired_access;
176 DWORD share_mode;
177 LPSECURITY_ATTRIBUTES security_attributes;
178 DWORD creation_disposition;
179 DWORD flags_and_attributes;
180 HANDLE template_file;
181 HANDLE _return_value;
182
183 if (!_PyArg_ParseStack(args, nargs, "skk" F_POINTER "kk" F_HANDLE ":CreateFile",
184 &file_name, &desired_access, &share_mode, &security_attributes, &creation_disposition, &flags_and_attributes, &template_file)) {
185 goto exit;
186 }
187 _return_value = _winapi_CreateFile_impl(module, file_name, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, template_file);
188 if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
189 goto exit;
190 }
191 if (_return_value == NULL) {
192 Py_RETURN_NONE;
193 }
194 return_value = HANDLE_TO_PYNUM(_return_value);
195
196 exit:
197 return return_value;
198 }
199
200 PyDoc_STRVAR(_winapi_CreateFileMapping__doc__,
201 "CreateFileMapping($module, file_handle, security_attributes, protect,\n"
202 " max_size_high, max_size_low, name, /)\n"
203 "--\n"
204 "\n");
205
206 #define _WINAPI_CREATEFILEMAPPING_METHODDEF \
207 {"CreateFileMapping", _PyCFunction_CAST(_winapi_CreateFileMapping), METH_FASTCALL, _winapi_CreateFileMapping__doc__},
208
209 static HANDLE
210 _winapi_CreateFileMapping_impl(PyObject *module, HANDLE file_handle,
211 LPSECURITY_ATTRIBUTES security_attributes,
212 DWORD protect, DWORD max_size_high,
213 DWORD max_size_low, LPCWSTR name);
214
215 static PyObject *
216 _winapi_CreateFileMapping(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
217 {
218 PyObject *return_value = NULL;
219 HANDLE file_handle;
220 LPSECURITY_ATTRIBUTES security_attributes;
221 DWORD protect;
222 DWORD max_size_high;
223 DWORD max_size_low;
224 LPCWSTR name = NULL;
225 HANDLE _return_value;
226
227 if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_POINTER "kkkO&:CreateFileMapping",
228 &file_handle, &security_attributes, &protect, &max_size_high, &max_size_low, _PyUnicode_WideCharString_Converter, &name)) {
229 goto exit;
230 }
231 _return_value = _winapi_CreateFileMapping_impl(module, file_handle, security_attributes, protect, max_size_high, max_size_low, name);
232 if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
233 goto exit;
234 }
235 if (_return_value == NULL) {
236 Py_RETURN_NONE;
237 }
238 return_value = HANDLE_TO_PYNUM(_return_value);
239
240 exit:
241 /* Cleanup for name */
242 PyMem_Free((void *)name);
243
244 return return_value;
245 }
246
247 PyDoc_STRVAR(_winapi_CreateJunction__doc__,
248 "CreateJunction($module, src_path, dst_path, /)\n"
249 "--\n"
250 "\n");
251
252 #define _WINAPI_CREATEJUNCTION_METHODDEF \
253 {"CreateJunction", _PyCFunction_CAST(_winapi_CreateJunction), METH_FASTCALL, _winapi_CreateJunction__doc__},
254
255 static PyObject *
256 _winapi_CreateJunction_impl(PyObject *module, LPCWSTR src_path,
257 LPCWSTR dst_path);
258
259 static PyObject *
260 _winapi_CreateJunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
261 {
262 PyObject *return_value = NULL;
263 LPCWSTR src_path = NULL;
264 LPCWSTR dst_path = NULL;
265
266 if (!_PyArg_CheckPositional("CreateJunction", nargs, 2, 2)) {
267 goto exit;
268 }
269 if (!PyUnicode_Check(args[0])) {
270 _PyArg_BadArgument("CreateJunction", "argument 1", "str", args[0]);
271 goto exit;
272 }
273 src_path = PyUnicode_AsWideCharString(args[0], NULL);
274 if (src_path == NULL) {
275 goto exit;
276 }
277 if (!PyUnicode_Check(args[1])) {
278 _PyArg_BadArgument("CreateJunction", "argument 2", "str", args[1]);
279 goto exit;
280 }
281 dst_path = PyUnicode_AsWideCharString(args[1], NULL);
282 if (dst_path == NULL) {
283 goto exit;
284 }
285 return_value = _winapi_CreateJunction_impl(module, src_path, dst_path);
286
287 exit:
288 /* Cleanup for src_path */
289 PyMem_Free((void *)src_path);
290 /* Cleanup for dst_path */
291 PyMem_Free((void *)dst_path);
292
293 return return_value;
294 }
295
296 PyDoc_STRVAR(_winapi_CreateNamedPipe__doc__,
297 "CreateNamedPipe($module, name, open_mode, pipe_mode, max_instances,\n"
298 " out_buffer_size, in_buffer_size, default_timeout,\n"
299 " security_attributes, /)\n"
300 "--\n"
301 "\n");
302
303 #define _WINAPI_CREATENAMEDPIPE_METHODDEF \
304 {"CreateNamedPipe", _PyCFunction_CAST(_winapi_CreateNamedPipe), METH_FASTCALL, _winapi_CreateNamedPipe__doc__},
305
306 static HANDLE
307 _winapi_CreateNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD open_mode,
308 DWORD pipe_mode, DWORD max_instances,
309 DWORD out_buffer_size, DWORD in_buffer_size,
310 DWORD default_timeout,
311 LPSECURITY_ATTRIBUTES security_attributes);
312
313 static PyObject *
314 _winapi_CreateNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
315 {
316 PyObject *return_value = NULL;
317 LPCTSTR name;
318 DWORD open_mode;
319 DWORD pipe_mode;
320 DWORD max_instances;
321 DWORD out_buffer_size;
322 DWORD in_buffer_size;
323 DWORD default_timeout;
324 LPSECURITY_ATTRIBUTES security_attributes;
325 HANDLE _return_value;
326
327 if (!_PyArg_ParseStack(args, nargs, "skkkkkk" F_POINTER ":CreateNamedPipe",
328 &name, &open_mode, &pipe_mode, &max_instances, &out_buffer_size, &in_buffer_size, &default_timeout, &security_attributes)) {
329 goto exit;
330 }
331 _return_value = _winapi_CreateNamedPipe_impl(module, name, open_mode, pipe_mode, max_instances, out_buffer_size, in_buffer_size, default_timeout, security_attributes);
332 if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
333 goto exit;
334 }
335 if (_return_value == NULL) {
336 Py_RETURN_NONE;
337 }
338 return_value = HANDLE_TO_PYNUM(_return_value);
339
340 exit:
341 return return_value;
342 }
343
344 PyDoc_STRVAR(_winapi_CreatePipe__doc__,
345 "CreatePipe($module, pipe_attrs, size, /)\n"
346 "--\n"
347 "\n"
348 "Create an anonymous pipe.\n"
349 "\n"
350 " pipe_attrs\n"
351 " Ignored internally, can be None.\n"
352 "\n"
353 "Returns a 2-tuple of handles, to the read and write ends of the pipe.");
354
355 #define _WINAPI_CREATEPIPE_METHODDEF \
356 {"CreatePipe", _PyCFunction_CAST(_winapi_CreatePipe), METH_FASTCALL, _winapi_CreatePipe__doc__},
357
358 static PyObject *
359 _winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, DWORD size);
360
361 static PyObject *
362 _winapi_CreatePipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
363 {
364 PyObject *return_value = NULL;
365 PyObject *pipe_attrs;
366 DWORD size;
367
368 if (!_PyArg_ParseStack(args, nargs, "Ok:CreatePipe",
369 &pipe_attrs, &size)) {
370 goto exit;
371 }
372 return_value = _winapi_CreatePipe_impl(module, pipe_attrs, size);
373
374 exit:
375 return return_value;
376 }
377
378 PyDoc_STRVAR(_winapi_CreateProcess__doc__,
379 "CreateProcess($module, application_name, command_line, proc_attrs,\n"
380 " thread_attrs, inherit_handles, creation_flags,\n"
381 " env_mapping, current_directory, startup_info, /)\n"
382 "--\n"
383 "\n"
384 "Create a new process and its primary thread.\n"
385 "\n"
386 " command_line\n"
387 " Can be str or None\n"
388 " proc_attrs\n"
389 " Ignored internally, can be None.\n"
390 " thread_attrs\n"
391 " Ignored internally, can be None.\n"
392 "\n"
393 "The return value is a tuple of the process handle, thread handle,\n"
394 "process ID, and thread ID.");
395
396 #define _WINAPI_CREATEPROCESS_METHODDEF \
397 {"CreateProcess", _PyCFunction_CAST(_winapi_CreateProcess), METH_FASTCALL, _winapi_CreateProcess__doc__},
398
399 static PyObject *
400 _winapi_CreateProcess_impl(PyObject *module,
401 const Py_UNICODE *application_name,
402 PyObject *command_line, PyObject *proc_attrs,
403 PyObject *thread_attrs, BOOL inherit_handles,
404 DWORD creation_flags, PyObject *env_mapping,
405 const Py_UNICODE *current_directory,
406 PyObject *startup_info);
407
408 static PyObject *
409 _winapi_CreateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
410 {
411 PyObject *return_value = NULL;
412 const Py_UNICODE *application_name = NULL;
413 PyObject *command_line;
414 PyObject *proc_attrs;
415 PyObject *thread_attrs;
416 BOOL inherit_handles;
417 DWORD creation_flags;
418 PyObject *env_mapping;
419 const Py_UNICODE *current_directory = NULL;
420 PyObject *startup_info;
421
422 if (!_PyArg_ParseStack(args, nargs, "O&OOOikOO&O:CreateProcess",
423 _PyUnicode_WideCharString_Opt_Converter, &application_name, &command_line, &proc_attrs, &thread_attrs, &inherit_handles, &creation_flags, &env_mapping, _PyUnicode_WideCharString_Opt_Converter, ¤t_directory, &startup_info)) {
424 goto exit;
425 }
426 return_value = _winapi_CreateProcess_impl(module, application_name, command_line, proc_attrs, thread_attrs, inherit_handles, creation_flags, env_mapping, current_directory, startup_info);
427
428 exit:
429 /* Cleanup for application_name */
430 PyMem_Free((void *)application_name);
431 /* Cleanup for current_directory */
432 PyMem_Free((void *)current_directory);
433
434 return return_value;
435 }
436
437 PyDoc_STRVAR(_winapi_DuplicateHandle__doc__,
438 "DuplicateHandle($module, source_process_handle, source_handle,\n"
439 " target_process_handle, desired_access, inherit_handle,\n"
440 " options=0, /)\n"
441 "--\n"
442 "\n"
443 "Return a duplicate handle object.\n"
444 "\n"
445 "The duplicate handle refers to the same object as the original\n"
446 "handle. Therefore, any changes to the object are reflected\n"
447 "through both handles.");
448
449 #define _WINAPI_DUPLICATEHANDLE_METHODDEF \
450 {"DuplicateHandle", _PyCFunction_CAST(_winapi_DuplicateHandle), METH_FASTCALL, _winapi_DuplicateHandle__doc__},
451
452 static HANDLE
453 _winapi_DuplicateHandle_impl(PyObject *module, HANDLE source_process_handle,
454 HANDLE source_handle,
455 HANDLE target_process_handle,
456 DWORD desired_access, BOOL inherit_handle,
457 DWORD options);
458
459 static PyObject *
460 _winapi_DuplicateHandle(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
461 {
462 PyObject *return_value = NULL;
463 HANDLE source_process_handle;
464 HANDLE source_handle;
465 HANDLE target_process_handle;
466 DWORD desired_access;
467 BOOL inherit_handle;
468 DWORD options = 0;
469 HANDLE _return_value;
470
471 if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_HANDLE "" F_HANDLE "ki|k:DuplicateHandle",
472 &source_process_handle, &source_handle, &target_process_handle, &desired_access, &inherit_handle, &options)) {
473 goto exit;
474 }
475 _return_value = _winapi_DuplicateHandle_impl(module, source_process_handle, source_handle, target_process_handle, desired_access, inherit_handle, options);
476 if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
477 goto exit;
478 }
479 if (_return_value == NULL) {
480 Py_RETURN_NONE;
481 }
482 return_value = HANDLE_TO_PYNUM(_return_value);
483
484 exit:
485 return return_value;
486 }
487
488 PyDoc_STRVAR(_winapi_ExitProcess__doc__,
489 "ExitProcess($module, ExitCode, /)\n"
490 "--\n"
491 "\n");
492
493 #define _WINAPI_EXITPROCESS_METHODDEF \
494 {"ExitProcess", (PyCFunction)_winapi_ExitProcess, METH_O, _winapi_ExitProcess__doc__},
495
496 static PyObject *
497 _winapi_ExitProcess_impl(PyObject *module, UINT ExitCode);
498
499 static PyObject *
500 _winapi_ExitProcess(PyObject *module, PyObject *arg)
501 {
502 PyObject *return_value = NULL;
503 UINT ExitCode;
504
505 if (!PyArg_Parse(arg, "I:ExitProcess", &ExitCode)) {
506 goto exit;
507 }
508 return_value = _winapi_ExitProcess_impl(module, ExitCode);
509
510 exit:
511 return return_value;
512 }
513
514 PyDoc_STRVAR(_winapi_GetCurrentProcess__doc__,
515 "GetCurrentProcess($module, /)\n"
516 "--\n"
517 "\n"
518 "Return a handle object for the current process.");
519
520 #define _WINAPI_GETCURRENTPROCESS_METHODDEF \
521 {"GetCurrentProcess", (PyCFunction)_winapi_GetCurrentProcess, METH_NOARGS, _winapi_GetCurrentProcess__doc__},
522
523 static HANDLE
524 _winapi_GetCurrentProcess_impl(PyObject *module);
525
526 static PyObject *
527 _winapi_GetCurrentProcess(PyObject *module, PyObject *Py_UNUSED(ignored))
528 {
529 PyObject *return_value = NULL;
530 HANDLE _return_value;
531
532 _return_value = _winapi_GetCurrentProcess_impl(module);
533 if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
534 goto exit;
535 }
536 if (_return_value == NULL) {
537 Py_RETURN_NONE;
538 }
539 return_value = HANDLE_TO_PYNUM(_return_value);
540
541 exit:
542 return return_value;
543 }
544
545 PyDoc_STRVAR(_winapi_GetExitCodeProcess__doc__,
546 "GetExitCodeProcess($module, process, /)\n"
547 "--\n"
548 "\n"
549 "Return the termination status of the specified process.");
550
551 #define _WINAPI_GETEXITCODEPROCESS_METHODDEF \
552 {"GetExitCodeProcess", (PyCFunction)_winapi_GetExitCodeProcess, METH_O, _winapi_GetExitCodeProcess__doc__},
553
554 static DWORD
555 _winapi_GetExitCodeProcess_impl(PyObject *module, HANDLE process);
556
557 static PyObject *
558 _winapi_GetExitCodeProcess(PyObject *module, PyObject *arg)
559 {
560 PyObject *return_value = NULL;
561 HANDLE process;
562 DWORD _return_value;
563
564 if (!PyArg_Parse(arg, "" F_HANDLE ":GetExitCodeProcess", &process)) {
565 goto exit;
566 }
567 _return_value = _winapi_GetExitCodeProcess_impl(module, process);
568 if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
569 goto exit;
570 }
571 return_value = Py_BuildValue("k", _return_value);
572
573 exit:
574 return return_value;
575 }
576
577 PyDoc_STRVAR(_winapi_GetLastError__doc__,
578 "GetLastError($module, /)\n"
579 "--\n"
580 "\n");
581
582 #define _WINAPI_GETLASTERROR_METHODDEF \
583 {"GetLastError", (PyCFunction)_winapi_GetLastError, METH_NOARGS, _winapi_GetLastError__doc__},
584
585 static DWORD
586 _winapi_GetLastError_impl(PyObject *module);
587
588 static PyObject *
589 _winapi_GetLastError(PyObject *module, PyObject *Py_UNUSED(ignored))
590 {
591 PyObject *return_value = NULL;
592 DWORD _return_value;
593
594 _return_value = _winapi_GetLastError_impl(module);
595 if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
596 goto exit;
597 }
598 return_value = Py_BuildValue("k", _return_value);
599
600 exit:
601 return return_value;
602 }
603
604 PyDoc_STRVAR(_winapi_GetModuleFileName__doc__,
605 "GetModuleFileName($module, module_handle, /)\n"
606 "--\n"
607 "\n"
608 "Return the fully-qualified path for the file that contains module.\n"
609 "\n"
610 "The module must have been loaded by the current process.\n"
611 "\n"
612 "The module parameter should be a handle to the loaded module\n"
613 "whose path is being requested. If this parameter is 0,\n"
614 "GetModuleFileName retrieves the path of the executable file\n"
615 "of the current process.");
616
617 #define _WINAPI_GETMODULEFILENAME_METHODDEF \
618 {"GetModuleFileName", (PyCFunction)_winapi_GetModuleFileName, METH_O, _winapi_GetModuleFileName__doc__},
619
620 static PyObject *
621 _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle);
622
623 static PyObject *
624 _winapi_GetModuleFileName(PyObject *module, PyObject *arg)
625 {
626 PyObject *return_value = NULL;
627 HMODULE module_handle;
628
629 if (!PyArg_Parse(arg, "" F_HANDLE ":GetModuleFileName", &module_handle)) {
630 goto exit;
631 }
632 return_value = _winapi_GetModuleFileName_impl(module, module_handle);
633
634 exit:
635 return return_value;
636 }
637
638 PyDoc_STRVAR(_winapi_GetStdHandle__doc__,
639 "GetStdHandle($module, std_handle, /)\n"
640 "--\n"
641 "\n"
642 "Return a handle to the specified standard device.\n"
643 "\n"
644 " std_handle\n"
645 " One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE.\n"
646 "\n"
647 "The integer associated with the handle object is returned.");
648
649 #define _WINAPI_GETSTDHANDLE_METHODDEF \
650 {"GetStdHandle", (PyCFunction)_winapi_GetStdHandle, METH_O, _winapi_GetStdHandle__doc__},
651
652 static HANDLE
653 _winapi_GetStdHandle_impl(PyObject *module, DWORD std_handle);
654
655 static PyObject *
656 _winapi_GetStdHandle(PyObject *module, PyObject *arg)
657 {
658 PyObject *return_value = NULL;
659 DWORD std_handle;
660 HANDLE _return_value;
661
662 if (!PyArg_Parse(arg, "k:GetStdHandle", &std_handle)) {
663 goto exit;
664 }
665 _return_value = _winapi_GetStdHandle_impl(module, std_handle);
666 if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
667 goto exit;
668 }
669 if (_return_value == NULL) {
670 Py_RETURN_NONE;
671 }
672 return_value = HANDLE_TO_PYNUM(_return_value);
673
674 exit:
675 return return_value;
676 }
677
678 PyDoc_STRVAR(_winapi_GetVersion__doc__,
679 "GetVersion($module, /)\n"
680 "--\n"
681 "\n"
682 "Return the version number of the current operating system.");
683
684 #define _WINAPI_GETVERSION_METHODDEF \
685 {"GetVersion", (PyCFunction)_winapi_GetVersion, METH_NOARGS, _winapi_GetVersion__doc__},
686
687 static long
688 _winapi_GetVersion_impl(PyObject *module);
689
690 static PyObject *
691 _winapi_GetVersion(PyObject *module, PyObject *Py_UNUSED(ignored))
692 {
693 PyObject *return_value = NULL;
694 long _return_value;
695
696 _return_value = _winapi_GetVersion_impl(module);
697 if ((_return_value == -1) && PyErr_Occurred()) {
698 goto exit;
699 }
700 return_value = PyLong_FromLong(_return_value);
701
702 exit:
703 return return_value;
704 }
705
706 PyDoc_STRVAR(_winapi_MapViewOfFile__doc__,
707 "MapViewOfFile($module, file_map, desired_access, file_offset_high,\n"
708 " file_offset_low, number_bytes, /)\n"
709 "--\n"
710 "\n");
711
712 #define _WINAPI_MAPVIEWOFFILE_METHODDEF \
713 {"MapViewOfFile", _PyCFunction_CAST(_winapi_MapViewOfFile), METH_FASTCALL, _winapi_MapViewOfFile__doc__},
714
715 static LPVOID
716 _winapi_MapViewOfFile_impl(PyObject *module, HANDLE file_map,
717 DWORD desired_access, DWORD file_offset_high,
718 DWORD file_offset_low, size_t number_bytes);
719
720 static PyObject *
721 _winapi_MapViewOfFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
722 {
723 PyObject *return_value = NULL;
724 HANDLE file_map;
725 DWORD desired_access;
726 DWORD file_offset_high;
727 DWORD file_offset_low;
728 size_t number_bytes;
729 LPVOID _return_value;
730
731 if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "kkkO&:MapViewOfFile",
732 &file_map, &desired_access, &file_offset_high, &file_offset_low, _PyLong_Size_t_Converter, &number_bytes)) {
733 goto exit;
734 }
735 _return_value = _winapi_MapViewOfFile_impl(module, file_map, desired_access, file_offset_high, file_offset_low, number_bytes);
736 if ((_return_value == NULL) && PyErr_Occurred()) {
737 goto exit;
738 }
739 return_value = HANDLE_TO_PYNUM(_return_value);
740
741 exit:
742 return return_value;
743 }
744
745 PyDoc_STRVAR(_winapi_UnmapViewOfFile__doc__,
746 "UnmapViewOfFile($module, address, /)\n"
747 "--\n"
748 "\n");
749
750 #define _WINAPI_UNMAPVIEWOFFILE_METHODDEF \
751 {"UnmapViewOfFile", (PyCFunction)_winapi_UnmapViewOfFile, METH_O, _winapi_UnmapViewOfFile__doc__},
752
753 static PyObject *
754 _winapi_UnmapViewOfFile_impl(PyObject *module, LPCVOID address);
755
756 static PyObject *
757 _winapi_UnmapViewOfFile(PyObject *module, PyObject *arg)
758 {
759 PyObject *return_value = NULL;
760 LPCVOID address;
761
762 if (!PyArg_Parse(arg, "" F_POINTER ":UnmapViewOfFile", &address)) {
763 goto exit;
764 }
765 return_value = _winapi_UnmapViewOfFile_impl(module, address);
766
767 exit:
768 return return_value;
769 }
770
771 PyDoc_STRVAR(_winapi_OpenFileMapping__doc__,
772 "OpenFileMapping($module, desired_access, inherit_handle, name, /)\n"
773 "--\n"
774 "\n");
775
776 #define _WINAPI_OPENFILEMAPPING_METHODDEF \
777 {"OpenFileMapping", _PyCFunction_CAST(_winapi_OpenFileMapping), METH_FASTCALL, _winapi_OpenFileMapping__doc__},
778
779 static HANDLE
780 _winapi_OpenFileMapping_impl(PyObject *module, DWORD desired_access,
781 BOOL inherit_handle, LPCWSTR name);
782
783 static PyObject *
784 _winapi_OpenFileMapping(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
785 {
786 PyObject *return_value = NULL;
787 DWORD desired_access;
788 BOOL inherit_handle;
789 LPCWSTR name = NULL;
790 HANDLE _return_value;
791
792 if (!_PyArg_ParseStack(args, nargs, "kiO&:OpenFileMapping",
793 &desired_access, &inherit_handle, _PyUnicode_WideCharString_Converter, &name)) {
794 goto exit;
795 }
796 _return_value = _winapi_OpenFileMapping_impl(module, desired_access, inherit_handle, name);
797 if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
798 goto exit;
799 }
800 if (_return_value == NULL) {
801 Py_RETURN_NONE;
802 }
803 return_value = HANDLE_TO_PYNUM(_return_value);
804
805 exit:
806 /* Cleanup for name */
807 PyMem_Free((void *)name);
808
809 return return_value;
810 }
811
812 PyDoc_STRVAR(_winapi_OpenProcess__doc__,
813 "OpenProcess($module, desired_access, inherit_handle, process_id, /)\n"
814 "--\n"
815 "\n");
816
817 #define _WINAPI_OPENPROCESS_METHODDEF \
818 {"OpenProcess", _PyCFunction_CAST(_winapi_OpenProcess), METH_FASTCALL, _winapi_OpenProcess__doc__},
819
820 static HANDLE
821 _winapi_OpenProcess_impl(PyObject *module, DWORD desired_access,
822 BOOL inherit_handle, DWORD process_id);
823
824 static PyObject *
825 _winapi_OpenProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
826 {
827 PyObject *return_value = NULL;
828 DWORD desired_access;
829 BOOL inherit_handle;
830 DWORD process_id;
831 HANDLE _return_value;
832
833 if (!_PyArg_ParseStack(args, nargs, "kik:OpenProcess",
834 &desired_access, &inherit_handle, &process_id)) {
835 goto exit;
836 }
837 _return_value = _winapi_OpenProcess_impl(module, desired_access, inherit_handle, process_id);
838 if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
839 goto exit;
840 }
841 if (_return_value == NULL) {
842 Py_RETURN_NONE;
843 }
844 return_value = HANDLE_TO_PYNUM(_return_value);
845
846 exit:
847 return return_value;
848 }
849
850 PyDoc_STRVAR(_winapi_PeekNamedPipe__doc__,
851 "PeekNamedPipe($module, handle, size=0, /)\n"
852 "--\n"
853 "\n");
854
855 #define _WINAPI_PEEKNAMEDPIPE_METHODDEF \
856 {"PeekNamedPipe", _PyCFunction_CAST(_winapi_PeekNamedPipe), METH_FASTCALL, _winapi_PeekNamedPipe__doc__},
857
858 static PyObject *
859 _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size);
860
861 static PyObject *
862 _winapi_PeekNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
863 {
864 PyObject *return_value = NULL;
865 HANDLE handle;
866 int size = 0;
867
868 if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "|i:PeekNamedPipe",
869 &handle, &size)) {
870 goto exit;
871 }
872 return_value = _winapi_PeekNamedPipe_impl(module, handle, size);
873
874 exit:
875 return return_value;
876 }
877
878 PyDoc_STRVAR(_winapi_LCMapStringEx__doc__,
879 "LCMapStringEx($module, /, locale, flags, src)\n"
880 "--\n"
881 "\n");
882
883 #define _WINAPI_LCMAPSTRINGEX_METHODDEF \
884 {"LCMapStringEx", _PyCFunction_CAST(_winapi_LCMapStringEx), METH_FASTCALL|METH_KEYWORDS, _winapi_LCMapStringEx__doc__},
885
886 static PyObject *
887 _winapi_LCMapStringEx_impl(PyObject *module, LPCWSTR locale, DWORD flags,
888 PyObject *src);
889
890 static PyObject *
891 _winapi_LCMapStringEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
892 {
893 PyObject *return_value = NULL;
894 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
895
896 #define NUM_KEYWORDS 3
897 static struct {
898 PyGC_Head _this_is_not_used;
899 PyObject_VAR_HEAD
900 PyObject *ob_item[NUM_KEYWORDS];
901 } _kwtuple = {
902 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
903 .ob_item = { &_Py_ID(locale), &_Py_ID(flags), &_Py_ID(src), },
904 };
905 #undef NUM_KEYWORDS
906 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
907
908 #else // !Py_BUILD_CORE
909 # define KWTUPLE NULL
910 #endif // !Py_BUILD_CORE
911
912 static const char * const _keywords[] = {"locale", "flags", "src", NULL};
913 static _PyArg_Parser _parser = {
914 .keywords = _keywords,
915 .format = "O&kU:LCMapStringEx",
916 .kwtuple = KWTUPLE,
917 };
918 #undef KWTUPLE
919 LPCWSTR locale = NULL;
920 DWORD flags;
921 PyObject *src;
922
923 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
924 _PyUnicode_WideCharString_Converter, &locale, &flags, &src)) {
925 goto exit;
926 }
927 return_value = _winapi_LCMapStringEx_impl(module, locale, flags, src);
928
929 exit:
930 /* Cleanup for locale */
931 PyMem_Free((void *)locale);
932
933 return return_value;
934 }
935
936 PyDoc_STRVAR(_winapi_ReadFile__doc__,
937 "ReadFile($module, /, handle, size, overlapped=False)\n"
938 "--\n"
939 "\n");
940
941 #define _WINAPI_READFILE_METHODDEF \
942 {"ReadFile", _PyCFunction_CAST(_winapi_ReadFile), METH_FASTCALL|METH_KEYWORDS, _winapi_ReadFile__doc__},
943
944 static PyObject *
945 _winapi_ReadFile_impl(PyObject *module, HANDLE handle, DWORD size,
946 int use_overlapped);
947
948 static PyObject *
949 _winapi_ReadFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
950 {
951 PyObject *return_value = NULL;
952 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
953
954 #define NUM_KEYWORDS 3
955 static struct {
956 PyGC_Head _this_is_not_used;
957 PyObject_VAR_HEAD
958 PyObject *ob_item[NUM_KEYWORDS];
959 } _kwtuple = {
960 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
961 .ob_item = { &_Py_ID(handle), &_Py_ID(size), &_Py_ID(overlapped), },
962 };
963 #undef NUM_KEYWORDS
964 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
965
966 #else // !Py_BUILD_CORE
967 # define KWTUPLE NULL
968 #endif // !Py_BUILD_CORE
969
970 static const char * const _keywords[] = {"handle", "size", "overlapped", NULL};
971 static _PyArg_Parser _parser = {
972 .keywords = _keywords,
973 .format = "" F_HANDLE "k|p:ReadFile",
974 .kwtuple = KWTUPLE,
975 };
976 #undef KWTUPLE
977 HANDLE handle;
978 DWORD size;
979 int use_overlapped = 0;
980
981 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
982 &handle, &size, &use_overlapped)) {
983 goto exit;
984 }
985 return_value = _winapi_ReadFile_impl(module, handle, size, use_overlapped);
986
987 exit:
988 return return_value;
989 }
990
991 PyDoc_STRVAR(_winapi_SetNamedPipeHandleState__doc__,
992 "SetNamedPipeHandleState($module, named_pipe, mode,\n"
993 " max_collection_count, collect_data_timeout, /)\n"
994 "--\n"
995 "\n");
996
997 #define _WINAPI_SETNAMEDPIPEHANDLESTATE_METHODDEF \
998 {"SetNamedPipeHandleState", _PyCFunction_CAST(_winapi_SetNamedPipeHandleState), METH_FASTCALL, _winapi_SetNamedPipeHandleState__doc__},
999
1000 static PyObject *
1001 _winapi_SetNamedPipeHandleState_impl(PyObject *module, HANDLE named_pipe,
1002 PyObject *mode,
1003 PyObject *max_collection_count,
1004 PyObject *collect_data_timeout);
1005
1006 static PyObject *
1007 _winapi_SetNamedPipeHandleState(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1008 {
1009 PyObject *return_value = NULL;
1010 HANDLE named_pipe;
1011 PyObject *mode;
1012 PyObject *max_collection_count;
1013 PyObject *collect_data_timeout;
1014
1015 if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "OOO:SetNamedPipeHandleState",
1016 &named_pipe, &mode, &max_collection_count, &collect_data_timeout)) {
1017 goto exit;
1018 }
1019 return_value = _winapi_SetNamedPipeHandleState_impl(module, named_pipe, mode, max_collection_count, collect_data_timeout);
1020
1021 exit:
1022 return return_value;
1023 }
1024
1025 PyDoc_STRVAR(_winapi_TerminateProcess__doc__,
1026 "TerminateProcess($module, handle, exit_code, /)\n"
1027 "--\n"
1028 "\n"
1029 "Terminate the specified process and all of its threads.");
1030
1031 #define _WINAPI_TERMINATEPROCESS_METHODDEF \
1032 {"TerminateProcess", _PyCFunction_CAST(_winapi_TerminateProcess), METH_FASTCALL, _winapi_TerminateProcess__doc__},
1033
1034 static PyObject *
1035 _winapi_TerminateProcess_impl(PyObject *module, HANDLE handle,
1036 UINT exit_code);
1037
1038 static PyObject *
1039 _winapi_TerminateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1040 {
1041 PyObject *return_value = NULL;
1042 HANDLE handle;
1043 UINT exit_code;
1044
1045 if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "I:TerminateProcess",
1046 &handle, &exit_code)) {
1047 goto exit;
1048 }
1049 return_value = _winapi_TerminateProcess_impl(module, handle, exit_code);
1050
1051 exit:
1052 return return_value;
1053 }
1054
1055 PyDoc_STRVAR(_winapi_VirtualQuerySize__doc__,
1056 "VirtualQuerySize($module, address, /)\n"
1057 "--\n"
1058 "\n");
1059
1060 #define _WINAPI_VIRTUALQUERYSIZE_METHODDEF \
1061 {"VirtualQuerySize", (PyCFunction)_winapi_VirtualQuerySize, METH_O, _winapi_VirtualQuerySize__doc__},
1062
1063 static size_t
1064 _winapi_VirtualQuerySize_impl(PyObject *module, LPCVOID address);
1065
1066 static PyObject *
1067 _winapi_VirtualQuerySize(PyObject *module, PyObject *arg)
1068 {
1069 PyObject *return_value = NULL;
1070 LPCVOID address;
1071 size_t _return_value;
1072
1073 if (!PyArg_Parse(arg, "" F_POINTER ":VirtualQuerySize", &address)) {
1074 goto exit;
1075 }
1076 _return_value = _winapi_VirtualQuerySize_impl(module, address);
1077 if ((_return_value == (size_t)-1) && PyErr_Occurred()) {
1078 goto exit;
1079 }
1080 return_value = PyLong_FromSize_t(_return_value);
1081
1082 exit:
1083 return return_value;
1084 }
1085
1086 PyDoc_STRVAR(_winapi_WaitNamedPipe__doc__,
1087 "WaitNamedPipe($module, name, timeout, /)\n"
1088 "--\n"
1089 "\n");
1090
1091 #define _WINAPI_WAITNAMEDPIPE_METHODDEF \
1092 {"WaitNamedPipe", _PyCFunction_CAST(_winapi_WaitNamedPipe), METH_FASTCALL, _winapi_WaitNamedPipe__doc__},
1093
1094 static PyObject *
1095 _winapi_WaitNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD timeout);
1096
1097 static PyObject *
1098 _winapi_WaitNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1099 {
1100 PyObject *return_value = NULL;
1101 LPCTSTR name;
1102 DWORD timeout;
1103
1104 if (!_PyArg_ParseStack(args, nargs, "sk:WaitNamedPipe",
1105 &name, &timeout)) {
1106 goto exit;
1107 }
1108 return_value = _winapi_WaitNamedPipe_impl(module, name, timeout);
1109
1110 exit:
1111 return return_value;
1112 }
1113
1114 PyDoc_STRVAR(_winapi_WaitForMultipleObjects__doc__,
1115 "WaitForMultipleObjects($module, handle_seq, wait_flag,\n"
1116 " milliseconds=_winapi.INFINITE, /)\n"
1117 "--\n"
1118 "\n");
1119
1120 #define _WINAPI_WAITFORMULTIPLEOBJECTS_METHODDEF \
1121 {"WaitForMultipleObjects", _PyCFunction_CAST(_winapi_WaitForMultipleObjects), METH_FASTCALL, _winapi_WaitForMultipleObjects__doc__},
1122
1123 static PyObject *
1124 _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq,
1125 BOOL wait_flag, DWORD milliseconds);
1126
1127 static PyObject *
1128 _winapi_WaitForMultipleObjects(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1129 {
1130 PyObject *return_value = NULL;
1131 PyObject *handle_seq;
1132 BOOL wait_flag;
1133 DWORD milliseconds = INFINITE;
1134
1135 if (!_PyArg_ParseStack(args, nargs, "Oi|k:WaitForMultipleObjects",
1136 &handle_seq, &wait_flag, &milliseconds)) {
1137 goto exit;
1138 }
1139 return_value = _winapi_WaitForMultipleObjects_impl(module, handle_seq, wait_flag, milliseconds);
1140
1141 exit:
1142 return return_value;
1143 }
1144
1145 PyDoc_STRVAR(_winapi_WaitForSingleObject__doc__,
1146 "WaitForSingleObject($module, handle, milliseconds, /)\n"
1147 "--\n"
1148 "\n"
1149 "Wait for a single object.\n"
1150 "\n"
1151 "Wait until the specified object is in the signaled state or\n"
1152 "the time-out interval elapses. The timeout value is specified\n"
1153 "in milliseconds.");
1154
1155 #define _WINAPI_WAITFORSINGLEOBJECT_METHODDEF \
1156 {"WaitForSingleObject", _PyCFunction_CAST(_winapi_WaitForSingleObject), METH_FASTCALL, _winapi_WaitForSingleObject__doc__},
1157
1158 static long
1159 _winapi_WaitForSingleObject_impl(PyObject *module, HANDLE handle,
1160 DWORD milliseconds);
1161
1162 static PyObject *
1163 _winapi_WaitForSingleObject(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1164 {
1165 PyObject *return_value = NULL;
1166 HANDLE handle;
1167 DWORD milliseconds;
1168 long _return_value;
1169
1170 if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "k:WaitForSingleObject",
1171 &handle, &milliseconds)) {
1172 goto exit;
1173 }
1174 _return_value = _winapi_WaitForSingleObject_impl(module, handle, milliseconds);
1175 if ((_return_value == -1) && PyErr_Occurred()) {
1176 goto exit;
1177 }
1178 return_value = PyLong_FromLong(_return_value);
1179
1180 exit:
1181 return return_value;
1182 }
1183
1184 PyDoc_STRVAR(_winapi_WriteFile__doc__,
1185 "WriteFile($module, /, handle, buffer, overlapped=False)\n"
1186 "--\n"
1187 "\n");
1188
1189 #define _WINAPI_WRITEFILE_METHODDEF \
1190 {"WriteFile", _PyCFunction_CAST(_winapi_WriteFile), METH_FASTCALL|METH_KEYWORDS, _winapi_WriteFile__doc__},
1191
1192 static PyObject *
1193 _winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer,
1194 int use_overlapped);
1195
1196 static PyObject *
1197 _winapi_WriteFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1198 {
1199 PyObject *return_value = NULL;
1200 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1201
1202 #define NUM_KEYWORDS 3
1203 static struct {
1204 PyGC_Head _this_is_not_used;
1205 PyObject_VAR_HEAD
1206 PyObject *ob_item[NUM_KEYWORDS];
1207 } _kwtuple = {
1208 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1209 .ob_item = { &_Py_ID(handle), &_Py_ID(buffer), &_Py_ID(overlapped), },
1210 };
1211 #undef NUM_KEYWORDS
1212 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1213
1214 #else // !Py_BUILD_CORE
1215 # define KWTUPLE NULL
1216 #endif // !Py_BUILD_CORE
1217
1218 static const char * const _keywords[] = {"handle", "buffer", "overlapped", NULL};
1219 static _PyArg_Parser _parser = {
1220 .keywords = _keywords,
1221 .format = "" F_HANDLE "O|p:WriteFile",
1222 .kwtuple = KWTUPLE,
1223 };
1224 #undef KWTUPLE
1225 HANDLE handle;
1226 PyObject *buffer;
1227 int use_overlapped = 0;
1228
1229 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1230 &handle, &buffer, &use_overlapped)) {
1231 goto exit;
1232 }
1233 return_value = _winapi_WriteFile_impl(module, handle, buffer, use_overlapped);
1234
1235 exit:
1236 return return_value;
1237 }
1238
1239 PyDoc_STRVAR(_winapi_GetACP__doc__,
1240 "GetACP($module, /)\n"
1241 "--\n"
1242 "\n"
1243 "Get the current Windows ANSI code page identifier.");
1244
1245 #define _WINAPI_GETACP_METHODDEF \
1246 {"GetACP", (PyCFunction)_winapi_GetACP, METH_NOARGS, _winapi_GetACP__doc__},
1247
1248 static PyObject *
1249 _winapi_GetACP_impl(PyObject *module);
1250
1251 static PyObject *
1252 _winapi_GetACP(PyObject *module, PyObject *Py_UNUSED(ignored))
1253 {
1254 return _winapi_GetACP_impl(module);
1255 }
1256
1257 PyDoc_STRVAR(_winapi_GetFileType__doc__,
1258 "GetFileType($module, /, handle)\n"
1259 "--\n"
1260 "\n");
1261
1262 #define _WINAPI_GETFILETYPE_METHODDEF \
1263 {"GetFileType", _PyCFunction_CAST(_winapi_GetFileType), METH_FASTCALL|METH_KEYWORDS, _winapi_GetFileType__doc__},
1264
1265 static DWORD
1266 _winapi_GetFileType_impl(PyObject *module, HANDLE handle);
1267
1268 static PyObject *
1269 _winapi_GetFileType(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1270 {
1271 PyObject *return_value = NULL;
1272 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1273
1274 #define NUM_KEYWORDS 1
1275 static struct {
1276 PyGC_Head _this_is_not_used;
1277 PyObject_VAR_HEAD
1278 PyObject *ob_item[NUM_KEYWORDS];
1279 } _kwtuple = {
1280 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1281 .ob_item = { &_Py_ID(handle), },
1282 };
1283 #undef NUM_KEYWORDS
1284 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1285
1286 #else // !Py_BUILD_CORE
1287 # define KWTUPLE NULL
1288 #endif // !Py_BUILD_CORE
1289
1290 static const char * const _keywords[] = {"handle", NULL};
1291 static _PyArg_Parser _parser = {
1292 .keywords = _keywords,
1293 .format = "" F_HANDLE ":GetFileType",
1294 .kwtuple = KWTUPLE,
1295 };
1296 #undef KWTUPLE
1297 HANDLE handle;
1298 DWORD _return_value;
1299
1300 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1301 &handle)) {
1302 goto exit;
1303 }
1304 _return_value = _winapi_GetFileType_impl(module, handle);
1305 if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
1306 goto exit;
1307 }
1308 return_value = Py_BuildValue("k", _return_value);
1309
1310 exit:
1311 return return_value;
1312 }
1313
1314 PyDoc_STRVAR(_winapi__mimetypes_read_windows_registry__doc__,
1315 "_mimetypes_read_windows_registry($module, /, on_type_read)\n"
1316 "--\n"
1317 "\n"
1318 "Optimized function for reading all known MIME types from the registry.\n"
1319 "\n"
1320 "*on_type_read* is a callable taking *type* and *ext* arguments, as for\n"
1321 "MimeTypes.add_type.");
1322
1323 #define _WINAPI__MIMETYPES_READ_WINDOWS_REGISTRY_METHODDEF \
1324 {"_mimetypes_read_windows_registry", _PyCFunction_CAST(_winapi__mimetypes_read_windows_registry), METH_FASTCALL|METH_KEYWORDS, _winapi__mimetypes_read_windows_registry__doc__},
1325
1326 static PyObject *
1327 _winapi__mimetypes_read_windows_registry_impl(PyObject *module,
1328 PyObject *on_type_read);
1329
1330 static PyObject *
1331 _winapi__mimetypes_read_windows_registry(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1332 {
1333 PyObject *return_value = NULL;
1334 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1335
1336 #define NUM_KEYWORDS 1
1337 static struct {
1338 PyGC_Head _this_is_not_used;
1339 PyObject_VAR_HEAD
1340 PyObject *ob_item[NUM_KEYWORDS];
1341 } _kwtuple = {
1342 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1343 .ob_item = { &_Py_ID(on_type_read), },
1344 };
1345 #undef NUM_KEYWORDS
1346 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1347
1348 #else // !Py_BUILD_CORE
1349 # define KWTUPLE NULL
1350 #endif // !Py_BUILD_CORE
1351
1352 static const char * const _keywords[] = {"on_type_read", NULL};
1353 static _PyArg_Parser _parser = {
1354 .keywords = _keywords,
1355 .fname = "_mimetypes_read_windows_registry",
1356 .kwtuple = KWTUPLE,
1357 };
1358 #undef KWTUPLE
1359 PyObject *argsbuf[1];
1360 PyObject *on_type_read;
1361
1362 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1363 if (!args) {
1364 goto exit;
1365 }
1366 on_type_read = args[0];
1367 return_value = _winapi__mimetypes_read_windows_registry_impl(module, on_type_read);
1368
1369 exit:
1370 return return_value;
1371 }
1372
1373 PyDoc_STRVAR(_winapi_NeedCurrentDirectoryForExePath__doc__,
1374 "NeedCurrentDirectoryForExePath($module, exe_name, /)\n"
1375 "--\n"
1376 "\n");
1377
1378 #define _WINAPI_NEEDCURRENTDIRECTORYFOREXEPATH_METHODDEF \
1379 {"NeedCurrentDirectoryForExePath", (PyCFunction)_winapi_NeedCurrentDirectoryForExePath, METH_O, _winapi_NeedCurrentDirectoryForExePath__doc__},
1380
1381 static int
1382 _winapi_NeedCurrentDirectoryForExePath_impl(PyObject *module,
1383 LPCWSTR exe_name);
1384
1385 static PyObject *
1386 _winapi_NeedCurrentDirectoryForExePath(PyObject *module, PyObject *arg)
1387 {
1388 PyObject *return_value = NULL;
1389 LPCWSTR exe_name = NULL;
1390 int _return_value;
1391
1392 if (!PyUnicode_Check(arg)) {
1393 _PyArg_BadArgument("NeedCurrentDirectoryForExePath", "argument", "str", arg);
1394 goto exit;
1395 }
1396 exe_name = PyUnicode_AsWideCharString(arg, NULL);
1397 if (exe_name == NULL) {
1398 goto exit;
1399 }
1400 _return_value = _winapi_NeedCurrentDirectoryForExePath_impl(module, exe_name);
1401 if ((_return_value == -1) && PyErr_Occurred()) {
1402 goto exit;
1403 }
1404 return_value = PyBool_FromLong((long)_return_value);
1405
1406 exit:
1407 /* Cleanup for exe_name */
1408 PyMem_Free((void *)exe_name);
1409
1410 return return_value;
1411 }
1412
1413 PyDoc_STRVAR(_winapi_CopyFile2__doc__,
1414 "CopyFile2($module, /, existing_file_name, new_file_name, flags,\n"
1415 " progress_routine=None)\n"
1416 "--\n"
1417 "\n"
1418 "Copies a file from one name to a new name.\n"
1419 "\n"
1420 "This is implemented using the CopyFile2 API, which preserves all stat\n"
1421 "and metadata information apart from security attributes.\n"
1422 "\n"
1423 "progress_routine is reserved for future use, but is currently not\n"
1424 "implemented. Its value is ignored.");
1425
1426 #define _WINAPI_COPYFILE2_METHODDEF \
1427 {"CopyFile2", _PyCFunction_CAST(_winapi_CopyFile2), METH_FASTCALL|METH_KEYWORDS, _winapi_CopyFile2__doc__},
1428
1429 static PyObject *
1430 _winapi_CopyFile2_impl(PyObject *module, LPCWSTR existing_file_name,
1431 LPCWSTR new_file_name, DWORD flags,
1432 PyObject *progress_routine);
1433
1434 static PyObject *
1435 _winapi_CopyFile2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1436 {
1437 PyObject *return_value = NULL;
1438 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1439
1440 #define NUM_KEYWORDS 4
1441 static struct {
1442 PyGC_Head _this_is_not_used;
1443 PyObject_VAR_HEAD
1444 PyObject *ob_item[NUM_KEYWORDS];
1445 } _kwtuple = {
1446 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1447 .ob_item = { &_Py_ID(existing_file_name), &_Py_ID(new_file_name), &_Py_ID(flags), &_Py_ID(progress_routine), },
1448 };
1449 #undef NUM_KEYWORDS
1450 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1451
1452 #else // !Py_BUILD_CORE
1453 # define KWTUPLE NULL
1454 #endif // !Py_BUILD_CORE
1455
1456 static const char * const _keywords[] = {"existing_file_name", "new_file_name", "flags", "progress_routine", NULL};
1457 static _PyArg_Parser _parser = {
1458 .keywords = _keywords,
1459 .format = "O&O&k|O:CopyFile2",
1460 .kwtuple = KWTUPLE,
1461 };
1462 #undef KWTUPLE
1463 LPCWSTR existing_file_name = NULL;
1464 LPCWSTR new_file_name = NULL;
1465 DWORD flags;
1466 PyObject *progress_routine = Py_None;
1467
1468 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1469 _PyUnicode_WideCharString_Converter, &existing_file_name, _PyUnicode_WideCharString_Converter, &new_file_name, &flags, &progress_routine)) {
1470 goto exit;
1471 }
1472 return_value = _winapi_CopyFile2_impl(module, existing_file_name, new_file_name, flags, progress_routine);
1473
1474 exit:
1475 /* Cleanup for existing_file_name */
1476 PyMem_Free((void *)existing_file_name);
1477 /* Cleanup for new_file_name */
1478 PyMem_Free((void *)new_file_name);
1479
1480 return return_value;
1481 }
1482 /*[clinic end generated code: output=9d43ae4bdbe1126a input=a9049054013a1b77]*/