Mercurial > cpython-lru_cache-weakref
annotate Modules/_winapi.c @ 86127:a3d09c19bb93
merge with 3.3
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sun, 06 Oct 2013 19:24:00 +0200 |
| parents | 4cc308acd26d |
| children | da10196b94f4 |
| rev | line source |
|---|---|
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1 /* |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
2 * Support routines from the Windows API |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
3 * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
4 * This module was originally created by merging PC/_subprocess.c with |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
5 * Modules/_multiprocessing/win32_functions.c. |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
6 * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
7 * Copyright (c) 2004 by Fredrik Lundh <fredrik@pythonware.com> |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
8 * Copyright (c) 2004 by Secret Labs AB, http://www.pythonware.com |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
9 * Copyright (c) 2004 by Peter Astrand <astrand@lysator.liu.se> |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
10 * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
11 * By obtaining, using, and/or copying this software and/or its |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
12 * associated documentation, you agree that you have read, understood, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
13 * and will comply with the following terms and conditions: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
14 * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
15 * Permission to use, copy, modify, and distribute this software and |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
16 * its associated documentation for any purpose and without fee is |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
17 * hereby granted, provided that the above copyright notice appears in |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
18 * all copies, and that both that copyright notice and this permission |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
19 * notice appear in supporting documentation, and that the name of the |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
20 * authors not be used in advertising or publicity pertaining to |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
21 * distribution of the software without specific, written prior |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
22 * permission. |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
23 * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
24 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
25 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
26 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
27 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
28 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
29 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
30 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
31 * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
32 */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
33 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
34 /* Licensed to PSF under a Contributor Agreement. */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
35 /* See http://www.python.org/2.4/license for licensing details. */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
36 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
37 #include "Python.h" |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
38 #include "structmember.h" |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
39 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
40 #define WINDOWS_LEAN_AND_MEAN |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
41 #include "windows.h" |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
42 #include <crtdbg.h> |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
43 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
44 #if defined(MS_WIN32) && !defined(MS_WIN64) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
45 #define HANDLE_TO_PYNUM(handle) \ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
46 PyLong_FromUnsignedLong((unsigned long) handle) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
47 #define PYNUM_TO_HANDLE(obj) ((HANDLE)PyLong_AsUnsignedLong(obj)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
48 #define F_POINTER "k" |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
49 #define T_POINTER T_ULONG |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
50 #else |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
51 #define HANDLE_TO_PYNUM(handle) \ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
52 PyLong_FromUnsignedLongLong((unsigned long long) handle) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
53 #define PYNUM_TO_HANDLE(obj) ((HANDLE)PyLong_AsUnsignedLongLong(obj)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
54 #define F_POINTER "K" |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
55 #define T_POINTER T_ULONGLONG |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
56 #endif |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
57 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
58 #define F_HANDLE F_POINTER |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
59 #define F_DWORD "k" |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
60 #define F_BOOL "i" |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
61 #define F_UINT "I" |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
62 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
63 #define T_HANDLE T_POINTER |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
64 |
|
84321
c75ab7b802df
Issue #9566: _winapi.WriteFile() now truncates length to DWORD_MAX (4294967295)
Victor Stinner <victor.stinner@gmail.com>
parents:
78697
diff
changeset
|
65 #define DWORD_MAX 4294967295U |
|
c75ab7b802df
Issue #9566: _winapi.WriteFile() now truncates length to DWORD_MAX (4294967295)
Victor Stinner <victor.stinner@gmail.com>
parents:
78697
diff
changeset
|
66 |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
67 /* Grab CancelIoEx dynamically from kernel32 */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
68 static int has_CancelIoEx = -1; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
69 static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
70 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
71 static int |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
72 check_CancelIoEx() |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
73 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
74 if (has_CancelIoEx == -1) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
75 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
76 HINSTANCE hKernel32 = GetModuleHandle("KERNEL32"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
77 * (FARPROC *) &Py_CancelIoEx = GetProcAddress(hKernel32, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
78 "CancelIoEx"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
79 has_CancelIoEx = (Py_CancelIoEx != NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
80 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
81 return has_CancelIoEx; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
82 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
83 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
84 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
85 /* |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
86 * A Python object wrapping an OVERLAPPED structure and other useful data |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
87 * for overlapped I/O |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
88 */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
89 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
90 typedef struct { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
91 PyObject_HEAD |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
92 OVERLAPPED overlapped; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
93 /* For convenience, we store the file handle too */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
94 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
95 /* Whether there's I/O in flight */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
96 int pending; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
97 /* Whether I/O completed successfully */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
98 int completed; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
99 /* Buffer used for reading (optional) */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
100 PyObject *read_buffer; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
101 /* Buffer used for writing (optional) */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
102 Py_buffer write_buffer; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
103 } OverlappedObject; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
104 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
105 static void |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
106 overlapped_dealloc(OverlappedObject *self) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
107 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
108 DWORD bytes; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
109 int err = GetLastError(); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
110 if (self->pending) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
111 /* make it a programming error to deallocate while operation |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
112 is pending, even if we can safely cancel it */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
113 if (check_CancelIoEx() && |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
114 Py_CancelIoEx(self->handle, &self->overlapped)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
115 GetOverlappedResult(self->handle, &self->overlapped, &bytes, TRUE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
116 PyErr_SetString(PyExc_RuntimeError, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
117 "I/O operations still in flight while destroying " |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
118 "Overlapped object, the process may crash"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
119 PyErr_WriteUnraisable(NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
120 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
121 CloseHandle(self->overlapped.hEvent); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
122 SetLastError(err); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
123 if (self->write_buffer.obj) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
124 PyBuffer_Release(&self->write_buffer); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
125 Py_CLEAR(self->read_buffer); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
126 PyObject_Del(self); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
127 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
128 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
129 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
130 overlapped_GetOverlappedResult(OverlappedObject *self, PyObject *waitobj) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
131 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
132 int wait; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
133 BOOL res; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
134 DWORD transferred = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
135 DWORD err; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
136 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
137 wait = PyObject_IsTrue(waitobj); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
138 if (wait < 0) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
139 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
140 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
141 res = GetOverlappedResult(self->handle, &self->overlapped, &transferred, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
142 wait != 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
143 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
144 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
145 err = res ? ERROR_SUCCESS : GetLastError(); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
146 switch (err) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
147 case ERROR_SUCCESS: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
148 case ERROR_MORE_DATA: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
149 case ERROR_OPERATION_ABORTED: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
150 self->completed = 1; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
151 self->pending = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
152 break; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
153 case ERROR_IO_INCOMPLETE: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
154 break; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
155 default: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
156 self->pending = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
157 return PyErr_SetExcFromWindowsErr(PyExc_IOError, err); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
158 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
159 if (self->completed && self->read_buffer != NULL) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
160 assert(PyBytes_CheckExact(self->read_buffer)); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
161 if (transferred != PyBytes_GET_SIZE(self->read_buffer) && |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
162 _PyBytes_Resize(&self->read_buffer, transferred)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
163 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
164 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
165 return Py_BuildValue("II", (unsigned) transferred, (unsigned) err); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
166 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
167 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
168 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
169 overlapped_getbuffer(OverlappedObject *self) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
170 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
171 PyObject *res; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
172 if (!self->completed) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
173 PyErr_SetString(PyExc_ValueError, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
174 "can't get read buffer before GetOverlappedResult() " |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
175 "signals the operation completed"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
176 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
177 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
178 res = self->read_buffer ? self->read_buffer : Py_None; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
179 Py_INCREF(res); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
180 return res; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
181 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
182 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
183 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
184 overlapped_cancel(OverlappedObject *self) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
185 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
186 BOOL res = TRUE; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
187 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
188 if (self->pending) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
189 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
190 if (check_CancelIoEx()) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
191 res = Py_CancelIoEx(self->handle, &self->overlapped); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
192 else |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
193 res = CancelIo(self->handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
194 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
195 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
196 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
197 /* CancelIoEx returns ERROR_NOT_FOUND if the I/O completed in-between */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
198 if (!res && GetLastError() != ERROR_NOT_FOUND) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
199 return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
200 self->pending = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
201 Py_RETURN_NONE; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
202 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
203 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
204 static PyMethodDef overlapped_methods[] = { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
205 {"GetOverlappedResult", (PyCFunction) overlapped_GetOverlappedResult, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
206 METH_O, NULL}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
207 {"getbuffer", (PyCFunction) overlapped_getbuffer, METH_NOARGS, NULL}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
208 {"cancel", (PyCFunction) overlapped_cancel, METH_NOARGS, NULL}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
209 {NULL} |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
210 }; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
211 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
212 static PyMemberDef overlapped_members[] = { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
213 {"event", T_HANDLE, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
214 offsetof(OverlappedObject, overlapped) + offsetof(OVERLAPPED, hEvent), |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
215 READONLY, "overlapped event handle"}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
216 {NULL} |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
217 }; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
218 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
219 PyTypeObject OverlappedType = { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
220 PyVarObject_HEAD_INIT(NULL, 0) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
221 /* tp_name */ "_winapi.Overlapped", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
222 /* tp_basicsize */ sizeof(OverlappedObject), |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
223 /* tp_itemsize */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
224 /* tp_dealloc */ (destructor) overlapped_dealloc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
225 /* tp_print */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
226 /* tp_getattr */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
227 /* tp_setattr */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
228 /* tp_reserved */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
229 /* tp_repr */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
230 /* tp_as_number */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
231 /* tp_as_sequence */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
232 /* tp_as_mapping */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
233 /* tp_hash */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
234 /* tp_call */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
235 /* tp_str */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
236 /* tp_getattro */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
237 /* tp_setattro */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
238 /* tp_as_buffer */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
239 /* tp_flags */ Py_TPFLAGS_DEFAULT, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
240 /* tp_doc */ "OVERLAPPED structure wrapper", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
241 /* tp_traverse */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
242 /* tp_clear */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
243 /* tp_richcompare */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
244 /* tp_weaklistoffset */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
245 /* tp_iter */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
246 /* tp_iternext */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
247 /* tp_methods */ overlapped_methods, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
248 /* tp_members */ overlapped_members, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
249 /* tp_getset */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
250 /* tp_base */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
251 /* tp_dict */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
252 /* tp_descr_get */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
253 /* tp_descr_set */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
254 /* tp_dictoffset */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
255 /* tp_init */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
256 /* tp_alloc */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
257 /* tp_new */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
258 }; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
259 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
260 static OverlappedObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
261 new_overlapped(HANDLE handle) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
262 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
263 OverlappedObject *self; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
264 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
265 self = PyObject_New(OverlappedObject, &OverlappedType); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
266 if (!self) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
267 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
268 self->handle = handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
269 self->read_buffer = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
270 self->pending = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
271 self->completed = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
272 memset(&self->overlapped, 0, sizeof(OVERLAPPED)); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
273 memset(&self->write_buffer, 0, sizeof(Py_buffer)); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
274 /* Manual reset, initially non-signalled */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
275 self->overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
276 return self; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
277 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
278 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
279 /* -------------------------------------------------------------------- */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
280 /* windows API functions */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
281 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
282 PyDoc_STRVAR(CloseHandle_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
283 "CloseHandle(handle) -> None\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
284 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
285 Close handle."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
286 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
287 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
288 winapi_CloseHandle(PyObject *self, PyObject *args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
289 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
290 HANDLE hObject; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
291 BOOL success; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
292 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
293 if (!PyArg_ParseTuple(args, F_HANDLE ":CloseHandle", &hObject)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
294 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
295 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
296 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
297 success = CloseHandle(hObject); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
298 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
299 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
300 if (!success) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
301 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
302 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
303 Py_RETURN_NONE; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
304 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
305 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
306 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
307 winapi_ConnectNamedPipe(PyObject *self, PyObject *args, PyObject *kwds) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
308 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
309 HANDLE hNamedPipe; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
310 int use_overlapped = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
311 BOOL success; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
312 OverlappedObject *overlapped = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
313 static char *kwlist[] = {"handle", "overlapped", NULL}; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
314 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
315 if (!PyArg_ParseTupleAndKeywords(args, kwds, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
316 F_HANDLE "|" F_BOOL, kwlist, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
317 &hNamedPipe, &use_overlapped)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
318 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
319 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
320 if (use_overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
321 overlapped = new_overlapped(hNamedPipe); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
322 if (!overlapped) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
323 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
324 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
325 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
326 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
327 success = ConnectNamedPipe(hNamedPipe, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
328 overlapped ? &overlapped->overlapped : NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
329 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
330 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
331 if (overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
332 int err = GetLastError(); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
333 /* Overlapped ConnectNamedPipe never returns a success code */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
334 assert(success == 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
335 if (err == ERROR_IO_PENDING) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
336 overlapped->pending = 1; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
337 else if (err == ERROR_PIPE_CONNECTED) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
338 SetEvent(overlapped->overlapped.hEvent); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
339 else { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
340 Py_DECREF(overlapped); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
341 return PyErr_SetFromWindowsErr(err); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
342 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
343 return (PyObject *) overlapped; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
344 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
345 if (!success) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
346 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
347 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
348 Py_RETURN_NONE; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
349 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
350 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
351 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
352 winapi_CreateFile(PyObject *self, PyObject *args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
353 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
354 LPCTSTR lpFileName; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
355 DWORD dwDesiredAccess; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
356 DWORD dwShareMode; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
357 LPSECURITY_ATTRIBUTES lpSecurityAttributes; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
358 DWORD dwCreationDisposition; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
359 DWORD dwFlagsAndAttributes; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
360 HANDLE hTemplateFile; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
361 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
362 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
363 if (!PyArg_ParseTuple(args, "s" F_DWORD F_DWORD F_POINTER |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
364 F_DWORD F_DWORD F_HANDLE, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
365 &lpFileName, &dwDesiredAccess, &dwShareMode, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
366 &lpSecurityAttributes, &dwCreationDisposition, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
367 &dwFlagsAndAttributes, &hTemplateFile)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
368 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
369 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
370 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
371 handle = CreateFile(lpFileName, dwDesiredAccess, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
372 dwShareMode, lpSecurityAttributes, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
373 dwCreationDisposition, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
374 dwFlagsAndAttributes, hTemplateFile); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
375 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
376 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
377 if (handle == INVALID_HANDLE_VALUE) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
378 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
379 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
380 return Py_BuildValue(F_HANDLE, handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
381 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
382 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
383 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
384 winapi_CreateNamedPipe(PyObject *self, PyObject *args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
385 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
386 LPCTSTR lpName; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
387 DWORD dwOpenMode; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
388 DWORD dwPipeMode; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
389 DWORD nMaxInstances; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
390 DWORD nOutBufferSize; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
391 DWORD nInBufferSize; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
392 DWORD nDefaultTimeOut; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
393 LPSECURITY_ATTRIBUTES lpSecurityAttributes; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
394 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
395 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
396 if (!PyArg_ParseTuple(args, "s" F_DWORD F_DWORD F_DWORD |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
397 F_DWORD F_DWORD F_DWORD F_POINTER, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
398 &lpName, &dwOpenMode, &dwPipeMode, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
399 &nMaxInstances, &nOutBufferSize, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
400 &nInBufferSize, &nDefaultTimeOut, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
401 &lpSecurityAttributes)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
402 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
403 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
404 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
405 handle = CreateNamedPipe(lpName, dwOpenMode, dwPipeMode, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
406 nMaxInstances, nOutBufferSize, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
407 nInBufferSize, nDefaultTimeOut, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
408 lpSecurityAttributes); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
409 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
410 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
411 if (handle == INVALID_HANDLE_VALUE) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
412 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
413 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
414 return Py_BuildValue(F_HANDLE, handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
415 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
416 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
417 PyDoc_STRVAR(CreatePipe_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
418 "CreatePipe(pipe_attrs, size) -> (read_handle, write_handle)\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
419 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
420 Create an anonymous pipe, and return handles to the read and\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
421 write ends of the pipe.\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
422 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
423 pipe_attrs is ignored internally and can be None."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
424 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
425 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
426 winapi_CreatePipe(PyObject* self, PyObject* args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
427 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
428 HANDLE read_pipe; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
429 HANDLE write_pipe; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
430 BOOL result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
431 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
432 PyObject* pipe_attributes; /* ignored */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
433 DWORD size; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
434 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
435 if (! PyArg_ParseTuple(args, "O" F_DWORD ":CreatePipe", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
436 &pipe_attributes, &size)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
437 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
438 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
439 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
440 result = CreatePipe(&read_pipe, &write_pipe, NULL, size); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
441 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
442 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
443 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
444 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
445 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
446 return Py_BuildValue( |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
447 "NN", HANDLE_TO_PYNUM(read_pipe), HANDLE_TO_PYNUM(write_pipe)); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
448 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
449 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
450 /* helpers for createprocess */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
451 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
452 static unsigned long |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
453 getulong(PyObject* obj, char* name) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
454 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
455 PyObject* value; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
456 unsigned long ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
457 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
458 value = PyObject_GetAttrString(obj, name); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
459 if (! value) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
460 PyErr_Clear(); /* FIXME: propagate error? */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
461 return 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
462 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
463 ret = PyLong_AsUnsignedLong(value); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
464 Py_DECREF(value); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
465 return ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
466 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
467 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
468 static HANDLE |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
469 gethandle(PyObject* obj, char* name) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
470 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
471 PyObject* value; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
472 HANDLE ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
473 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
474 value = PyObject_GetAttrString(obj, name); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
475 if (! value) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
476 PyErr_Clear(); /* FIXME: propagate error? */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
477 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
478 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
479 if (value == Py_None) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
480 ret = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
481 else |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
482 ret = PYNUM_TO_HANDLE(value); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
483 Py_DECREF(value); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
484 return ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
485 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
486 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
487 static PyObject* |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
488 getenvironment(PyObject* environment) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
489 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
490 Py_ssize_t i, envsize, totalsize; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
491 Py_UCS4 *buffer = NULL, *p, *end; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
492 PyObject *keys, *values, *res; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
493 |
|
85231
61227b4c169f
#18466: fix more typos. Patch by Févry Thibault.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
78697
diff
changeset
|
494 /* convert environment dictionary to windows environment string */ |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
495 if (! PyMapping_Check(environment)) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
496 PyErr_SetString( |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
497 PyExc_TypeError, "environment must be dictionary or None"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
498 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
499 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
500 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
501 envsize = PyMapping_Length(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
502 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
503 keys = PyMapping_Keys(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
504 values = PyMapping_Values(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
505 if (!keys || !values) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
506 goto error; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
507 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
508 totalsize = 1; /* trailing null character */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
509 for (i = 0; i < envsize; i++) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
510 PyObject* key = PyList_GET_ITEM(keys, i); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
511 PyObject* value = PyList_GET_ITEM(values, i); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
512 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
513 if (! PyUnicode_Check(key) || ! PyUnicode_Check(value)) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
514 PyErr_SetString(PyExc_TypeError, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
515 "environment can only contain strings"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
516 goto error; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
517 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
518 totalsize += PyUnicode_GET_LENGTH(key) + 1; /* +1 for '=' */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
519 totalsize += PyUnicode_GET_LENGTH(value) + 1; /* +1 for '\0' */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
520 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
521 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
522 buffer = PyMem_Malloc(totalsize * sizeof(Py_UCS4)); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
523 if (! buffer) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
524 goto error; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
525 p = buffer; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
526 end = buffer + totalsize; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
527 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
528 for (i = 0; i < envsize; i++) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
529 PyObject* key = PyList_GET_ITEM(keys, i); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
530 PyObject* value = PyList_GET_ITEM(values, i); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
531 if (!PyUnicode_AsUCS4(key, p, end - p, 0)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
532 goto error; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
533 p += PyUnicode_GET_LENGTH(key); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
534 *p++ = '='; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
535 if (!PyUnicode_AsUCS4(value, p, end - p, 0)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
536 goto error; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
537 p += PyUnicode_GET_LENGTH(value); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
538 *p++ = '\0'; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
539 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
540 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
541 /* add trailing null byte */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
542 *p++ = '\0'; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
543 assert(p == end); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
544 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
545 Py_XDECREF(keys); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
546 Py_XDECREF(values); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
547 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
548 res = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buffer, p - buffer); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
549 PyMem_Free(buffer); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
550 return res; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
551 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
552 error: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
553 PyMem_Free(buffer); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
554 Py_XDECREF(keys); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
555 Py_XDECREF(values); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
556 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
557 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
558 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
559 PyDoc_STRVAR(CreateProcess_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
560 "CreateProcess(app_name, cmd_line, proc_attrs, thread_attrs,\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
561 inherit, flags, env_mapping, curdir,\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
562 startup_info) -> (proc_handle, thread_handle,\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
563 pid, tid)\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
564 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
565 Create a new process and its primary thread. The return\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
566 value is a tuple of the process handle, thread handle,\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
567 process ID, and thread ID.\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
568 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
569 proc_attrs and thread_attrs are ignored internally and can be None."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
570 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
571 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
572 winapi_CreateProcess(PyObject* self, PyObject* args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
573 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
574 BOOL result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
575 PROCESS_INFORMATION pi; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
576 STARTUPINFOW si; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
577 PyObject* environment; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
578 wchar_t *wenvironment; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
579 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
580 wchar_t* application_name; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
581 wchar_t* command_line; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
582 PyObject* process_attributes; /* ignored */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
583 PyObject* thread_attributes; /* ignored */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
584 BOOL inherit_handles; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
585 DWORD creation_flags; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
586 PyObject* env_mapping; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
587 wchar_t* current_directory; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
588 PyObject* startup_info; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
589 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
590 if (! PyArg_ParseTuple(args, "ZZOO" F_BOOL F_DWORD "OZO:CreateProcess", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
591 &application_name, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
592 &command_line, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
593 &process_attributes, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
594 &thread_attributes, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
595 &inherit_handles, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
596 &creation_flags, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
597 &env_mapping, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
598 ¤t_directory, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
599 &startup_info)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
600 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
601 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
602 ZeroMemory(&si, sizeof(si)); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
603 si.cb = sizeof(si); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
604 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
605 /* note: we only support a small subset of all SI attributes */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
606 si.dwFlags = getulong(startup_info, "dwFlags"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
607 si.wShowWindow = (WORD)getulong(startup_info, "wShowWindow"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
608 si.hStdInput = gethandle(startup_info, "hStdInput"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
609 si.hStdOutput = gethandle(startup_info, "hStdOutput"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
610 si.hStdError = gethandle(startup_info, "hStdError"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
611 if (PyErr_Occurred()) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
612 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
613 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
614 if (env_mapping != Py_None) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
615 environment = getenvironment(env_mapping); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
616 if (! environment) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
617 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
618 wenvironment = PyUnicode_AsUnicode(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
619 if (wenvironment == NULL) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
620 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
621 Py_XDECREF(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
622 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
623 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
624 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
625 else { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
626 environment = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
627 wenvironment = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
628 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
629 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
630 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
631 result = CreateProcessW(application_name, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
632 command_line, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
633 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
634 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
635 inherit_handles, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
636 creation_flags | CREATE_UNICODE_ENVIRONMENT, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
637 wenvironment, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
638 current_directory, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
639 &si, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
640 &pi); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
641 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
642 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
643 Py_XDECREF(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
644 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
645 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
646 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
647 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
648 return Py_BuildValue("NNkk", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
649 HANDLE_TO_PYNUM(pi.hProcess), |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
650 HANDLE_TO_PYNUM(pi.hThread), |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
651 pi.dwProcessId, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
652 pi.dwThreadId); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
653 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
654 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
655 PyDoc_STRVAR(DuplicateHandle_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
656 "DuplicateHandle(source_proc_handle, source_handle,\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
657 target_proc_handle, target_handle, access,\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
658 inherit[, options]) -> handle\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
659 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
660 Return a duplicate handle object.\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
661 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
662 The duplicate handle refers to the same object as the original\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
663 handle. Therefore, any changes to the object are reflected\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
664 through both handles."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
665 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
666 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
667 winapi_DuplicateHandle(PyObject* self, PyObject* args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
668 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
669 HANDLE target_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
670 BOOL result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
671 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
672 HANDLE source_process_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
673 HANDLE source_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
674 HANDLE target_process_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
675 DWORD desired_access; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
676 BOOL inherit_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
677 DWORD options = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
678 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
679 if (! PyArg_ParseTuple(args, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
680 F_HANDLE F_HANDLE F_HANDLE F_DWORD F_BOOL F_DWORD |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
681 ":DuplicateHandle", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
682 &source_process_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
683 &source_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
684 &target_process_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
685 &desired_access, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
686 &inherit_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
687 &options)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
688 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
689 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
690 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
691 result = DuplicateHandle( |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
692 source_process_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
693 source_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
694 target_process_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
695 &target_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
696 desired_access, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
697 inherit_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
698 options |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
699 ); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
700 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
701 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
702 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
703 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
704 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
705 return HANDLE_TO_PYNUM(target_handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
706 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
707 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
708 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
709 winapi_ExitProcess(PyObject *self, PyObject *args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
710 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
711 UINT uExitCode; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
712 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
713 if (!PyArg_ParseTuple(args, F_UINT, &uExitCode)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
714 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
715 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
716 #if defined(Py_DEBUG) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
717 SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOALIGNMENTFAULTEXCEPT| |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
718 SEM_NOGPFAULTERRORBOX|SEM_NOOPENFILEERRORBOX); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
719 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
720 #endif |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
721 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
722 ExitProcess(uExitCode); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
723 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
724 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
725 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
726 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
727 PyDoc_STRVAR(GetCurrentProcess_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
728 "GetCurrentProcess() -> handle\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
729 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
730 Return a handle object for the current process."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
731 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
732 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
733 winapi_GetCurrentProcess(PyObject* self, PyObject* args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
734 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
735 if (! PyArg_ParseTuple(args, ":GetCurrentProcess")) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
736 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
737 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
738 return HANDLE_TO_PYNUM(GetCurrentProcess()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
739 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
740 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
741 PyDoc_STRVAR(GetExitCodeProcess_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
742 "GetExitCodeProcess(handle) -> Exit code\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
743 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
744 Return the termination status of the specified process."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
745 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
746 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
747 winapi_GetExitCodeProcess(PyObject* self, PyObject* args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
748 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
749 DWORD exit_code; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
750 BOOL result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
751 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
752 HANDLE process; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
753 if (! PyArg_ParseTuple(args, F_HANDLE ":GetExitCodeProcess", &process)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
754 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
755 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
756 result = GetExitCodeProcess(process, &exit_code); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
757 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
758 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
759 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
760 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
761 return PyLong_FromUnsignedLong(exit_code); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
762 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
763 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
764 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
765 winapi_GetLastError(PyObject *self, PyObject *args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
766 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
767 return Py_BuildValue(F_DWORD, GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
768 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
769 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
770 PyDoc_STRVAR(GetModuleFileName_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
771 "GetModuleFileName(module) -> path\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
772 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
773 Return the fully-qualified path for the file that contains\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
774 the specified module. The module must have been loaded by the\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
775 current process.\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
776 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
777 The module parameter should be a handle to the loaded module\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
778 whose path is being requested. If this parameter is 0, \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
779 GetModuleFileName retrieves the path of the executable file\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
780 of the current process."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
781 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
782 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
783 winapi_GetModuleFileName(PyObject* self, PyObject* args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
784 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
785 BOOL result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
786 HMODULE module; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
787 WCHAR filename[MAX_PATH]; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
788 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
789 if (! PyArg_ParseTuple(args, F_HANDLE ":GetModuleFileName", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
790 &module)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
791 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
792 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
793 result = GetModuleFileNameW(module, filename, MAX_PATH); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
794 filename[MAX_PATH-1] = '\0'; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
795 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
796 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
797 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
798 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
799 return PyUnicode_FromWideChar(filename, wcslen(filename)); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
800 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
801 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
802 PyDoc_STRVAR(GetStdHandle_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
803 "GetStdHandle(handle) -> integer\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
804 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
805 Return a handle to the specified standard device\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
806 (STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE).\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
807 The integer associated with the handle object is returned."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
808 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
809 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
810 winapi_GetStdHandle(PyObject* self, PyObject* args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
811 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
812 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
813 DWORD std_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
814 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
815 if (! PyArg_ParseTuple(args, F_DWORD ":GetStdHandle", &std_handle)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
816 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
817 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
818 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
819 handle = GetStdHandle(std_handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
820 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
821 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
822 if (handle == INVALID_HANDLE_VALUE) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
823 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
824 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
825 if (! handle) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
826 Py_INCREF(Py_None); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
827 return Py_None; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
828 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
829 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
830 /* note: returns integer, not handle object */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
831 return HANDLE_TO_PYNUM(handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
832 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
833 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
834 PyDoc_STRVAR(GetVersion_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
835 "GetVersion() -> version\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
836 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
837 Return the version number of the current operating system."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
838 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
839 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
840 winapi_GetVersion(PyObject* self, PyObject* args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
841 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
842 if (! PyArg_ParseTuple(args, ":GetVersion")) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
843 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
844 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
845 return PyLong_FromUnsignedLong(GetVersion()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
846 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
847 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
848 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
849 winapi_OpenProcess(PyObject *self, PyObject *args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
850 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
851 DWORD dwDesiredAccess; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
852 BOOL bInheritHandle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
853 DWORD dwProcessId; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
854 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
855 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
856 if (!PyArg_ParseTuple(args, F_DWORD F_BOOL F_DWORD, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
857 &dwDesiredAccess, &bInheritHandle, &dwProcessId)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
858 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
859 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
860 handle = OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
861 if (handle == NULL) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
862 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
863 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
864 return Py_BuildValue(F_HANDLE, handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
865 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
866 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
867 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
868 winapi_PeekNamedPipe(PyObject *self, PyObject *args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
869 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
870 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
871 int size = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
872 PyObject *buf = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
873 DWORD nread, navail, nleft; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
874 BOOL ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
875 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
876 if (!PyArg_ParseTuple(args, F_HANDLE "|i:PeekNamedPipe" , &handle, &size)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
877 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
878 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
879 if (size < 0) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
880 PyErr_SetString(PyExc_ValueError, "negative size"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
881 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
882 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
883 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
884 if (size) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
885 buf = PyBytes_FromStringAndSize(NULL, size); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
886 if (!buf) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
887 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
888 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
889 ret = PeekNamedPipe(handle, PyBytes_AS_STRING(buf), size, &nread, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
890 &navail, &nleft); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
891 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
892 if (!ret) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
893 Py_DECREF(buf); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
894 return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
895 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
896 if (_PyBytes_Resize(&buf, nread)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
897 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
898 return Py_BuildValue("Nii", buf, navail, nleft); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
899 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
900 else { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
901 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
902 ret = PeekNamedPipe(handle, NULL, 0, NULL, &navail, &nleft); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
903 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
904 if (!ret) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
905 return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
906 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
907 return Py_BuildValue("ii", navail, nleft); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
908 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
909 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
910 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
911 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
912 winapi_ReadFile(PyObject *self, PyObject *args, PyObject *kwds) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
913 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
914 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
915 int size; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
916 DWORD nread; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
917 PyObject *buf; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
918 BOOL ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
919 int use_overlapped = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
920 DWORD err; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
921 OverlappedObject *overlapped = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
922 static char *kwlist[] = {"handle", "size", "overlapped", NULL}; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
923 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
924 if (!PyArg_ParseTupleAndKeywords(args, kwds, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
925 F_HANDLE "i|i:ReadFile", kwlist, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
926 &handle, &size, &use_overlapped)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
927 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
928 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
929 buf = PyBytes_FromStringAndSize(NULL, size); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
930 if (!buf) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
931 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
932 if (use_overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
933 overlapped = new_overlapped(handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
934 if (!overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
935 Py_DECREF(buf); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
936 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
937 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
938 /* Steals reference to buf */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
939 overlapped->read_buffer = buf; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
940 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
941 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
942 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
943 ret = ReadFile(handle, PyBytes_AS_STRING(buf), size, &nread, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
944 overlapped ? &overlapped->overlapped : NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
945 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
946 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
947 err = ret ? 0 : GetLastError(); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
948 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
949 if (overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
950 if (!ret) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
951 if (err == ERROR_IO_PENDING) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
952 overlapped->pending = 1; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
953 else if (err != ERROR_MORE_DATA) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
954 Py_DECREF(overlapped); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
955 return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
956 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
957 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
958 return Py_BuildValue("NI", (PyObject *) overlapped, err); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
959 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
960 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
961 if (!ret && err != ERROR_MORE_DATA) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
962 Py_DECREF(buf); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
963 return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
964 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
965 if (_PyBytes_Resize(&buf, nread)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
966 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
967 return Py_BuildValue("NI", buf, err); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
968 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
969 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
970 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
971 winapi_SetNamedPipeHandleState(PyObject *self, PyObject *args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
972 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
973 HANDLE hNamedPipe; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
974 PyObject *oArgs[3]; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
975 DWORD dwArgs[3], *pArgs[3] = {NULL, NULL, NULL}; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
976 int i; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
977 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
978 if (!PyArg_ParseTuple(args, F_HANDLE "OOO", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
979 &hNamedPipe, &oArgs[0], &oArgs[1], &oArgs[2])) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
980 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
981 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
982 PyErr_Clear(); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
983 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
984 for (i = 0 ; i < 3 ; i++) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
985 if (oArgs[i] != Py_None) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
986 dwArgs[i] = PyLong_AsUnsignedLongMask(oArgs[i]); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
987 if (PyErr_Occurred()) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
988 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
989 pArgs[i] = &dwArgs[i]; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
990 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
991 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
992 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
993 if (!SetNamedPipeHandleState(hNamedPipe, pArgs[0], pArgs[1], pArgs[2])) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
994 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
995 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
996 Py_RETURN_NONE; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
997 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
998 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
999 PyDoc_STRVAR(TerminateProcess_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1000 "TerminateProcess(handle, exit_code) -> None\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1001 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1002 Terminate the specified process and all of its threads."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1003 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1004 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1005 winapi_TerminateProcess(PyObject* self, PyObject* args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1006 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1007 BOOL result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1008 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1009 HANDLE process; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1010 UINT exit_code; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1011 if (! PyArg_ParseTuple(args, F_HANDLE F_UINT ":TerminateProcess", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1012 &process, &exit_code)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1013 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1014 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1015 result = TerminateProcess(process, exit_code); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1016 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1017 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1018 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1019 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1020 Py_INCREF(Py_None); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1021 return Py_None; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1022 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1023 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1024 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1025 winapi_WaitNamedPipe(PyObject *self, PyObject *args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1026 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1027 LPCTSTR lpNamedPipeName; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1028 DWORD nTimeOut; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1029 BOOL success; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1030 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1031 if (!PyArg_ParseTuple(args, "s" F_DWORD, &lpNamedPipeName, &nTimeOut)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1032 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1033 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1034 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1035 success = WaitNamedPipe(lpNamedPipeName, nTimeOut); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1036 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1037 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1038 if (!success) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1039 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1040 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1041 Py_RETURN_NONE; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1042 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1043 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1044 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1045 winapi_WaitForMultipleObjects(PyObject* self, PyObject* args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1046 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1047 DWORD result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1048 PyObject *handle_seq; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1049 HANDLE handles[MAXIMUM_WAIT_OBJECTS]; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1050 HANDLE sigint_event = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1051 Py_ssize_t nhandles, i; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1052 BOOL wait_flag; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1053 DWORD milliseconds = INFINITE; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1054 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1055 if (!PyArg_ParseTuple(args, "O" F_BOOL "|" F_DWORD |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1056 ":WaitForMultipleObjects", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1057 &handle_seq, &wait_flag, &milliseconds)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1058 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1059 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1060 if (!PySequence_Check(handle_seq)) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1061 PyErr_Format(PyExc_TypeError, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1062 "sequence type expected, got '%s'", |
|
78697
ca54c27a9045
Fix typo in error handling for WaitForMultipleObjects()
Richard Oudkerk <shibturn@gmail.com>
parents:
76771
diff
changeset
|
1063 Py_TYPE(handle_seq)->tp_name); |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1064 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1065 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1066 nhandles = PySequence_Length(handle_seq); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1067 if (nhandles == -1) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1068 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1069 if (nhandles < 0 || nhandles >= MAXIMUM_WAIT_OBJECTS - 1) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1070 PyErr_Format(PyExc_ValueError, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1071 "need at most %zd handles, got a sequence of length %zd", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1072 MAXIMUM_WAIT_OBJECTS - 1, nhandles); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1073 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1074 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1075 for (i = 0; i < nhandles; i++) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1076 HANDLE h; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1077 PyObject *v = PySequence_GetItem(handle_seq, i); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1078 if (v == NULL) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1079 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1080 if (!PyArg_Parse(v, F_HANDLE, &h)) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1081 Py_DECREF(v); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1082 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1083 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1084 handles[i] = h; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1085 Py_DECREF(v); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1086 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1087 /* If this is the main thread then make the wait interruptible |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1088 by Ctrl-C unless we are waiting for *all* handles */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1089 if (!wait_flag && _PyOS_IsMainThread()) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1090 sigint_event = _PyOS_SigintEvent(); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1091 assert(sigint_event != NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1092 handles[nhandles++] = sigint_event; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1093 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1094 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1095 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1096 if (sigint_event != NULL) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1097 ResetEvent(sigint_event); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1098 result = WaitForMultipleObjects((DWORD) nhandles, handles, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1099 wait_flag, milliseconds); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1100 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1101 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1102 if (result == WAIT_FAILED) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1103 return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1104 else if (sigint_event != NULL && result == WAIT_OBJECT_0 + nhandles - 1) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1105 errno = EINTR; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1106 return PyErr_SetFromErrno(PyExc_IOError); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1107 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1108 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1109 return PyLong_FromLong((int) result); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1110 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1111 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1112 PyDoc_STRVAR(WaitForSingleObject_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1113 "WaitForSingleObject(handle, timeout) -> result\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1114 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1115 Wait until the specified object is in the signaled state or\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1116 the time-out interval elapses. The timeout value is specified\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1117 in milliseconds."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1118 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1119 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1120 winapi_WaitForSingleObject(PyObject* self, PyObject* args) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1121 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1122 DWORD result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1123 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1124 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1125 DWORD milliseconds; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1126 if (! PyArg_ParseTuple(args, F_HANDLE F_DWORD ":WaitForSingleObject", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1127 &handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1128 &milliseconds)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1129 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1130 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1131 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1132 result = WaitForSingleObject(handle, milliseconds); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1133 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1134 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1135 if (result == WAIT_FAILED) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1136 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1137 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1138 return PyLong_FromUnsignedLong(result); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1139 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1140 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1141 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1142 winapi_WriteFile(PyObject *self, PyObject *args, PyObject *kwds) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1143 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1144 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1145 Py_buffer _buf, *buf; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1146 PyObject *bufobj; |
|
84321
c75ab7b802df
Issue #9566: _winapi.WriteFile() now truncates length to DWORD_MAX (4294967295)
Victor Stinner <victor.stinner@gmail.com>
parents:
78697
diff
changeset
|
1147 DWORD len, written; |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1148 BOOL ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1149 int use_overlapped = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1150 DWORD err; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1151 OverlappedObject *overlapped = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1152 static char *kwlist[] = {"handle", "buffer", "overlapped", NULL}; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1153 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1154 /* First get handle and use_overlapped to know which Py_buffer to use */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1155 if (!PyArg_ParseTupleAndKeywords(args, kwds, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1156 F_HANDLE "O|i:WriteFile", kwlist, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1157 &handle, &bufobj, &use_overlapped)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1158 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1159 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1160 if (use_overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1161 overlapped = new_overlapped(handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1162 if (!overlapped) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1163 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1164 buf = &overlapped->write_buffer; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1165 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1166 else |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1167 buf = &_buf; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1168 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1169 if (!PyArg_Parse(bufobj, "y*", buf)) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1170 Py_XDECREF(overlapped); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1171 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1172 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1173 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1174 Py_BEGIN_ALLOW_THREADS |
|
84321
c75ab7b802df
Issue #9566: _winapi.WriteFile() now truncates length to DWORD_MAX (4294967295)
Victor Stinner <victor.stinner@gmail.com>
parents:
78697
diff
changeset
|
1175 len = (DWORD)Py_MIN(buf->len, DWORD_MAX); |
|
c75ab7b802df
Issue #9566: _winapi.WriteFile() now truncates length to DWORD_MAX (4294967295)
Victor Stinner <victor.stinner@gmail.com>
parents:
78697
diff
changeset
|
1176 ret = WriteFile(handle, buf->buf, len, &written, |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1177 overlapped ? &overlapped->overlapped : NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1178 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1179 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1180 err = ret ? 0 : GetLastError(); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1181 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1182 if (overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1183 if (!ret) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1184 if (err == ERROR_IO_PENDING) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1185 overlapped->pending = 1; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1186 else { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1187 Py_DECREF(overlapped); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1188 return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1189 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1190 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1191 return Py_BuildValue("NI", (PyObject *) overlapped, err); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1192 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1193 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1194 PyBuffer_Release(buf); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1195 if (!ret) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1196 return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1197 return Py_BuildValue("II", written, err); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1198 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1199 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1200 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1201 static PyMethodDef winapi_functions[] = { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1202 {"CloseHandle", winapi_CloseHandle, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1203 CloseHandle_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1204 {"ConnectNamedPipe", (PyCFunction)winapi_ConnectNamedPipe, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1205 METH_VARARGS | METH_KEYWORDS, ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1206 {"CreateFile", winapi_CreateFile, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1207 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1208 {"CreateNamedPipe", winapi_CreateNamedPipe, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1209 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1210 {"CreatePipe", winapi_CreatePipe, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1211 CreatePipe_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1212 {"CreateProcess", winapi_CreateProcess, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1213 CreateProcess_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1214 {"DuplicateHandle", winapi_DuplicateHandle, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1215 DuplicateHandle_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1216 {"ExitProcess", winapi_ExitProcess, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1217 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1218 {"GetCurrentProcess", winapi_GetCurrentProcess, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1219 GetCurrentProcess_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1220 {"GetExitCodeProcess", winapi_GetExitCodeProcess, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1221 GetExitCodeProcess_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1222 {"GetLastError", winapi_GetLastError, METH_NOARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1223 GetCurrentProcess_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1224 {"GetModuleFileName", winapi_GetModuleFileName, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1225 GetModuleFileName_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1226 {"GetStdHandle", winapi_GetStdHandle, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1227 GetStdHandle_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1228 {"GetVersion", winapi_GetVersion, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1229 GetVersion_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1230 {"OpenProcess", winapi_OpenProcess, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1231 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1232 {"PeekNamedPipe", winapi_PeekNamedPipe, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1233 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1234 {"ReadFile", (PyCFunction)winapi_ReadFile, METH_VARARGS | METH_KEYWORDS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1235 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1236 {"SetNamedPipeHandleState", winapi_SetNamedPipeHandleState, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1237 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1238 {"TerminateProcess", winapi_TerminateProcess, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1239 TerminateProcess_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1240 {"WaitNamedPipe", winapi_WaitNamedPipe, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1241 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1242 {"WaitForMultipleObjects", winapi_WaitForMultipleObjects, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1243 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1244 {"WaitForSingleObject", winapi_WaitForSingleObject, METH_VARARGS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1245 WaitForSingleObject_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1246 {"WriteFile", (PyCFunction)winapi_WriteFile, METH_VARARGS | METH_KEYWORDS, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1247 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1248 {NULL, NULL} |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1249 }; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1250 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1251 static struct PyModuleDef winapi_module = { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1252 PyModuleDef_HEAD_INIT, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1253 "_winapi", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1254 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1255 -1, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1256 winapi_functions, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1257 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1258 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1259 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1260 NULL |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1261 }; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1262 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1263 #define WINAPI_CONSTANT(fmt, con) \ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1264 PyDict_SetItemString(d, #con, Py_BuildValue(fmt, con)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1265 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1266 PyMODINIT_FUNC |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1267 PyInit__winapi(void) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1268 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1269 PyObject *d; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1270 PyObject *m; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1271 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1272 if (PyType_Ready(&OverlappedType) < 0) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1273 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1274 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1275 m = PyModule_Create(&winapi_module); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1276 if (m == NULL) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1277 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1278 d = PyModule_GetDict(m); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1279 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1280 PyDict_SetItemString(d, "Overlapped", (PyObject *) &OverlappedType); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1281 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1282 /* constants */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1283 WINAPI_CONSTANT(F_DWORD, CREATE_NEW_CONSOLE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1284 WINAPI_CONSTANT(F_DWORD, CREATE_NEW_PROCESS_GROUP); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1285 WINAPI_CONSTANT(F_DWORD, DUPLICATE_SAME_ACCESS); |
|
76541
08d4c2fe51ea
Issue #4892: multiprocessing Connections can now be transferred over multiprocessing Connections.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76405
diff
changeset
|
1286 WINAPI_CONSTANT(F_DWORD, DUPLICATE_CLOSE_SOURCE); |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1287 WINAPI_CONSTANT(F_DWORD, ERROR_ALREADY_EXISTS); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1288 WINAPI_CONSTANT(F_DWORD, ERROR_BROKEN_PIPE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1289 WINAPI_CONSTANT(F_DWORD, ERROR_IO_PENDING); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1290 WINAPI_CONSTANT(F_DWORD, ERROR_MORE_DATA); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1291 WINAPI_CONSTANT(F_DWORD, ERROR_NETNAME_DELETED); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1292 WINAPI_CONSTANT(F_DWORD, ERROR_NO_SYSTEM_RESOURCES); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1293 WINAPI_CONSTANT(F_DWORD, ERROR_MORE_DATA); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1294 WINAPI_CONSTANT(F_DWORD, ERROR_NETNAME_DELETED); |
|
76771
44f078ea05f3
Fix for Issue 14725 for 3.3 branch.
Richard Oudkerk <shibturn@gmail.com>
parents:
76541
diff
changeset
|
1295 WINAPI_CONSTANT(F_DWORD, ERROR_NO_DATA); |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1296 WINAPI_CONSTANT(F_DWORD, ERROR_NO_SYSTEM_RESOURCES); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1297 WINAPI_CONSTANT(F_DWORD, ERROR_OPERATION_ABORTED); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1298 WINAPI_CONSTANT(F_DWORD, ERROR_PIPE_BUSY); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1299 WINAPI_CONSTANT(F_DWORD, ERROR_PIPE_CONNECTED); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1300 WINAPI_CONSTANT(F_DWORD, ERROR_SEM_TIMEOUT); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1301 WINAPI_CONSTANT(F_DWORD, FILE_FLAG_FIRST_PIPE_INSTANCE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1302 WINAPI_CONSTANT(F_DWORD, FILE_FLAG_OVERLAPPED); |
|
76541
08d4c2fe51ea
Issue #4892: multiprocessing Connections can now be transferred over multiprocessing Connections.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76405
diff
changeset
|
1303 WINAPI_CONSTANT(F_DWORD, FILE_GENERIC_READ); |
|
08d4c2fe51ea
Issue #4892: multiprocessing Connections can now be transferred over multiprocessing Connections.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76405
diff
changeset
|
1304 WINAPI_CONSTANT(F_DWORD, FILE_GENERIC_WRITE); |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1305 WINAPI_CONSTANT(F_DWORD, GENERIC_READ); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1306 WINAPI_CONSTANT(F_DWORD, GENERIC_WRITE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1307 WINAPI_CONSTANT(F_DWORD, INFINITE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1308 WINAPI_CONSTANT(F_DWORD, NMPWAIT_WAIT_FOREVER); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1309 WINAPI_CONSTANT(F_DWORD, OPEN_EXISTING); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1310 WINAPI_CONSTANT(F_DWORD, PIPE_ACCESS_DUPLEX); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1311 WINAPI_CONSTANT(F_DWORD, PIPE_ACCESS_INBOUND); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1312 WINAPI_CONSTANT(F_DWORD, PIPE_READMODE_MESSAGE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1313 WINAPI_CONSTANT(F_DWORD, PIPE_TYPE_MESSAGE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1314 WINAPI_CONSTANT(F_DWORD, PIPE_UNLIMITED_INSTANCES); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1315 WINAPI_CONSTANT(F_DWORD, PIPE_WAIT); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1316 WINAPI_CONSTANT(F_DWORD, PROCESS_ALL_ACCESS); |
|
76541
08d4c2fe51ea
Issue #4892: multiprocessing Connections can now be transferred over multiprocessing Connections.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76405
diff
changeset
|
1317 WINAPI_CONSTANT(F_DWORD, PROCESS_DUP_HANDLE); |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1318 WINAPI_CONSTANT(F_DWORD, STARTF_USESHOWWINDOW); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1319 WINAPI_CONSTANT(F_DWORD, STARTF_USESTDHANDLES); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1320 WINAPI_CONSTANT(F_DWORD, STD_INPUT_HANDLE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1321 WINAPI_CONSTANT(F_DWORD, STD_OUTPUT_HANDLE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1322 WINAPI_CONSTANT(F_DWORD, STD_ERROR_HANDLE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1323 WINAPI_CONSTANT(F_DWORD, STILL_ACTIVE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1324 WINAPI_CONSTANT(F_DWORD, SW_HIDE); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1325 WINAPI_CONSTANT(F_DWORD, WAIT_OBJECT_0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1326 WINAPI_CONSTANT(F_DWORD, WAIT_TIMEOUT); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1327 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1328 WINAPI_CONSTANT("i", NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1329 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1330 return m; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1331 } |
