annotate PC/_subprocess.c @ 60008:0dfd62076ded

Blocked revisions 79402,79406 via svnmerge ........ r79402 | benjamin.peterson | 2010-03-24 20:03:51 -0500 (Wed, 24 Mar 2010) | 1 line set bsddb eol style ........ r79406 | benjamin.peterson | 2010-03-24 20:05:57 -0500 (Wed, 24 Mar 2010) | 1 line fix eol properties on capsule files ........
author Benjamin Peterson <benjamin@python.org>
date Thu, 25 Mar 2010 01:11:10 +0000
parents f632a4e6ee31
children 91f9168aadd0 a2f5b3b19eb2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #include "Python.h"
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
39
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
40 #define WINDOWS_LEAN_AND_MEAN
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
41 #include "windows.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 /* -------------------------------------------------------------------- */
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
44 /* 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
45 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
46 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
47
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
48 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
49 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
50 HANDLE handle;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
51 } sp_handle_object;
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
52
37144
91dd4d44d3bc Finish getting rid of statichere/staticforward
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
53 static PyTypeObject sp_handle_type;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
54
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
55 static PyObject*
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
56 sp_handle_new(HANDLE handle)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
57 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
58 sp_handle_object* self;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
59
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
60 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
61 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
62 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
63
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
64 self->handle = handle;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
65
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
66 return (PyObject*) self;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
67 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
68
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
69 #if defined(MS_WIN32) && !defined(MS_WIN64)
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
70 #define HANDLE_TO_PYNUM(handle) PyLong_FromLong((long) handle)
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
71 #define PY_HANDLE_PARAM "l"
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
72 #else
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
73 #define HANDLE_TO_PYNUM(handle) PyLong_FromLongLong((long long) handle)
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
74 #define PY_HANDLE_PARAM "L"
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
75 #endif
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
76
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
77 static PyObject*
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
78 sp_handle_detach(sp_handle_object* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
79 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
80 HANDLE handle;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
81
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
82 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
83 return NULL;
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 handle = self->handle;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
86
51985
f632a4e6ee31 Merged revisions 70142 via svnmerge from
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 51271
diff changeset
87 self->handle = INVALID_HANDLE_VALUE;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
88
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
89 /* note: return the current handle, as an integer */
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
90 return HANDLE_TO_PYNUM(handle);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
91 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
92
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
93 static PyObject*
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
94 sp_handle_close(sp_handle_object* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
95 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
96 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
97 return NULL;
33723
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 (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
100 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
101 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
102 }
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
103 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
104 return Py_None;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
105 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
106
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
107 static void
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
108 sp_handle_dealloc(sp_handle_object* self)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
109 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
110 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
111 CloseHandle(self->handle);
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37144
diff changeset
112 PyObject_FREE(self);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
113 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
114
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
115 static PyMethodDef sp_handle_methods[] = {
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
116 {"Detach", (PyCFunction) sp_handle_detach, METH_VARARGS},
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
117 {"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
118 {NULL, NULL}
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
119 };
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
120
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 static PyObject*
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
122 sp_handle_as_int(sp_handle_object* self)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
123 {
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
124 return HANDLE_TO_PYNUM(self->handle);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
125 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
126
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
127 static PyNumberMethods sp_handle_as_number;
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
128
37144
91dd4d44d3bc Finish getting rid of statichere/staticforward
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
129 static PyTypeObject sp_handle_type = {
42338
7bfe9a107b29 Merged revisions 56483-56491 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 38673
diff changeset
130 PyVarObject_HEAD_INIT(NULL, 0)
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
131 "_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
132 (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
133 0, /*tp_print*/
48413
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
134 0, /*tp_getattr*/
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
135 0, /*tp_setattr*/
51271
87fbbf22adf3 Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48563
diff changeset
136 0, /*tp_reserved*/
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
137 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
138 &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
139 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
140 0, /*tp_as_mapping */
48413
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
141 0, /*tp_hash*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
142 0, /*tp_call*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
143 0, /*tp_str*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
144 0, /*tp_getattro*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
145 0, /*tp_setattro*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
146 0, /*tp_as_buffer*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
147 Py_TPFLAGS_DEFAULT, /*tp_flags*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
148 0, /*tp_doc*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
149 0, /*tp_traverse*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
150 0, /*tp_clear*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
151 0, /*tp_richcompare*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
152 0, /*tp_weaklistoffset*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
153 0, /*tp_iter*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
154 0, /*tp_iternext*/
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
155 sp_handle_methods, /*tp_methods*/
33723
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
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
158 /* -------------------------------------------------------------------- */
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
159 /* windows API functions */
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
160
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
161 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
162 sp_GetStdHandle(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
163 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
164 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
165 int std_handle;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
166
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
167 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
168 return NULL;
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 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
171 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
172 Py_END_ALLOW_THREADS
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
173
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
174 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
175 return PyErr_SetFromWindowsErr(GetLastError());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
176
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
177 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
178 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
179 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
180 }
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
181
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
182 /* note: returns integer, not handle object */
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
183 return HANDLE_TO_PYNUM(handle);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
184 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
185
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
186 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
187 sp_GetCurrentProcess(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
188 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
189 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
190 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
191
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
192 return sp_handle_new(GetCurrentProcess());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
193 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
194
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
195 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
196 sp_DuplicateHandle(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
197 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
198 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
199 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
200
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
201 HANDLE source_process_handle;
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
202 HANDLE source_handle;
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
203 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
204 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
205 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
206 int options = 0;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
207
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
208 if (! PyArg_ParseTuple(args,
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
209 PY_HANDLE_PARAM PY_HANDLE_PARAM PY_HANDLE_PARAM
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
210 "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
211 &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
212 &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
213 &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
214 &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
215 &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
216 &options))
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
217 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
218
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
219 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
220 result = DuplicateHandle(
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
221 source_process_handle,
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
222 source_handle,
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
223 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
224 &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
225 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
226 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
227 options
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
228 );
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
229 Py_END_ALLOW_THREADS
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
230
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
231 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
232 return PyErr_SetFromWindowsErr(GetLastError());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
233
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
234 return sp_handle_new(target_handle);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
235 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
236
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
237 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
238 sp_CreatePipe(PyObject* self, PyObject* args)
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 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
241 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
242 BOOL result;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
243
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
244 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
245 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
246
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
247 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
248 return NULL;
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 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
251 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
252 Py_END_ALLOW_THREADS
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
253
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
254 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
255 return PyErr_SetFromWindowsErr(GetLastError());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
256
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
257 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
258 "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
259 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
260
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
261 /* helpers for createprocess */
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
262
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
263 static int
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
264 getint(PyObject* obj, char* name)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
265 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
266 PyObject* value;
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
267 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
268
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
269 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
270 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
271 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
272 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
273 }
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 42997
diff changeset
274 ret = (int) PyLong_AsLong(value);
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
275 Py_DECREF(value);
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
276 return ret;
33723
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
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
279 static HANDLE
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
280 gethandle(PyObject* obj, char* name)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
281 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
282 sp_handle_object* value;
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
283 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
284
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
285 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
286 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
287 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
288 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
289 }
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
290 if (Py_TYPE(value) != &sp_handle_type)
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
291 ret = NULL;
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
292 else
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
293 ret = value->handle;
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
294 Py_DECREF(value);
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
295 return ret;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
296 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
297
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
298 static PyObject*
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
299 getenvironment(PyObject* environment)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
300 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
301 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
302 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
303 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
304 PyObject* values;
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
305 Py_UNICODE* p;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
306
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
307 /* 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
308 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
309 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
310 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
311 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
312 }
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
313
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
314 envsize = PyMapping_Length(environment);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
315
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
316 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
317 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
318 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
319 goto error;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
320
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
321 out = PyUnicode_FromUnicode(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
322 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
323 goto error;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
324
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
325 p = PyUnicode_AS_UNICODE(out);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
326
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
327 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
328 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
329 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
330 PyObject* value = PyList_GET_ITEM(values, i);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
331
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
332 if (! PyUnicode_Check(key) || ! PyUnicode_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
333 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
334 "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
335 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
336 }
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
337 ksize = PyUnicode_GET_SIZE(key);
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
338 vsize = PyUnicode_GET_SIZE(value);
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
339 totalsize = (p - PyUnicode_AS_UNICODE(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
340 vsize + 1 + 1;
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
341 if (totalsize > PyUnicode_GET_SIZE(out)) {
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
342 int offset = p - PyUnicode_AS_UNICODE(out);
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
343 PyUnicode_Resize(&out, totalsize + 1024);
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
344 p = PyUnicode_AS_UNICODE(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
345 }
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
346 Py_UNICODE_COPY(p, PyUnicode_AS_UNICODE(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
347 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
348 *p++ = '=';
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
349 Py_UNICODE_COPY(p, PyUnicode_AS_UNICODE(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
350 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
351 *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
352 }
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 /* 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
355 *p++ = '\0';
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
356 PyUnicode_Resize(&out, p - PyUnicode_AS_UNICODE(out));
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
357
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
358 /* PyObject_Print(out, stdout, 0); */
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
359
35855
429f537cf6d6 r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 33929
diff changeset
360 Py_XDECREF(keys);
429f537cf6d6 r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 33929
diff changeset
361 Py_XDECREF(values);
429f537cf6d6 r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 33929
diff changeset
362
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
363 return out;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
364
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
365 error:
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
366 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
367 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
368 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
369 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
370 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
371
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
372 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
373 sp_CreateProcess(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
374 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
375 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
376 PROCESS_INFORMATION pi;
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
377 STARTUPINFOW si;
33729
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* environment;
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
379
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
380 Py_UNICODE* application_name;
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
381 Py_UNICODE* command_line;
33729
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* 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
383 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
384 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
385 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
386 PyObject* env_mapping;
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
387 Py_UNICODE* current_directory;
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
388 PyObject* startup_info;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
389
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
390 if (! PyArg_ParseTuple(args, "ZZOOiiOZO:CreateProcess",
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
391 &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
392 &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
393 &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
394 &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
395 &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
396 &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
397 &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
398 &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
399 &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
400 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
401
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
402 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
403 si.cb = sizeof(si);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
404
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
405 /* 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
406 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
407 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
408 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
409 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
410 si.hStdError = gethandle(startup_info, "hStdError");
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
411
35856
4462871a6dce r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 35855
diff changeset
412 if (PyErr_Occurred())
4462871a6dce r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 35855
diff changeset
413 return NULL;
4462871a6dce r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 35855
diff changeset
414
33729
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 (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
416 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
417 else {
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
418 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
419 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
420 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
421 }
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
422
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
423 Py_BEGIN_ALLOW_THREADS
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
424 result = CreateProcessW(application_name,
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
425 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
426 NULL,
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
427 NULL,
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
428 inherit_handles,
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
429 creation_flags | CREATE_UNICODE_ENVIRONMENT,
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
430 environment ? PyUnicode_AS_UNICODE(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
431 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
432 &si,
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
433 &pi);
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
434 Py_END_ALLOW_THREADS
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
435
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
436 Py_XDECREF(environment);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
437
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
438 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
439 return PyErr_SetFromWindowsErr(GetLastError());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
440
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
441 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
442 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
443 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
444 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
445 pi.dwThreadId);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
446 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
447
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
448 static PyObject *
36086
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
449 sp_TerminateProcess(PyObject* self, PyObject* args)
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
450 {
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
451 BOOL result;
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
452
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
453 HANDLE process;
36086
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
454 int exit_code;
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
455 if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM "i:TerminateProcess",
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
456 &process, &exit_code))
36086
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
457 return NULL;
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
458
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
459 result = TerminateProcess(process, exit_code);
36086
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
460
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
461 if (! result)
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
462 return PyErr_SetFromWindowsErr(GetLastError());
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 Py_INCREF(Py_None);
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
465 return Py_None;
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
466 }
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
467
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
468 static PyObject *
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
469 sp_GetExitCodeProcess(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
470 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
471 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
472 BOOL result;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
473
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
474 HANDLE process;
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
475 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
476 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
477
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
478 result = GetExitCodeProcess(process, &exit_code);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
479
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
480 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
481 return PyErr_SetFromWindowsErr(GetLastError());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
482
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 42997
diff changeset
483 return PyLong_FromLong(exit_code);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
484 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
485
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
486 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
487 sp_WaitForSingleObject(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
488 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
489 DWORD result;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
490
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
491 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
492 int milliseconds;
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
493 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
494 &handle,
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
495 &milliseconds))
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
496 return NULL;
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 Py_BEGIN_ALLOW_THREADS
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
499 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
500 Py_END_ALLOW_THREADS
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
501
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
502 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
503 return PyErr_SetFromWindowsErr(GetLastError());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
504
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 42997
diff changeset
505 return PyLong_FromLong((int) result);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
506 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
507
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
508 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
509 sp_GetVersion(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
510 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
511 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
512 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
513
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 42997
diff changeset
514 return PyLong_FromLong((int) GetVersion());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
515 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
516
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
517 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
518 sp_GetModuleFileName(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
519 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
520 BOOL result;
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
521 HMODULE module;
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
522 WCHAR filename[MAX_PATH];
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
523
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
524 if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM ":GetModuleFileName",
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
525 &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
526 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
527
48563
b51cd5d3795c Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48413
diff changeset
528 result = GetModuleFileNameW(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
529 filename[MAX_PATH-1] = '\0';
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
530
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
531 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
532 return PyErr_SetFromWindowsErr(GetLastError());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
533
42997
b9226cad9dfd Three patches from issue #1047, by Amaury Forgeot d'Arc:
Guido van Rossum <guido@python.org>
parents: 42338
diff changeset
534 return PyUnicode_FromUnicode(filename, Py_UNICODE_strlen(filename));
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
535 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
536
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
537 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
538 {"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
539 {"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
540 {"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
541 {"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
542 {"CreateProcess", sp_CreateProcess, METH_VARARGS},
36086
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
543 {"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
544 {"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
545 {"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
546 {"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
547 {"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
548 {NULL, NULL}
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
549 };
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
550
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
551 /* -------------------------------------------------------------------- */
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
552
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
553 static void
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
554 defint(PyObject* d, const char* name, int value)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
555 {
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 42997
diff changeset
556 PyObject* v = PyLong_FromLong((long) 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
557 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
558 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
559 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
560 }
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
561 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
562
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
563 static struct PyModuleDef _subprocessmodule = {
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
564 PyModuleDef_HEAD_INIT,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
565 "_subprocess",
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
566 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
567 -1,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
568 sp_functions,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
569 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
570 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
571 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
572 NULL
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
573 };
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
574
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
575 PyMODINIT_FUNC
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
576 PyInit__subprocess()
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 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
579 PyObject *m;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
580
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
581 /* 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
582 sp_handle_as_number.nb_int = (unaryfunc) sp_handle_as_int;
48413
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
583 if (PyType_Ready(&sp_handle_type) < 0)
7e56016a6565 #3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
584 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
585
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
586 m = PyModule_Create(&_subprocessmodule);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36086
diff changeset
587 if (m == NULL)
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
588 return 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
589 d = PyModule_GetDict(m);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
590
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
591 /* constants */
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
592 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
593 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
594 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
595 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
596 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
597 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
598 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
599 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
600 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
601 defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE);
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
602 return m;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
603 }