Debian Codegraph @

Modules/clinic/_winapi.c.h

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