annotate Modules/_winapi.c @ 84007:dbfbdf2b5c19 3.3

Fix #17967: For ftp urls CWD to target instead of hopping to each directory towards target. This fixes a bug where target is accessible, but parent directories are restricted.
author Senthil Kumaran <senthil@uthcode.com>
date Sat, 01 Jun 2013 08:27:06 -0700
parents ca54c27a9045
children 61227b4c169f c75ab7b802df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
65 /* 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
66 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
67 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
68
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
69 static int
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
70 check_CancelIoEx()
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
71 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
72 if (has_CancelIoEx == -1)
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 HINSTANCE hKernel32 = GetModuleHandle("KERNEL32");
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
75 * (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
76 "CancelIoEx");
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
77 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
78 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
79 return has_CancelIoEx;
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
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 * 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
85 * for overlapped I/O
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
86 */
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
87
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
88 typedef struct {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
89 PyObject_HEAD
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
90 OVERLAPPED overlapped;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
91 /* 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
92 HANDLE handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
93 /* 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
94 int pending;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
95 /* 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
96 int completed;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
97 /* 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
98 PyObject *read_buffer;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
99 /* 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
100 Py_buffer write_buffer;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
101 } OverlappedObject;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
102
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
103 static void
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
104 overlapped_dealloc(OverlappedObject *self)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
105 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
106 DWORD bytes;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
107 int err = GetLastError();
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
108 if (self->pending) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
109 /* make it a programming error to deallocate while operation
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
110 is pending, even if we can safely cancel it */
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
111 if (check_CancelIoEx() &&
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
112 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
113 GetOverlappedResult(self->handle, &self->overlapped, &bytes, TRUE);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
114 PyErr_SetString(PyExc_RuntimeError,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
115 "I/O operations still in flight while destroying "
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
116 "Overlapped object, the process may crash");
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
117 PyErr_WriteUnraisable(NULL);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
118 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
119 CloseHandle(self->overlapped.hEvent);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
120 SetLastError(err);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
121 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
122 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
123 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
124 PyObject_Del(self);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
125 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
126
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
127 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
128 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
129 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
130 int wait;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
131 BOOL res;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
132 DWORD transferred = 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
133 DWORD err;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
134
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
135 wait = PyObject_IsTrue(waitobj);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
136 if (wait < 0)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
137 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
138 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
139 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
140 wait != 0);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
141 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
142
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
143 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
144 switch (err) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
145 case ERROR_SUCCESS:
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
146 case ERROR_MORE_DATA:
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
147 case ERROR_OPERATION_ABORTED:
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
148 self->completed = 1;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
149 self->pending = 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
150 break;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
151 case ERROR_IO_INCOMPLETE:
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
152 break;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
153 default:
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
154 self->pending = 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
155 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
156 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
157 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
158 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
159 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
160 _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
161 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
162 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
163 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
164 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
165
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
166 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
167 overlapped_getbuffer(OverlappedObject *self)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
168 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
169 PyObject *res;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
170 if (!self->completed) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
171 PyErr_SetString(PyExc_ValueError,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
172 "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
173 "signals the operation completed");
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
174 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
175 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
176 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
177 Py_INCREF(res);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
178 return res;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
179 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
180
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
181 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
182 overlapped_cancel(OverlappedObject *self)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
183 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
184 BOOL res = TRUE;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
185
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
186 if (self->pending) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
187 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
188 if (check_CancelIoEx())
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
189 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
190 else
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
191 res = CancelIo(self->handle);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
192 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
193 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
194
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
195 /* 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
196 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
197 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
198 self->pending = 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
199 Py_RETURN_NONE;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
200 }
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 static PyMethodDef overlapped_methods[] = {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
203 {"GetOverlappedResult", (PyCFunction) overlapped_GetOverlappedResult,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
204 METH_O, NULL},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
205 {"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
206 {"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
207 {NULL}
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
208 };
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
209
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
210 static PyMemberDef overlapped_members[] = {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
211 {"event", T_HANDLE,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
212 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
213 READONLY, "overlapped event handle"},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
214 {NULL}
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 PyTypeObject OverlappedType = {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
218 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
219 /* tp_name */ "_winapi.Overlapped",
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
220 /* tp_basicsize */ sizeof(OverlappedObject),
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
221 /* tp_itemsize */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
222 /* 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
223 /* tp_print */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
224 /* tp_getattr */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
225 /* tp_setattr */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
226 /* tp_reserved */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
227 /* tp_repr */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
228 /* tp_as_number */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
229 /* tp_as_sequence */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
230 /* tp_as_mapping */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
231 /* tp_hash */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
232 /* tp_call */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
233 /* tp_str */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
234 /* tp_getattro */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
235 /* tp_setattro */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
236 /* tp_as_buffer */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
237 /* 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
238 /* 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
239 /* tp_traverse */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
240 /* tp_clear */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
241 /* tp_richcompare */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
242 /* tp_weaklistoffset */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
243 /* tp_iter */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
244 /* tp_iternext */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
245 /* tp_methods */ overlapped_methods,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
246 /* tp_members */ overlapped_members,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
247 /* tp_getset */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
248 /* tp_base */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
249 /* tp_dict */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
250 /* tp_descr_get */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
251 /* tp_descr_set */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
252 /* tp_dictoffset */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
253 /* tp_init */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
254 /* tp_alloc */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
255 /* tp_new */ 0,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
256 };
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
257
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
258 static OverlappedObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
259 new_overlapped(HANDLE handle)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
260 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
261 OverlappedObject *self;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
262
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
263 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
264 if (!self)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
265 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
266 self->handle = handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
267 self->read_buffer = NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
268 self->pending = 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
269 self->completed = 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
270 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
271 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
272 /* 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
273 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
274 return self;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
275 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
276
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
277 /* -------------------------------------------------------------------- */
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
278 /* windows API functions */
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 PyDoc_STRVAR(CloseHandle_doc,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
281 "CloseHandle(handle) -> None\n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
282 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
283 Close handle.");
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 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
286 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
287 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
288 HANDLE hObject;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
289 BOOL success;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
290
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
291 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
292 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
293
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
294 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
295 success = CloseHandle(hObject);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
296 Py_END_ALLOW_THREADS
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 if (!success)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
299 return PyErr_SetFromWindowsErr(0);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
300
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
301 Py_RETURN_NONE;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
302 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
303
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
304 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
305 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
306 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
307 HANDLE hNamedPipe;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
308 int use_overlapped = 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
309 BOOL success;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
310 OverlappedObject *overlapped = NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
311 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
312
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
313 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
314 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
315 &hNamedPipe, &use_overlapped))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
316 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
317
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
318 if (use_overlapped) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
319 overlapped = new_overlapped(hNamedPipe);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
320 if (!overlapped)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
321 return NULL;
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
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
324 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
325 success = ConnectNamedPipe(hNamedPipe,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
326 overlapped ? &overlapped->overlapped : NULL);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
327 Py_END_ALLOW_THREADS
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 if (overlapped) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
330 int err = GetLastError();
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
331 /* 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
332 assert(success == 0);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
333 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
334 overlapped->pending = 1;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
335 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
336 SetEvent(overlapped->overlapped.hEvent);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
337 else {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
338 Py_DECREF(overlapped);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
339 return PyErr_SetFromWindowsErr(err);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
340 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
341 return (PyObject *) overlapped;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
342 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
343 if (!success)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
344 return PyErr_SetFromWindowsErr(0);
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_RETURN_NONE;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
347 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
348
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
349 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
350 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
351 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
352 LPCTSTR lpFileName;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
353 DWORD dwDesiredAccess;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
354 DWORD dwShareMode;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
355 LPSECURITY_ATTRIBUTES lpSecurityAttributes;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
356 DWORD dwCreationDisposition;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
357 DWORD dwFlagsAndAttributes;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
358 HANDLE hTemplateFile;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
359 HANDLE handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
360
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
361 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
362 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
363 &lpFileName, &dwDesiredAccess, &dwShareMode,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
364 &lpSecurityAttributes, &dwCreationDisposition,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
365 &dwFlagsAndAttributes, &hTemplateFile))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
366 return NULL;
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_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
369 handle = CreateFile(lpFileName, dwDesiredAccess,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
370 dwShareMode, lpSecurityAttributes,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
371 dwCreationDisposition,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
372 dwFlagsAndAttributes, hTemplateFile);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
373 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
374
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
375 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
376 return PyErr_SetFromWindowsErr(0);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
377
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
378 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
379 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
380
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
381 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
382 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
383 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
384 LPCTSTR lpName;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
385 DWORD dwOpenMode;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
386 DWORD dwPipeMode;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
387 DWORD nMaxInstances;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
388 DWORD nOutBufferSize;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
389 DWORD nInBufferSize;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
390 DWORD nDefaultTimeOut;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
391 LPSECURITY_ATTRIBUTES lpSecurityAttributes;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
392 HANDLE handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
393
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
394 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
395 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
396 &lpName, &dwOpenMode, &dwPipeMode,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
397 &nMaxInstances, &nOutBufferSize,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
398 &nInBufferSize, &nDefaultTimeOut,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
399 &lpSecurityAttributes))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
400 return NULL;
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 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
403 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
404 nMaxInstances, nOutBufferSize,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
405 nInBufferSize, nDefaultTimeOut,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
406 lpSecurityAttributes);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
407 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
408
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
409 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
410 return PyErr_SetFromWindowsErr(0);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
411
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
412 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
413 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
414
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
415 PyDoc_STRVAR(CreatePipe_doc,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
416 "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
417 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
418 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
419 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
420 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
421 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
422
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
423 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
424 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
425 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
426 HANDLE read_pipe;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
427 HANDLE write_pipe;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
428 BOOL result;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
429
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
430 PyObject* pipe_attributes; /* ignored */
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
431 DWORD size;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
432
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
433 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
434 &pipe_attributes, &size))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
435 return NULL;
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 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
438 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
439 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
440
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
441 if (! result)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
442 return PyErr_SetFromWindowsErr(GetLastError());
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
443
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
444 return Py_BuildValue(
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
445 "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
446 }
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 /* helpers for createprocess */
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
449
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
450 static unsigned long
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
451 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
452 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
453 PyObject* value;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
454 unsigned long ret;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
455
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
456 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
457 if (! value) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
458 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
459 return 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
460 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
461 ret = PyLong_AsUnsignedLong(value);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
462 Py_DECREF(value);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
463 return ret;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
464 }
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 static HANDLE
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
467 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
468 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
469 PyObject* value;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
470 HANDLE ret;
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 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
473 if (! value) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
474 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
475 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
476 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
477 if (value == Py_None)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
478 ret = NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
479 else
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
480 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
481 Py_DECREF(value);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
482 return ret;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
483 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
484
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
485 static PyObject*
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
486 getenvironment(PyObject* environment)
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 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
489 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
490 PyObject *keys, *values, *res;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
491
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
492 /* convert environment dictionary to windows enviroment string */
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
493 if (! PyMapping_Check(environment)) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
494 PyErr_SetString(
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
495 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
496 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
497 }
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 envsize = PyMapping_Length(environment);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
500
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
501 keys = PyMapping_Keys(environment);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
502 values = PyMapping_Values(environment);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
503 if (!keys || !values)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
504 goto error;
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 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
507 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
508 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
509 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
510
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
511 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
512 PyErr_SetString(PyExc_TypeError,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
513 "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
514 goto error;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
515 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
516 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
517 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
518 }
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 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
521 if (! buffer)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
522 goto error;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
523 p = buffer;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
524 end = buffer + totalsize;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
525
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
526 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
527 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
528 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
529 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
530 goto error;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
531 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
532 *p++ = '=';
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
533 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
534 goto error;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
535 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
536 *p++ = '\0';
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
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
539 /* add trailing null byte */
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
540 *p++ = '\0';
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
541 assert(p == end);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
542
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
543 Py_XDECREF(keys);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
544 Py_XDECREF(values);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
545
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
546 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
547 PyMem_Free(buffer);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
548 return res;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
549
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
550 error:
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
551 PyMem_Free(buffer);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
552 Py_XDECREF(keys);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
553 Py_XDECREF(values);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
554 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
555 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
556
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
557 PyDoc_STRVAR(CreateProcess_doc,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
558 "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
559 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
560 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
561 pid, tid)\n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
562 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
563 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
564 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
565 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
566 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
567 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
568
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
569 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
570 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
571 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
572 BOOL result;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
573 PROCESS_INFORMATION pi;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
574 STARTUPINFOW si;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
575 PyObject* environment;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
576 wchar_t *wenvironment;
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 wchar_t* application_name;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
579 wchar_t* command_line;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
580 PyObject* process_attributes; /* ignored */
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
581 PyObject* thread_attributes; /* ignored */
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
582 BOOL inherit_handles;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
583 DWORD creation_flags;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
584 PyObject* env_mapping;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
585 wchar_t* current_directory;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
586 PyObject* startup_info;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
587
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
588 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
589 &application_name,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
590 &command_line,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
591 &process_attributes,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
592 &thread_attributes,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
593 &inherit_handles,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
594 &creation_flags,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
595 &env_mapping,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
596 &current_directory,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
597 &startup_info))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
598 return NULL;
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 ZeroMemory(&si, sizeof(si));
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
601 si.cb = sizeof(si);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
602
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
603 /* 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
604 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
605 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
606 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
607 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
608 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
609 if (PyErr_Occurred())
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
610 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
611
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
612 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
613 environment = getenvironment(env_mapping);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
614 if (! environment)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
615 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
616 wenvironment = PyUnicode_AsUnicode(environment);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
617 if (wenvironment == NULL)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
618 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
619 Py_XDECREF(environment);
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 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
623 else {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
624 environment = NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
625 wenvironment = NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
626 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
627
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
628 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
629 result = CreateProcessW(application_name,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
630 command_line,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
631 NULL,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
632 NULL,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
633 inherit_handles,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
634 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
635 wenvironment,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
636 current_directory,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
637 &si,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
638 &pi);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
639 Py_END_ALLOW_THREADS
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
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
643 if (! result)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
644 return PyErr_SetFromWindowsErr(GetLastError());
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
645
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
646 return Py_BuildValue("NNkk",
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
647 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
648 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
649 pi.dwProcessId,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
650 pi.dwThreadId);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
651 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
652
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
653 PyDoc_STRVAR(DuplicateHandle_doc,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
654 "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
655 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
656 inherit[, options]) -> handle\n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
657 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
658 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
659 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
660 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
661 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
662 through both handles.");
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
663
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
664 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
665 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
666 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
667 HANDLE target_handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
668 BOOL result;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
669
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
670 HANDLE source_process_handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
671 HANDLE source_handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
672 HANDLE target_process_handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
673 DWORD desired_access;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
674 BOOL inherit_handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
675 DWORD options = 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
676
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
677 if (! PyArg_ParseTuple(args,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
678 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
679 ":DuplicateHandle",
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
680 &source_process_handle,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
681 &source_handle,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
682 &target_process_handle,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
683 &desired_access,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
684 &inherit_handle,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
685 &options))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
686 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
687
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
688 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
689 result = DuplicateHandle(
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
690 source_process_handle,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
691 source_handle,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
692 target_process_handle,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
693 &target_handle,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
694 desired_access,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
695 inherit_handle,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
696 options
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
697 );
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
698 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
699
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
700 if (! result)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
701 return PyErr_SetFromWindowsErr(GetLastError());
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
702
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
703 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
704 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
705
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
706 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
707 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
708 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
709 UINT uExitCode;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
710
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
711 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
712 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
713
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
714 #if defined(Py_DEBUG)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
715 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
716 SEM_NOGPFAULTERRORBOX|SEM_NOOPENFILEERRORBOX);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
717 _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
718 #endif
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 ExitProcess(uExitCode);
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 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
723 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
724
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
725 PyDoc_STRVAR(GetCurrentProcess_doc,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
726 "GetCurrentProcess() -> handle\n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
727 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
728 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
729
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
730 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
731 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
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, ":GetCurrentProcess"))
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 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
737 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
738
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
739 PyDoc_STRVAR(GetExitCodeProcess_doc,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
740 "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
741 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
742 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
743
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
744 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
745 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
746 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
747 DWORD exit_code;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
748 BOOL result;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
749
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
750 HANDLE process;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
751 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
752 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
753
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
754 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
755
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
756 if (! result)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
757 return PyErr_SetFromWindowsErr(GetLastError());
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
758
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
759 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
760 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
761
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
762 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
763 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
764 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
765 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
766 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
767
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
768 PyDoc_STRVAR(GetModuleFileName_doc,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
769 "GetModuleFileName(module) -> path\n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
770 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
771 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
772 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
773 current process.\n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
774 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
775 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
776 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
777 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
778 of the current process.");
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
779
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
780 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
781 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
782 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
783 BOOL result;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
784 HMODULE module;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
785 WCHAR filename[MAX_PATH];
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 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
788 &module))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
789 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
790
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
791 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
792 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
793
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
794 if (! result)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
795 return PyErr_SetFromWindowsErr(GetLastError());
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
796
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
797 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
798 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
799
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
800 PyDoc_STRVAR(GetStdHandle_doc,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
801 "GetStdHandle(handle) -> integer\n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
802 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
803 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
804 (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
805 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
806
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
807 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
808 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
809 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
810 HANDLE handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
811 DWORD std_handle;
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 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
814 return NULL;
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 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
817 handle = GetStdHandle(std_handle);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
818 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
819
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
820 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
821 return PyErr_SetFromWindowsErr(GetLastError());
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
822
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
823 if (! handle) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
824 Py_INCREF(Py_None);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
825 return Py_None;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
826 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
827
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
828 /* 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
829 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
830 }
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 PyDoc_STRVAR(GetVersion_doc,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
833 "GetVersion() -> version\n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
834 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
835 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
836
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
837 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
838 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
839 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
840 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
841 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
842
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
843 return PyLong_FromUnsignedLong(GetVersion());
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
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
846 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
847 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
848 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
849 DWORD dwDesiredAccess;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
850 BOOL bInheritHandle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
851 DWORD dwProcessId;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
852 HANDLE handle;
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 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
855 &dwDesiredAccess, &bInheritHandle, &dwProcessId))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
856 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
857
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
858 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
859 if (handle == NULL)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
860 return PyErr_SetFromWindowsErr(0);
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 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
863 }
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 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
866 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
867 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
868 HANDLE handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
869 int size = 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
870 PyObject *buf = NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
871 DWORD nread, navail, nleft;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
872 BOOL ret;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
873
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
874 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
875 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
876
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
877 if (size < 0) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
878 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
879 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
880 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
881
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
882 if (size) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
883 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
884 if (!buf)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
885 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
886 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
887 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
888 &navail, &nleft);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
889 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
890 if (!ret) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
891 Py_DECREF(buf);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
892 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
893 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
894 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
895 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
896 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
897 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
898 else {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
899 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
900 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
901 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
902 if (!ret) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
903 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
904 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
905 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
906 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
907 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
908
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
909 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
910 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
911 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
912 HANDLE handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
913 int size;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
914 DWORD nread;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
915 PyObject *buf;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
916 BOOL ret;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
917 int use_overlapped = 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
918 DWORD err;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
919 OverlappedObject *overlapped = NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
920 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
921
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
922 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
923 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
924 &handle, &size, &use_overlapped))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
925 return NULL;
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 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
928 if (!buf)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
929 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
930 if (use_overlapped) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
931 overlapped = new_overlapped(handle);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
932 if (!overlapped) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
933 Py_DECREF(buf);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
934 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
935 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
936 /* Steals reference to buf */
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
937 overlapped->read_buffer = buf;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
938 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
939
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
940 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
941 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
942 overlapped ? &overlapped->overlapped : NULL);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
943 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
944
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
945 err = ret ? 0 : GetLastError();
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
946
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
947 if (overlapped) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
948 if (!ret) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
949 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
950 overlapped->pending = 1;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
951 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
952 Py_DECREF(overlapped);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
953 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
954 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
955 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
956 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
957 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
958
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
959 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
960 Py_DECREF(buf);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
961 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
962 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
963 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
964 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
965 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
966 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
967
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
968 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
969 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
970 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
971 HANDLE hNamedPipe;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
972 PyObject *oArgs[3];
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
973 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
974 int i;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
975
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
976 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
977 &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
978 return NULL;
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 PyErr_Clear();
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
981
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
982 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
983 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
984 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
985 if (PyErr_Occurred())
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 pArgs[i] = &dwArgs[i];
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
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
991 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
992 return PyErr_SetFromWindowsErr(0);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
993
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
994 Py_RETURN_NONE;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
995 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
996
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
997 PyDoc_STRVAR(TerminateProcess_doc,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
998 "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
999 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1000 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
1001
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1002 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1003 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
1004 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1005 BOOL result;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1006
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1007 HANDLE process;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1008 UINT exit_code;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1009 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
1010 &process, &exit_code))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1011 return NULL;
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 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
1014
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1015 if (! result)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1016 return PyErr_SetFromWindowsErr(GetLastError());
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 Py_INCREF(Py_None);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1019 return Py_None;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1020 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1021
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1022 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1023 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
1024 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1025 LPCTSTR lpNamedPipeName;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1026 DWORD nTimeOut;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1027 BOOL success;
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 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
1030 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1031
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1032 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1033 success = WaitNamedPipe(lpNamedPipeName, nTimeOut);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1034 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1035
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1036 if (!success)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1037 return PyErr_SetFromWindowsErr(0);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1038
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1039 Py_RETURN_NONE;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1040 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1041
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1042 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1043 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
1044 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1045 DWORD result;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1046 PyObject *handle_seq;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1047 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
1048 HANDLE sigint_event = NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1049 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
1050 BOOL wait_flag;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1051 DWORD milliseconds = INFINITE;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1052
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1053 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
1054 ":WaitForMultipleObjects",
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1055 &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
1056 return NULL;
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 (!PySequence_Check(handle_seq)) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1059 PyErr_Format(PyExc_TypeError,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1060 "sequence type expected, got '%s'",
78697
ca54c27a9045 Fix typo in error handling for WaitForMultipleObjects()
Richard Oudkerk <shibturn@gmail.com>
parents: 76771
diff changeset
1061 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
1062 return NULL;
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 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
1065 if (nhandles == -1)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1066 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1067 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
1068 PyErr_Format(PyExc_ValueError,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1069 "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
1070 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
1071 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1072 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1073 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
1074 HANDLE h;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1075 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
1076 if (v == NULL)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1077 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1078 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
1079 Py_DECREF(v);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1080 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1081 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1082 handles[i] = h;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1083 Py_DECREF(v);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1084 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1085 /* 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
1086 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
1087 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
1088 sigint_event = _PyOS_SigintEvent();
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1089 assert(sigint_event != NULL);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1090 handles[nhandles++] = sigint_event;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1091 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1092
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1093 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1094 if (sigint_event != NULL)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1095 ResetEvent(sigint_event);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1096 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
1097 wait_flag, milliseconds);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1098 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1099
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1100 if (result == WAIT_FAILED)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1101 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
1102 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
1103 errno = EINTR;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1104 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
1105 }
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 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
1108 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1109
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1110 PyDoc_STRVAR(WaitForSingleObject_doc,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1111 "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
1112 \n\
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1113 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
1114 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
1115 in milliseconds.");
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1116
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1117 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1118 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
1119 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1120 DWORD result;
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 HANDLE handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1123 DWORD milliseconds;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1124 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
1125 &handle,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1126 &milliseconds))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1127 return NULL;
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 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1130 result = WaitForSingleObject(handle, milliseconds);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1131 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1132
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1133 if (result == WAIT_FAILED)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1134 return PyErr_SetFromWindowsErr(GetLastError());
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1135
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1136 return PyLong_FromUnsignedLong(result);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1137 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1138
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_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
1141 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1142 HANDLE handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1143 Py_buffer _buf, *buf;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1144 PyObject *bufobj;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1145 DWORD written;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1146 BOOL ret;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1147 int use_overlapped = 0;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1148 DWORD err;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1149 OverlappedObject *overlapped = NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1150 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
1151
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1152 /* 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
1153 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
1154 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
1155 &handle, &bufobj, &use_overlapped))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1156 return NULL;
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 if (use_overlapped) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1159 overlapped = new_overlapped(handle);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1160 if (!overlapped)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1161 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1162 buf = &overlapped->write_buffer;
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 else
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1165 buf = &_buf;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1166
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1167 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
1168 Py_XDECREF(overlapped);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1169 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1170 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1171
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1172 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1173 ret = WriteFile(handle, buf->buf, buf->len, &written,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1174 overlapped ? &overlapped->overlapped : NULL);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1175 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1176
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1177 err = ret ? 0 : GetLastError();
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1178
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1179 if (overlapped) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1180 if (!ret) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1181 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
1182 overlapped->pending = 1;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1183 else {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1184 Py_DECREF(overlapped);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1185 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
1186 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1187 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1188 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
1189 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1190
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1191 PyBuffer_Release(buf);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1192 if (!ret)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1193 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
1194 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
1195 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1196
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1197
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1198 static PyMethodDef winapi_functions[] = {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1199 {"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
1200 CloseHandle_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1201 {"ConnectNamedPipe", (PyCFunction)winapi_ConnectNamedPipe,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1202 METH_VARARGS | METH_KEYWORDS, ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1203 {"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
1204 ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1205 {"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
1206 ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1207 {"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
1208 CreatePipe_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1209 {"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
1210 CreateProcess_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1211 {"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
1212 DuplicateHandle_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1213 {"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
1214 ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1215 {"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
1216 GetCurrentProcess_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1217 {"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
1218 GetExitCodeProcess_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1219 {"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
1220 GetCurrentProcess_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1221 {"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
1222 GetModuleFileName_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1223 {"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
1224 GetStdHandle_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1225 {"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
1226 GetVersion_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1227 {"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
1228 ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1229 {"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
1230 ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1231 {"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
1232 ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1233 {"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
1234 ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1235 {"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
1236 TerminateProcess_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1237 {"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
1238 ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1239 {"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
1240 ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1241 {"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
1242 WaitForSingleObject_doc},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1243 {"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
1244 ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1245 {NULL, NULL}
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1246 };
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1247
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1248 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
1249 PyModuleDef_HEAD_INIT,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1250 "_winapi",
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1251 NULL,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1252 -1,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1253 winapi_functions,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1254 NULL,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1255 NULL,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1256 NULL,
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1257 NULL
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1258 };
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1259
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1260 #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
1261 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
1262
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1263 PyMODINIT_FUNC
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1264 PyInit__winapi(void)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1265 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1266 PyObject *d;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1267 PyObject *m;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1268
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1269 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
1270 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1271
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1272 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
1273 if (m == NULL)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1274 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1275 d = PyModule_GetDict(m);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1276
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1277 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
1278
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1279 /* constants */
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1280 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
1281 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
1282 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
1283 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
1284 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
1285 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
1286 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
1287 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
1288 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
1289 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
1290 WINAPI_CONSTANT(F_DWORD, ERROR_MORE_DATA);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1291 WINAPI_CONSTANT(F_DWORD, ERROR_NETNAME_DELETED);
76771
44f078ea05f3 Fix for Issue 14725 for 3.3 branch.
Richard Oudkerk <shibturn@gmail.com>
parents: 76541
diff changeset
1292 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
1293 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
1294 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
1295 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
1296 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
1297 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
1298 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
1299 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
1300 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
1301 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
1302 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
1303 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
1304 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
1305 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
1306 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
1307 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
1308 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
1309 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
1310 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
1311 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
1312 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
1313 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
1314 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
1315 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
1316 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
1317 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
1318 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
1319 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
1320 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
1321 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
1322 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
1323 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
1324
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1325 WINAPI_CONSTANT("i", NULL);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1326
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1327 return m;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1328 }