Mercurial > cpython-lru_cache-weakref
annotate PC/_subprocess.c @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 7111845c2f5e |
| children | 2a768ea06023 0ab89e8bdedc |
| rev | line source |
|---|---|
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1 /* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2 * support routines for subprocess module |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3 * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
4 * Currently, this extension module is only required when using the |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
5 * subprocess module on Windows, but in the future, stubs for other |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
6 * platforms might be added here as well. |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
7 * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
8 * Copyright (c) 2004 by Fredrik Lundh <fredrik@pythonware.com> |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
9 * Copyright (c) 2004 by Secret Labs AB, http://www.pythonware.com |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
10 * Copyright (c) 2004 by Peter Astrand <astrand@lysator.liu.se> |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
11 * |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
12 * By obtaining, using, and/or copying this software and/or its |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
13 * associated documentation, you agree that you have read, understood, |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
14 * and will comply with the following terms and conditions: |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
15 * |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
16 * Permission to use, copy, modify, and distribute this software and |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
17 * its associated documentation for any purpose and without fee is |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
18 * hereby granted, provided that the above copyright notice appears in |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
19 * all copies, and that both that copyright notice and this permission |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
20 * notice appear in supporting documentation, and that the name of the |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
21 * authors not be used in advertising or publicity pertaining to |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
22 * distribution of the software without specific, written prior |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
23 * permission. |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
24 * |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
25 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
26 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
27 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
28 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
29 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
30 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
31 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
32 * |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
33 */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
34 |
|
36030
f0a5330f2b3e
added PSF licensing blurbs to relevant files
Fredrik Lundh <fredrik@pythonware.com>
parents:
35856
diff
changeset
|
35 /* Licensed to PSF under a Contributor Agreement. */ |
|
f0a5330f2b3e
added PSF licensing blurbs to relevant files
Fredrik Lundh <fredrik@pythonware.com>
parents:
35856
diff
changeset
|
36 /* See http://www.python.org/2.4/license for licensing details. */ |
|
f0a5330f2b3e
added PSF licensing blurbs to relevant files
Fredrik Lundh <fredrik@pythonware.com>
parents:
35856
diff
changeset
|
37 |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
38 /* TODO: handle unicode command lines? */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
39 /* TODO: handle unicode environment? */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
40 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
41 #include "Python.h" |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
42 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
43 #define WINDOWS_LEAN_AND_MEAN |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
44 #include "windows.h" |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
45 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
46 /* -------------------------------------------------------------------- */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
47 /* handle wrapper. note that this library uses integers when passing |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
48 handles to a function, and handle wrappers when returning handles. |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
49 the wrapper is used to provide Detach and Close methods */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
50 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
51 typedef struct { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
52 PyObject_HEAD |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
53 HANDLE handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
54 } sp_handle_object; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
55 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
56 staticforward PyTypeObject sp_handle_type; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
57 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
58 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
59 sp_handle_new(HANDLE handle) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
60 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
61 sp_handle_object* self; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
62 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
63 self = PyObject_NEW(sp_handle_object, &sp_handle_type); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
64 if (self == NULL) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
65 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
66 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
67 self->handle = handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
68 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
69 return (PyObject*) self; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
70 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
71 |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
72 #if defined(MS_WIN32) && !defined(MS_WIN64) |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
73 #define HANDLE_TO_PYNUM(handle) PyInt_FromLong((long) handle) |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
74 #define PY_HANDLE_PARAM "l" |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
75 #else |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
76 #define HANDLE_TO_PYNUM(handle) PyLong_FromLongLong((long long) handle) |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
77 #define PY_HANDLE_PARAM "L" |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
78 #endif |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
79 |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
80 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
81 sp_handle_detach(sp_handle_object* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
82 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
83 HANDLE handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
84 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
85 if (! PyArg_ParseTuple(args, ":Detach")) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
86 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
87 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
88 handle = self->handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
89 |
|
51986
7111845c2f5e
Merged revisions 70137 via svnmerge from
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
48034
diff
changeset
|
90 self->handle = INVALID_HANDLE_VALUE; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
91 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
92 /* note: return the current handle, as an integer */ |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
93 return HANDLE_TO_PYNUM(handle); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
94 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
95 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
96 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
97 sp_handle_close(sp_handle_object* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
98 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
99 if (! PyArg_ParseTuple(args, ":Close")) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
100 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
101 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
102 if (self->handle != INVALID_HANDLE_VALUE) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
103 CloseHandle(self->handle); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
104 self->handle = INVALID_HANDLE_VALUE; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
105 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
106 Py_INCREF(Py_None); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
107 return Py_None; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
108 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
109 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
110 static void |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
111 sp_handle_dealloc(sp_handle_object* self) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
112 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
113 if (self->handle != INVALID_HANDLE_VALUE) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
114 CloseHandle(self->handle); |
| 37229 | 115 PyObject_FREE(self); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
116 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
117 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
118 static PyMethodDef sp_handle_methods[] = { |
|
38490
a5298f371be7
Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents:
37229
diff
changeset
|
119 {"Detach", (PyCFunction) sp_handle_detach, METH_VARARGS}, |
|
a5298f371be7
Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents:
37229
diff
changeset
|
120 {"Close", (PyCFunction) sp_handle_close, METH_VARARGS}, |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
121 {NULL, NULL} |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
122 }; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
123 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
124 static PyObject* |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
125 sp_handle_getattr(sp_handle_object* self, char* name) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
126 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
127 return Py_FindMethod(sp_handle_methods, (PyObject*) self, name); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
128 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
129 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
130 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
131 sp_handle_as_int(sp_handle_object* self) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
132 { |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
133 return HANDLE_TO_PYNUM(self->handle); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
134 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
135 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
136 static PyNumberMethods sp_handle_as_number; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
137 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
138 statichere PyTypeObject sp_handle_type = { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
139 PyObject_HEAD_INIT(NULL) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
140 0, /*ob_size*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
141 "_subprocess_handle", sizeof(sp_handle_object), 0, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
142 (destructor) sp_handle_dealloc, /*tp_dealloc*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
143 0, /*tp_print*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
144 (getattrfunc) sp_handle_getattr,/*tp_getattr*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
145 0, /*tp_setattr*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
146 0, /*tp_compare*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
147 0, /*tp_repr*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
148 &sp_handle_as_number, /*tp_as_number */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
149 0, /*tp_as_sequence */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
150 0, /*tp_as_mapping */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
151 0 /*tp_hash*/ |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
152 }; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
153 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
154 /* -------------------------------------------------------------------- */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
155 /* windows API functions */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
156 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
157 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
158 sp_GetStdHandle(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
159 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
160 HANDLE handle; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
161 int std_handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
162 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
163 if (! PyArg_ParseTuple(args, "i:GetStdHandle", &std_handle)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
164 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
165 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
166 Py_BEGIN_ALLOW_THREADS |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
167 handle = GetStdHandle((DWORD) std_handle); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
168 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
169 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
170 if (handle == INVALID_HANDLE_VALUE) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
171 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
172 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
173 if (! handle) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
174 Py_INCREF(Py_None); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
175 return Py_None; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
176 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
177 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
178 /* note: returns integer, not handle object */ |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
179 return HANDLE_TO_PYNUM(handle); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
180 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
181 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
182 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
183 sp_GetCurrentProcess(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
184 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
185 if (! PyArg_ParseTuple(args, ":GetCurrentProcess")) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
186 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
187 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
188 return sp_handle_new(GetCurrentProcess()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
189 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
190 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
191 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
192 sp_DuplicateHandle(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
193 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
194 HANDLE target_handle; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
195 BOOL result; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
196 |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
197 HANDLE source_process_handle; |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
198 HANDLE source_handle; |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
199 HANDLE target_process_handle; |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
200 int desired_access; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
201 int inherit_handle; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
202 int options = 0; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
203 |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
204 if (! PyArg_ParseTuple(args, |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
205 PY_HANDLE_PARAM PY_HANDLE_PARAM PY_HANDLE_PARAM |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
206 "ii|i:DuplicateHandle", |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
207 &source_process_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
208 &source_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
209 &target_process_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
210 &desired_access, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
211 &inherit_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
212 &options)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
213 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
214 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
215 Py_BEGIN_ALLOW_THREADS |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
216 result = DuplicateHandle( |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
217 source_process_handle, |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
218 source_handle, |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
219 target_process_handle, |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
220 &target_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
221 desired_access, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
222 inherit_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
223 options |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
224 ); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
225 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
226 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
227 if (! result) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
228 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
229 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
230 return sp_handle_new(target_handle); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
231 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
232 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
233 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
234 sp_CreatePipe(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
235 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
236 HANDLE read_pipe; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
237 HANDLE write_pipe; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
238 BOOL result; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
239 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
240 PyObject* pipe_attributes; /* ignored */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
241 int size; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
242 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
243 if (! PyArg_ParseTuple(args, "Oi:CreatePipe", &pipe_attributes, &size)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
244 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
245 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
246 Py_BEGIN_ALLOW_THREADS |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
247 result = CreatePipe(&read_pipe, &write_pipe, NULL, size); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
248 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
249 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
250 if (! result) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
251 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
252 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
253 return Py_BuildValue( |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
254 "NN", sp_handle_new(read_pipe), sp_handle_new(write_pipe)); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
255 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
256 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
257 /* helpers for createprocess */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
258 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
259 static int |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
260 getint(PyObject* obj, char* name) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
261 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
262 PyObject* value; |
|
38589
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
263 int ret; |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
264 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
265 value = PyObject_GetAttrString(obj, name); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
266 if (! value) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
267 PyErr_Clear(); /* FIXME: propagate error? */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
268 return 0; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
269 } |
|
38589
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
270 ret = (int) PyInt_AsLong(value); |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
271 Py_DECREF(value); |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
272 return ret; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
273 } |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
274 |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
275 static HANDLE |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
276 gethandle(PyObject* obj, char* name) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
277 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
278 sp_handle_object* value; |
|
38589
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
279 HANDLE ret; |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
280 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
281 value = (sp_handle_object*) PyObject_GetAttrString(obj, name); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
282 if (! value) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
283 PyErr_Clear(); /* FIXME: propagate error? */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
284 return NULL; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
285 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
286 if (value->ob_type != &sp_handle_type) |
|
38589
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
287 ret = NULL; |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
288 else |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
289 ret = value->handle; |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
290 Py_DECREF(value); |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
291 return ret; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
292 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
293 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
294 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
295 getenvironment(PyObject* environment) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
296 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
297 int i, envsize; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
298 PyObject* out = NULL; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
299 PyObject* keys; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
300 PyObject* values; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
301 char* p; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
302 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
303 /* convert environment dictionary to windows enviroment string */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
304 if (! PyMapping_Check(environment)) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
305 PyErr_SetString( |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
306 PyExc_TypeError, "environment must be dictionary or None"); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
307 return NULL; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
308 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
309 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
310 envsize = PyMapping_Length(environment); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
311 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
312 keys = PyMapping_Keys(environment); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
313 values = PyMapping_Values(environment); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
314 if (!keys || !values) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
315 goto error; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
316 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
317 out = PyString_FromStringAndSize(NULL, 2048); |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
318 if (! out) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
319 goto error; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
320 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
321 p = PyString_AS_STRING(out); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
322 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
323 for (i = 0; i < envsize; i++) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
324 int ksize, vsize, totalsize; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
325 PyObject* key = PyList_GET_ITEM(keys, i); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
326 PyObject* value = PyList_GET_ITEM(values, i); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
327 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
328 if (! PyString_Check(key) || ! PyString_Check(value)) { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
329 PyErr_SetString(PyExc_TypeError, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
330 "environment can only contain strings"); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
331 goto error; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
332 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
333 ksize = PyString_GET_SIZE(key); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
334 vsize = PyString_GET_SIZE(value); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
335 totalsize = (p - PyString_AS_STRING(out)) + ksize + 1 + |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
336 vsize + 1 + 1; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
337 if (totalsize > PyString_GET_SIZE(out)) { |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
338 int offset = p - PyString_AS_STRING(out); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
339 _PyString_Resize(&out, totalsize + 1024); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
340 p = PyString_AS_STRING(out) + offset; |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
341 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
342 memcpy(p, PyString_AS_STRING(key), ksize); |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
343 p += ksize; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
344 *p++ = '='; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
345 memcpy(p, PyString_AS_STRING(value), vsize); |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
346 p += vsize; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
347 *p++ = '\0'; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
348 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
349 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
350 /* add trailing null byte */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
351 *p++ = '\0'; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
352 _PyString_Resize(&out, p - PyString_AS_STRING(out)); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
353 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
354 /* PyObject_Print(out, stdout, 0); */ |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
355 |
|
35855
429f537cf6d6
r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
33929
diff
changeset
|
356 Py_XDECREF(keys); |
|
429f537cf6d6
r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
33929
diff
changeset
|
357 Py_XDECREF(values); |
|
429f537cf6d6
r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
33929
diff
changeset
|
358 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
359 return out; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
360 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
361 error: |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
362 Py_XDECREF(out); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
363 Py_XDECREF(keys); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
364 Py_XDECREF(values); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
365 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
366 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
367 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
368 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
369 sp_CreateProcess(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
370 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
371 BOOL result; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
372 PROCESS_INFORMATION pi; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
373 STARTUPINFO si; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
374 PyObject* environment; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
375 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
376 char* application_name; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
377 char* command_line; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
378 PyObject* process_attributes; /* ignored */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
379 PyObject* thread_attributes; /* ignored */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
380 int inherit_handles; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
381 int creation_flags; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
382 PyObject* env_mapping; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
383 char* current_directory; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
384 PyObject* startup_info; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
385 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
386 if (! PyArg_ParseTuple(args, "zzOOiiOzO:CreateProcess", |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
387 &application_name, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
388 &command_line, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
389 &process_attributes, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
390 &thread_attributes, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
391 &inherit_handles, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
392 &creation_flags, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
393 &env_mapping, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
394 ¤t_directory, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
395 &startup_info)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
396 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
397 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
398 ZeroMemory(&si, sizeof(si)); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
399 si.cb = sizeof(si); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
400 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
401 /* note: we only support a small subset of all SI attributes */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
402 si.dwFlags = getint(startup_info, "dwFlags"); |
|
33929
66223a9ebe48
When using shell=True on Windows, don't display a shell window by default. Fixes #1057061.
Peter Astrand <astrand@lysator.liu.se>
parents:
33729
diff
changeset
|
403 si.wShowWindow = getint(startup_info, "wShowWindow"); |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
404 si.hStdInput = gethandle(startup_info, "hStdInput"); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
405 si.hStdOutput = gethandle(startup_info, "hStdOutput"); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
406 si.hStdError = gethandle(startup_info, "hStdError"); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
407 |
|
35856
4462871a6dce
r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
35855
diff
changeset
|
408 if (PyErr_Occurred()) |
|
4462871a6dce
r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
35855
diff
changeset
|
409 return NULL; |
|
4462871a6dce
r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
35855
diff
changeset
|
410 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
411 if (env_mapping == Py_None) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
412 environment = NULL; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
413 else { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
414 environment = getenvironment(env_mapping); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
415 if (! environment) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
416 return NULL; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
417 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
418 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
419 Py_BEGIN_ALLOW_THREADS |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
420 result = CreateProcess(application_name, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
421 command_line, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
422 NULL, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
423 NULL, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
424 inherit_handles, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
425 creation_flags, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
426 environment ? PyString_AS_STRING(environment) : NULL, |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
427 current_directory, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
428 &si, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
429 &pi); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
430 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
431 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
432 Py_XDECREF(environment); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
433 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
434 if (! result) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
435 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
436 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
437 return Py_BuildValue("NNii", |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
438 sp_handle_new(pi.hProcess), |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
439 sp_handle_new(pi.hThread), |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
440 pi.dwProcessId, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
441 pi.dwThreadId); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
442 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
443 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
444 static PyObject * |
|
36086
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
445 sp_TerminateProcess(PyObject* self, PyObject* args) |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
446 { |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
447 BOOL result; |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
448 |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
449 HANDLE process; |
|
36086
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
450 int exit_code; |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
451 if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM "i:TerminateProcess", |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
452 &process, &exit_code)) |
|
36086
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
453 return NULL; |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
454 |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
455 result = TerminateProcess(process, exit_code); |
|
36086
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
456 |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
457 if (! result) |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
458 return PyErr_SetFromWindowsErr(GetLastError()); |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
459 |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
460 Py_INCREF(Py_None); |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
461 return Py_None; |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
462 } |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
463 |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
464 static PyObject * |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
465 sp_GetExitCodeProcess(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
466 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
467 DWORD exit_code; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
468 BOOL result; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
469 |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
470 HANDLE process; |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
471 if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM ":GetExitCodeProcess", &process)) |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
472 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
473 |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
474 result = GetExitCodeProcess(process, &exit_code); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
475 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
476 if (! result) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
477 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
478 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
479 return PyInt_FromLong(exit_code); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
480 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
481 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
482 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
483 sp_WaitForSingleObject(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
484 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
485 DWORD result; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
486 |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
487 HANDLE handle; |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
488 int milliseconds; |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
489 if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM "i:WaitForSingleObject", |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
490 &handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
491 &milliseconds)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
492 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
493 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
494 Py_BEGIN_ALLOW_THREADS |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
495 result = WaitForSingleObject(handle, (DWORD) milliseconds); |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
496 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
497 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
498 if (result == WAIT_FAILED) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
499 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
500 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
501 return PyInt_FromLong((int) result); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
502 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
503 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
504 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
505 sp_GetVersion(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
506 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
507 if (! PyArg_ParseTuple(args, ":GetVersion")) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
508 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
509 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
510 return PyInt_FromLong((int) GetVersion()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
511 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
512 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
513 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
514 sp_GetModuleFileName(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
515 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
516 BOOL result; |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
517 HMODULE module; |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
518 TCHAR filename[MAX_PATH]; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
519 |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
520 if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM ":GetModuleFileName", |
|
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
521 &module)) |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
522 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
523 |
|
48034
8989213f386b
fix issue3120 - don't truncate handles on 64-bit Windows.
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
524 result = GetModuleFileName(module, filename, MAX_PATH); |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
525 filename[MAX_PATH-1] = '\0'; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
526 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
527 if (! result) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
528 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
529 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
530 return PyString_FromString(filename); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
531 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
532 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
533 static PyMethodDef sp_functions[] = { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
534 {"GetStdHandle", sp_GetStdHandle, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
535 {"GetCurrentProcess", sp_GetCurrentProcess, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
536 {"DuplicateHandle", sp_DuplicateHandle, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
537 {"CreatePipe", sp_CreatePipe, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
538 {"CreateProcess", sp_CreateProcess, METH_VARARGS}, |
|
36086
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
539 {"TerminateProcess", sp_TerminateProcess, METH_VARARGS}, |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
540 {"GetExitCodeProcess", sp_GetExitCodeProcess, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
541 {"WaitForSingleObject", sp_WaitForSingleObject, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
542 {"GetVersion", sp_GetVersion, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
543 {"GetModuleFileName", sp_GetModuleFileName, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
544 {NULL, NULL} |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
545 }; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
546 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
547 /* -------------------------------------------------------------------- */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
548 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
549 static void |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
550 defint(PyObject* d, const char* name, int value) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
551 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
552 PyObject* v = PyInt_FromLong((long) value); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
553 if (v) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
554 PyDict_SetItemString(d, (char*) name, v); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
555 Py_DECREF(v); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
556 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
557 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
558 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
559 #if PY_VERSION_HEX >= 0x02030000 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
560 PyMODINIT_FUNC |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
561 #else |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
562 DL_EXPORT(void) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
563 #endif |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
564 init_subprocess() |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
565 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
566 PyObject *d; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
567 PyObject *m; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
568 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
569 /* patch up object descriptors */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
570 sp_handle_type.ob_type = &PyType_Type; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
571 sp_handle_as_number.nb_int = (unaryfunc) sp_handle_as_int; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
572 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
573 m = Py_InitModule("_subprocess", sp_functions); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36086
diff
changeset
|
574 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36086
diff
changeset
|
575 return; |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
576 d = PyModule_GetDict(m); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
577 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
578 /* constants */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
579 defint(d, "STD_INPUT_HANDLE", STD_INPUT_HANDLE); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
580 defint(d, "STD_OUTPUT_HANDLE", STD_OUTPUT_HANDLE); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
581 defint(d, "STD_ERROR_HANDLE", STD_ERROR_HANDLE); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
582 defint(d, "DUPLICATE_SAME_ACCESS", DUPLICATE_SAME_ACCESS); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
583 defint(d, "STARTF_USESTDHANDLES", STARTF_USESTDHANDLES); |
|
33929
66223a9ebe48
When using shell=True on Windows, don't display a shell window by default. Fixes #1057061.
Peter Astrand <astrand@lysator.liu.se>
parents:
33729
diff
changeset
|
584 defint(d, "STARTF_USESHOWWINDOW", STARTF_USESHOWWINDOW); |
|
66223a9ebe48
When using shell=True on Windows, don't display a shell window by default. Fixes #1057061.
Peter Astrand <astrand@lysator.liu.se>
parents:
33729
diff
changeset
|
585 defint(d, "SW_HIDE", SW_HIDE); |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
586 defint(d, "INFINITE", INFINITE); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
587 defint(d, "WAIT_OBJECT_0", WAIT_OBJECT_0); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
588 defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
589 } |
