Mercurial > cpython-lru_cache-weakref
annotate Modules/_winapi.c @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | da10196b94f4 |
| children |
| 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(); |
|
87201
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
110 |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
111 if (self->pending) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
112 if (check_CancelIoEx() && |
|
87201
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
113 Py_CancelIoEx(self->handle, &self->overlapped) && |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
114 GetOverlappedResult(self->handle, &self->overlapped, &bytes, TRUE)) |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
115 { |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
116 /* The operation is no longer pending -- nothing to do. */ |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
117 } |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
118 else if (_Py_Finalizing == NULL) |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
119 { |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
120 /* The operation is still pending -- give a warning. This |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
121 will probably only happen on Windows XP. */ |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
122 PyErr_SetString(PyExc_RuntimeError, |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
123 "I/O operations still in flight while destroying " |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
124 "Overlapped object, the process may crash"); |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
125 PyErr_WriteUnraisable(NULL); |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
126 } |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
127 else |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
128 { |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
129 /* The operation is still pending, but the process is |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
130 probably about to exit, so we need not worry too much |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
131 about memory leaks. Leaking self prevents a potential |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
132 crash. This can happen when a daemon thread is cleaned |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
133 up at exit -- see #19565. We only expect to get here |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
134 on Windows XP. */ |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
135 CloseHandle(self->overlapped.hEvent); |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
136 SetLastError(err); |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
137 return; |
|
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
138 } |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
139 } |
|
87201
da10196b94f4
Issue #19565: Prevent warnings at shutdown about pending overlapped ops.
Richard Oudkerk <shibturn@gmail.com>
parents:
85232
diff
changeset
|
140 |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
141 CloseHandle(self->overlapped.hEvent); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
142 SetLastError(err); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 PyObject_Del(self); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
147 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
148 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
149 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
150 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
|
151 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
152 int wait; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
153 BOOL res; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
154 DWORD transferred = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
155 DWORD err; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
156 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
157 wait = PyObject_IsTrue(waitobj); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
158 if (wait < 0) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
159 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
160 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
161 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
|
162 wait != 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
163 Py_END_ALLOW_THREADS |
|
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 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
|
166 switch (err) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
167 case ERROR_SUCCESS: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
168 case ERROR_MORE_DATA: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
169 case ERROR_OPERATION_ABORTED: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
170 self->completed = 1; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
171 self->pending = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
172 break; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
173 case ERROR_IO_INCOMPLETE: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
174 break; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
175 default: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
176 self->pending = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
177 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
|
178 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
179 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
|
180 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
|
181 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
|
182 _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
|
183 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
184 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
185 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
|
186 } |
|
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 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
189 overlapped_getbuffer(OverlappedObject *self) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
190 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
191 PyObject *res; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
192 if (!self->completed) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
193 PyErr_SetString(PyExc_ValueError, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
194 "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
|
195 "signals the operation completed"); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
196 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
197 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
198 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
|
199 Py_INCREF(res); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
200 return res; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
201 } |
|
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 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
204 overlapped_cancel(OverlappedObject *self) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
205 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
206 BOOL res = TRUE; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
207 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
208 if (self->pending) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
209 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
210 if (check_CancelIoEx()) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
211 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
|
212 else |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
213 res = CancelIo(self->handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
214 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
215 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
216 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
217 /* 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
|
218 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
|
219 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
|
220 self->pending = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
221 Py_RETURN_NONE; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
222 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
223 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
224 static PyMethodDef overlapped_methods[] = { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
225 {"GetOverlappedResult", (PyCFunction) overlapped_GetOverlappedResult, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
226 METH_O, NULL}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
227 {"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
|
228 {"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
|
229 {NULL} |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
230 }; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
231 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
232 static PyMemberDef overlapped_members[] = { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
233 {"event", T_HANDLE, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
234 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
|
235 READONLY, "overlapped event handle"}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
236 {NULL} |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
237 }; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
238 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
239 PyTypeObject OverlappedType = { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
240 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
|
241 /* tp_name */ "_winapi.Overlapped", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
242 /* tp_basicsize */ sizeof(OverlappedObject), |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
243 /* tp_itemsize */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
244 /* 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
|
245 /* tp_print */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
246 /* tp_getattr */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
247 /* tp_setattr */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
248 /* tp_reserved */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
249 /* tp_repr */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
250 /* tp_as_number */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
251 /* tp_as_sequence */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
252 /* tp_as_mapping */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
253 /* tp_hash */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
254 /* tp_call */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
255 /* tp_str */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
256 /* tp_getattro */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
257 /* tp_setattro */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
258 /* tp_as_buffer */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
259 /* 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
|
260 /* 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
|
261 /* tp_traverse */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
262 /* tp_clear */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
263 /* tp_richcompare */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
264 /* tp_weaklistoffset */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
265 /* tp_iter */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
266 /* tp_iternext */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
267 /* tp_methods */ overlapped_methods, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
268 /* tp_members */ overlapped_members, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
269 /* tp_getset */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
270 /* tp_base */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
271 /* tp_dict */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
272 /* tp_descr_get */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
273 /* tp_descr_set */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
274 /* tp_dictoffset */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
275 /* tp_init */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
276 /* tp_alloc */ 0, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
277 /* tp_new */ 0, |
|
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 static OverlappedObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
281 new_overlapped(HANDLE handle) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
282 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
283 OverlappedObject *self; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
284 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
285 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
|
286 if (!self) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
287 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
288 self->handle = handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
289 self->read_buffer = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
290 self->pending = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
291 self->completed = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
292 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
|
293 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
|
294 /* 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
|
295 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
|
296 return self; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
297 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
298 |
|
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 /* windows API functions */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
301 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
302 PyDoc_STRVAR(CloseHandle_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
303 "CloseHandle(handle) -> None\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
304 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
305 Close handle."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
306 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
307 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
308 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
|
309 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
310 HANDLE hObject; |
|
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 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
313 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
|
314 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
315 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
316 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
317 success = CloseHandle(hObject); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
318 Py_END_ALLOW_THREADS |
|
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 (!success) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
321 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
322 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
323 Py_RETURN_NONE; |
|
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 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
327 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
|
328 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
329 HANDLE hNamedPipe; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
330 int use_overlapped = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
331 BOOL success; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
332 OverlappedObject *overlapped = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
333 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
|
334 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
335 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
|
336 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
|
337 &hNamedPipe, &use_overlapped)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
338 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
339 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
340 if (use_overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
341 overlapped = new_overlapped(hNamedPipe); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
342 if (!overlapped) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
343 return NULL; |
|
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 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
346 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
347 success = ConnectNamedPipe(hNamedPipe, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
348 overlapped ? &overlapped->overlapped : NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
349 Py_END_ALLOW_THREADS |
|
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 if (overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
352 int err = GetLastError(); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
353 /* 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
|
354 assert(success == 0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
355 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
|
356 overlapped->pending = 1; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
357 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
|
358 SetEvent(overlapped->overlapped.hEvent); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
359 else { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
360 Py_DECREF(overlapped); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
361 return PyErr_SetFromWindowsErr(err); |
|
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 return (PyObject *) overlapped; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
364 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
365 if (!success) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
366 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
367 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
368 Py_RETURN_NONE; |
|
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 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
371 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
372 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
|
373 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
374 LPCTSTR lpFileName; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
375 DWORD dwDesiredAccess; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
376 DWORD dwShareMode; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
377 LPSECURITY_ATTRIBUTES lpSecurityAttributes; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
378 DWORD dwCreationDisposition; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
379 DWORD dwFlagsAndAttributes; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
380 HANDLE hTemplateFile; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
381 HANDLE handle; |
|
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 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
|
384 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
|
385 &lpFileName, &dwDesiredAccess, &dwShareMode, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
386 &lpSecurityAttributes, &dwCreationDisposition, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
387 &dwFlagsAndAttributes, &hTemplateFile)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
388 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
389 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
390 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
391 handle = CreateFile(lpFileName, dwDesiredAccess, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
392 dwShareMode, lpSecurityAttributes, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
393 dwCreationDisposition, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
394 dwFlagsAndAttributes, hTemplateFile); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
395 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
396 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
397 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
|
398 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
399 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
400 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
|
401 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
402 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
403 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
404 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
|
405 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
406 LPCTSTR lpName; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
407 DWORD dwOpenMode; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
408 DWORD dwPipeMode; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
409 DWORD nMaxInstances; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
410 DWORD nOutBufferSize; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
411 DWORD nInBufferSize; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
412 DWORD nDefaultTimeOut; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
413 LPSECURITY_ATTRIBUTES lpSecurityAttributes; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
414 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 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
|
417 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
|
418 &lpName, &dwOpenMode, &dwPipeMode, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
419 &nMaxInstances, &nOutBufferSize, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
420 &nInBufferSize, &nDefaultTimeOut, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
421 &lpSecurityAttributes)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
422 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
423 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
424 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
425 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
|
426 nMaxInstances, nOutBufferSize, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
427 nInBufferSize, nDefaultTimeOut, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
428 lpSecurityAttributes); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
429 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
430 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
431 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
|
432 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
433 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
434 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
|
435 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
436 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
437 PyDoc_STRVAR(CreatePipe_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
438 "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
|
439 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
440 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
|
441 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
|
442 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
443 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
|
444 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
445 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
446 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
|
447 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
448 HANDLE read_pipe; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
449 HANDLE write_pipe; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
450 BOOL result; |
|
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 PyObject* pipe_attributes; /* ignored */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
453 DWORD size; |
|
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 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
|
456 &pipe_attributes, &size)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
457 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
458 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
459 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
460 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
|
461 Py_END_ALLOW_THREADS |
|
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 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
464 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
465 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
466 return Py_BuildValue( |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
467 "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
|
468 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
469 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
470 /* helpers for createprocess */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
471 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
472 static unsigned long |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
473 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
|
474 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
475 PyObject* value; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
476 unsigned long ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
477 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
478 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
|
479 if (! value) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
480 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
|
481 return 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
482 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
483 ret = PyLong_AsUnsignedLong(value); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
484 Py_DECREF(value); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
485 return ret; |
|
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 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
488 static HANDLE |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
489 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
|
490 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
491 PyObject* value; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
492 HANDLE ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
493 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
494 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
|
495 if (! value) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
496 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
|
497 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
498 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
499 if (value == Py_None) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
500 ret = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
501 else |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
502 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
|
503 Py_DECREF(value); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
504 return ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
505 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
506 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
507 static PyObject* |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
508 getenvironment(PyObject* environment) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
509 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
510 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
|
511 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
|
512 PyObject *keys, *values, *res; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
513 |
|
85231
61227b4c169f
#18466: fix more typos. Patch by Févry Thibault.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
78697
diff
changeset
|
514 /* 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
|
515 if (! PyMapping_Check(environment)) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
516 PyErr_SetString( |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
517 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
|
518 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
519 } |
|
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 envsize = PyMapping_Length(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
522 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
523 keys = PyMapping_Keys(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
524 values = PyMapping_Values(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
525 if (!keys || !values) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
526 goto error; |
|
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 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
|
529 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
|
530 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
|
531 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
|
532 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
533 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
|
534 PyErr_SetString(PyExc_TypeError, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
535 "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
|
536 goto error; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
537 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
538 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
|
539 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
|
540 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
541 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
542 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
|
543 if (! buffer) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
544 goto error; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
545 p = buffer; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
546 end = buffer + totalsize; |
|
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 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
|
549 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
|
550 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
|
551 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
|
552 goto error; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
553 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
|
554 *p++ = '='; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
555 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
|
556 goto error; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
557 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
|
558 *p++ = '\0'; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
559 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
560 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
561 /* add trailing null byte */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
562 *p++ = '\0'; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
563 assert(p == end); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
564 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
565 Py_XDECREF(keys); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
566 Py_XDECREF(values); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
567 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
568 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
|
569 PyMem_Free(buffer); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
570 return res; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
571 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
572 error: |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
573 PyMem_Free(buffer); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
574 Py_XDECREF(keys); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
575 Py_XDECREF(values); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
576 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
577 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
578 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
579 PyDoc_STRVAR(CreateProcess_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
580 "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
|
581 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
|
582 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
|
583 pid, tid)\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
584 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
585 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
|
586 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
|
587 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
|
588 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
589 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
|
590 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
591 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
592 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
|
593 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
594 BOOL result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
595 PROCESS_INFORMATION pi; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
596 STARTUPINFOW si; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
597 PyObject* environment; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
598 wchar_t *wenvironment; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
599 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
600 wchar_t* application_name; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
601 wchar_t* command_line; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
602 PyObject* process_attributes; /* ignored */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
603 PyObject* thread_attributes; /* ignored */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
604 BOOL inherit_handles; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
605 DWORD creation_flags; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
606 PyObject* env_mapping; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
607 wchar_t* current_directory; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
608 PyObject* startup_info; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
609 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
610 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
|
611 &application_name, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
612 &command_line, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
613 &process_attributes, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
614 &thread_attributes, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
615 &inherit_handles, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
616 &creation_flags, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
617 &env_mapping, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
618 ¤t_directory, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
619 &startup_info)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
620 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
621 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
622 ZeroMemory(&si, sizeof(si)); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
623 si.cb = sizeof(si); |
|
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 /* 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
|
626 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 if (PyErr_Occurred()) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
632 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
633 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
634 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
|
635 environment = getenvironment(env_mapping); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
636 if (! environment) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
637 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
638 wenvironment = PyUnicode_AsUnicode(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
639 if (wenvironment == NULL) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
640 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
641 Py_XDECREF(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
642 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
643 } |
|
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 else { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
646 environment = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
647 wenvironment = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
648 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
649 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
650 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
651 result = CreateProcessW(application_name, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
652 command_line, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
653 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
654 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
655 inherit_handles, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
656 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
|
657 wenvironment, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
658 current_directory, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
659 &si, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
660 &pi); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
661 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
662 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
663 Py_XDECREF(environment); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
664 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
665 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
666 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
667 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
668 return Py_BuildValue("NNkk", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
669 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
|
670 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
|
671 pi.dwProcessId, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
672 pi.dwThreadId); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
673 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
674 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
675 PyDoc_STRVAR(DuplicateHandle_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
676 "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
|
677 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
|
678 inherit[, options]) -> handle\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
679 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
680 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
|
681 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
682 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
|
683 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
|
684 through both handles."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
685 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
686 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
687 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
|
688 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
689 HANDLE target_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
690 BOOL result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
691 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
692 HANDLE source_process_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
693 HANDLE source_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
694 HANDLE target_process_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
695 DWORD desired_access; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
696 BOOL inherit_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
697 DWORD options = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
698 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
699 if (! PyArg_ParseTuple(args, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
700 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
|
701 ":DuplicateHandle", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
702 &source_process_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
703 &source_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
704 &target_process_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
705 &desired_access, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
706 &inherit_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
707 &options)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
708 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
709 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
710 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
711 result = DuplicateHandle( |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
712 source_process_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
713 source_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
714 target_process_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
715 &target_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
716 desired_access, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
717 inherit_handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
718 options |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
719 ); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
720 Py_END_ALLOW_THREADS |
|
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 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
723 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
724 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
725 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
|
726 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
727 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
728 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
729 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
|
730 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
731 UINT uExitCode; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
732 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
733 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
|
734 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
735 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
736 #if defined(Py_DEBUG) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
737 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
|
738 SEM_NOGPFAULTERRORBOX|SEM_NOOPENFILEERRORBOX); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
739 _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
|
740 #endif |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
741 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
742 ExitProcess(uExitCode); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
743 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
744 return NULL; |
|
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 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
747 PyDoc_STRVAR(GetCurrentProcess_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
748 "GetCurrentProcess() -> handle\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
749 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
750 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
|
751 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
752 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
753 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
|
754 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
755 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
|
756 return NULL; |
|
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 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
|
759 } |
|
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 PyDoc_STRVAR(GetExitCodeProcess_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
762 "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
|
763 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
764 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
|
765 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
766 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
767 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
|
768 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
769 DWORD exit_code; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
770 BOOL result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
771 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
772 HANDLE process; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
773 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
|
774 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
775 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
776 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
|
777 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
778 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
779 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
780 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
781 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
|
782 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
783 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
784 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
785 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
|
786 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
787 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
|
788 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
789 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
790 PyDoc_STRVAR(GetModuleFileName_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
791 "GetModuleFileName(module) -> path\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
792 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
793 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
|
794 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
|
795 current process.\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
796 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
797 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
|
798 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
|
799 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
|
800 of the current process."); |
|
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 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
803 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
|
804 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
805 BOOL result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
806 HMODULE module; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
807 WCHAR filename[MAX_PATH]; |
|
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 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
|
810 &module)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
811 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
812 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
813 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
|
814 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
|
815 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
816 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
817 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
818 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
819 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
|
820 } |
|
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 PyDoc_STRVAR(GetStdHandle_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
823 "GetStdHandle(handle) -> integer\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
824 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
825 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
|
826 (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
|
827 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
|
828 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
829 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
830 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
|
831 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
832 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
833 DWORD std_handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
834 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
835 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
|
836 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
837 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
838 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
839 handle = GetStdHandle(std_handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
840 Py_END_ALLOW_THREADS |
|
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 (handle == INVALID_HANDLE_VALUE) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
843 return PyErr_SetFromWindowsErr(GetLastError()); |
|
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 if (! handle) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
846 Py_INCREF(Py_None); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
847 return Py_None; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
848 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
849 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
850 /* 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
|
851 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
|
852 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
853 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
854 PyDoc_STRVAR(GetVersion_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
855 "GetVersion() -> version\n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
856 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
857 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
|
858 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
859 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
860 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
|
861 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
862 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
|
863 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
864 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
865 return PyLong_FromUnsignedLong(GetVersion()); |
|
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 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
868 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
869 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
|
870 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
871 DWORD dwDesiredAccess; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
872 BOOL bInheritHandle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
873 DWORD dwProcessId; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
874 HANDLE handle; |
|
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_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
|
877 &dwDesiredAccess, &bInheritHandle, &dwProcessId)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
878 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
879 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
880 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
|
881 if (handle == NULL) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
882 return PyErr_SetFromWindowsErr(0); |
|
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 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
|
885 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
886 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
887 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
888 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
|
889 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
890 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
891 int size = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
892 PyObject *buf = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
893 DWORD nread, navail, nleft; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
894 BOOL ret; |
|
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 (!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
|
897 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
898 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
899 if (size < 0) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
900 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
|
901 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
902 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
903 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
904 if (size) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
905 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
|
906 if (!buf) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
907 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
908 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
909 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
|
910 &navail, &nleft); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
911 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
912 if (!ret) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
913 Py_DECREF(buf); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
914 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
|
915 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
916 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
|
917 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
918 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
|
919 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
920 else { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
921 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
922 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
|
923 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
924 if (!ret) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
925 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
|
926 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
927 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
|
928 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
929 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
930 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
931 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
932 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
|
933 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
934 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
935 int size; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
936 DWORD nread; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
937 PyObject *buf; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
938 BOOL ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
939 int use_overlapped = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
940 DWORD err; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
941 OverlappedObject *overlapped = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
942 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
|
943 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
944 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
|
945 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
|
946 &handle, &size, &use_overlapped)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
947 return NULL; |
|
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 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
|
950 if (!buf) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
951 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
952 if (use_overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
953 overlapped = new_overlapped(handle); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
954 if (!overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
955 Py_DECREF(buf); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
956 return NULL; |
|
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 /* Steals reference to buf */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
959 overlapped->read_buffer = buf; |
|
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 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
962 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
963 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
|
964 overlapped ? &overlapped->overlapped : NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
965 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
966 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
967 err = ret ? 0 : GetLastError(); |
|
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 if (overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
970 if (!ret) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
971 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
|
972 overlapped->pending = 1; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
973 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
|
974 Py_DECREF(overlapped); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
975 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
|
976 } |
|
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 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
|
979 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
980 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
981 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
|
982 Py_DECREF(buf); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
983 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
|
984 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
985 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
|
986 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
987 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
|
988 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
989 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
990 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
991 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
|
992 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
993 HANDLE hNamedPipe; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
994 PyObject *oArgs[3]; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
995 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
|
996 int i; |
|
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 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
|
999 &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
|
1000 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1001 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1002 PyErr_Clear(); |
|
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 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
|
1005 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
|
1006 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
|
1007 if (PyErr_Occurred()) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1008 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1009 pArgs[i] = &dwArgs[i]; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1010 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1011 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1012 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1013 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
|
1014 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1015 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1016 Py_RETURN_NONE; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1017 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1018 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1019 PyDoc_STRVAR(TerminateProcess_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1020 "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
|
1021 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1022 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
|
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_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
|
1026 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1027 BOOL result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1028 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1029 HANDLE process; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1030 UINT exit_code; |
|
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, 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
|
1032 &process, &exit_code)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1033 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1034 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1035 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
|
1036 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1037 if (! result) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1038 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1039 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1040 Py_INCREF(Py_None); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1041 return Py_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_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
|
1046 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1047 LPCTSTR lpNamedPipeName; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1048 DWORD nTimeOut; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1049 BOOL success; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1050 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1051 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
|
1052 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1053 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1054 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1055 success = WaitNamedPipe(lpNamedPipeName, nTimeOut); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1056 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1057 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1058 if (!success) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1059 return PyErr_SetFromWindowsErr(0); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1060 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1061 Py_RETURN_NONE; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1062 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1063 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1064 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1065 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
|
1066 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1067 DWORD result; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1068 PyObject *handle_seq; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1069 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
|
1070 HANDLE sigint_event = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1071 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
|
1072 BOOL wait_flag; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1073 DWORD milliseconds = INFINITE; |
|
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 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
|
1076 ":WaitForMultipleObjects", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1077 &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
|
1078 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1079 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1080 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
|
1081 PyErr_Format(PyExc_TypeError, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1082 "sequence type expected, got '%s'", |
|
78697
ca54c27a9045
Fix typo in error handling for WaitForMultipleObjects()
Richard Oudkerk <shibturn@gmail.com>
parents:
76771
diff
changeset
|
1083 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
|
1084 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1085 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1086 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
|
1087 if (nhandles == -1) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1088 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1089 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
|
1090 PyErr_Format(PyExc_ValueError, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1091 "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
|
1092 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
|
1093 return NULL; |
|
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 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
|
1096 HANDLE h; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1097 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
|
1098 if (v == NULL) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1099 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1100 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
|
1101 Py_DECREF(v); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1102 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1103 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1104 handles[i] = h; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1105 Py_DECREF(v); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1106 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1107 /* 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
|
1108 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
|
1109 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
|
1110 sigint_event = _PyOS_SigintEvent(); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1111 assert(sigint_event != NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1112 handles[nhandles++] = sigint_event; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1113 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1114 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1115 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1116 if (sigint_event != NULL) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1117 ResetEvent(sigint_event); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1118 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
|
1119 wait_flag, milliseconds); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1120 Py_END_ALLOW_THREADS |
|
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 if (result == WAIT_FAILED) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1123 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
|
1124 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
|
1125 errno = EINTR; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1126 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
|
1127 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1128 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1129 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
|
1130 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1131 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1132 PyDoc_STRVAR(WaitForSingleObject_doc, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1133 "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
|
1134 \n\ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1135 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
|
1136 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
|
1137 in milliseconds."); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1138 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1139 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1140 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
|
1141 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1142 DWORD result; |
|
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 DWORD milliseconds; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1146 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
|
1147 &handle, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1148 &milliseconds)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1149 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1150 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1151 Py_BEGIN_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1152 result = WaitForSingleObject(handle, milliseconds); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1153 Py_END_ALLOW_THREADS |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1154 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1155 if (result == WAIT_FAILED) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1156 return PyErr_SetFromWindowsErr(GetLastError()); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1157 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1158 return PyLong_FromUnsignedLong(result); |
|
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 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1161 static PyObject * |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1162 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
|
1163 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1164 HANDLE handle; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1165 Py_buffer _buf, *buf; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1166 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
|
1167 DWORD len, written; |
|
76405
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1168 BOOL ret; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1169 int use_overlapped = 0; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1170 DWORD err; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1171 OverlappedObject *overlapped = NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1172 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
|
1173 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1174 /* 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
|
1175 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
|
1176 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
|
1177 &handle, &bufobj, &use_overlapped)) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1178 return NULL; |
|
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 if (use_overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1181 overlapped = new_overlapped(handle); |
|
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 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1184 buf = &overlapped->write_buffer; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1185 } |
|
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 buf = &_buf; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1188 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1189 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
|
1190 Py_XDECREF(overlapped); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1191 return NULL; |
|
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 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
|
1195 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
|
1196 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
|
1197 overlapped ? &overlapped->overlapped : NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1198 Py_END_ALLOW_THREADS |
|
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 err = ret ? 0 : GetLastError(); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1201 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1202 if (overlapped) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1203 if (!ret) { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1204 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
|
1205 overlapped->pending = 1; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1206 else { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1207 Py_DECREF(overlapped); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1208 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
|
1209 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1210 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1211 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
|
1212 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1213 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1214 PyBuffer_Release(buf); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1215 if (!ret) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1216 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
|
1217 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
|
1218 } |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1219 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1220 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1221 static PyMethodDef winapi_functions[] = { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1222 {"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
|
1223 CloseHandle_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1224 {"ConnectNamedPipe", (PyCFunction)winapi_ConnectNamedPipe, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1225 METH_VARARGS | METH_KEYWORDS, ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1226 {"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
|
1227 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1228 {"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
|
1229 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1230 {"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
|
1231 CreatePipe_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1232 {"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
|
1233 CreateProcess_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1234 {"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
|
1235 DuplicateHandle_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1236 {"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
|
1237 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1238 {"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
|
1239 GetCurrentProcess_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1240 {"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
|
1241 GetExitCodeProcess_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1242 {"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
|
1243 GetCurrentProcess_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1244 {"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
|
1245 GetModuleFileName_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1246 {"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
|
1247 GetStdHandle_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1248 {"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
|
1249 GetVersion_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1250 {"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
|
1251 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1252 {"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
|
1253 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1254 {"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
|
1255 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1256 {"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
|
1257 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1258 {"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
|
1259 TerminateProcess_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1260 {"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
|
1261 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1262 {"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
|
1263 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1264 {"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
|
1265 WaitForSingleObject_doc}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1266 {"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
|
1267 ""}, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1268 {NULL, NULL} |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1269 }; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1270 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1271 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
|
1272 PyModuleDef_HEAD_INIT, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1273 "_winapi", |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1274 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1275 -1, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1276 winapi_functions, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1277 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1278 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1279 NULL, |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1280 NULL |
|
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 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1283 #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
|
1284 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
|
1285 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1286 PyMODINIT_FUNC |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1287 PyInit__winapi(void) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1288 { |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1289 PyObject *d; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1290 PyObject *m; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1291 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1292 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
|
1293 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1294 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1295 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
|
1296 if (m == NULL) |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1297 return NULL; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1298 d = PyModule_GetDict(m); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1299 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1300 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
|
1301 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1302 /* constants */ |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1303 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
|
1304 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
|
1305 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
|
1306 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
|
1307 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
|
1308 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
|
1309 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
|
1310 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
|
1311 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
|
1312 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
|
1313 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
|
1314 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
|
1315 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
|
1316 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
|
1317 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
|
1318 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
|
1319 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
|
1320 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
|
1321 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
|
1322 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
|
1323 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
|
1324 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
|
1325 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
|
1326 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
|
1327 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
|
1328 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
|
1329 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
|
1330 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
|
1331 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
|
1332 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
|
1333 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
|
1334 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
|
1335 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
|
1336 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
|
1337 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
|
1338 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
|
1339 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
|
1340 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
|
1341 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
|
1342 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
|
1343 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
|
1344 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
|
1345 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
|
1346 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
|
1347 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1348 WINAPI_CONSTANT("i", NULL); |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1349 |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1350 return m; |
|
f3a27d11101a
Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1351 } |
