mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Before this turns into an unreadable mess, follow PEP 7 by using
hard tab indents in C code.
This commit is contained in:
parent
25b38c8969
commit
f3250b0b0b
1 changed files with 313 additions and 288 deletions
|
@ -147,8 +147,8 @@ static PyObject *
|
||||||
sp_GetStdHandle(PyObject* self, PyObject* args)
|
sp_GetStdHandle(PyObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
HANDLE handle;
|
HANDLE handle;
|
||||||
|
|
||||||
int std_handle;
|
int std_handle;
|
||||||
|
|
||||||
if (! PyArg_ParseTuple(args, "i:GetStdHandle", &std_handle))
|
if (! PyArg_ParseTuple(args, "i:GetStdHandle", &std_handle))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -189,17 +189,25 @@ sp_DuplicateHandle(PyObject* self, PyObject* args)
|
||||||
int desired_access;
|
int desired_access;
|
||||||
int inherit_handle;
|
int inherit_handle;
|
||||||
int options = 0;
|
int options = 0;
|
||||||
|
|
||||||
if (! PyArg_ParseTuple(args, "lllii|i:DuplicateHandle",
|
if (! PyArg_ParseTuple(args, "lllii|i:DuplicateHandle",
|
||||||
&source_process_handle, &source_handle,
|
&source_process_handle,
|
||||||
|
&source_handle,
|
||||||
&target_process_handle,
|
&target_process_handle,
|
||||||
&desired_access, &inherit_handle, &options))
|
&desired_access,
|
||||||
|
&inherit_handle,
|
||||||
|
&options))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
result = DuplicateHandle(
|
result = DuplicateHandle(
|
||||||
(HANDLE) source_process_handle, (HANDLE) source_handle,
|
(HANDLE) source_process_handle,
|
||||||
(HANDLE) target_process_handle, &target_handle, desired_access,
|
(HANDLE) source_handle,
|
||||||
inherit_handle, options
|
(HANDLE) target_process_handle,
|
||||||
|
&target_handle,
|
||||||
|
desired_access,
|
||||||
|
inherit_handle,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
|
@ -218,6 +226,7 @@ sp_CreatePipe(PyObject* self, PyObject* args)
|
||||||
|
|
||||||
PyObject* pipe_attributes; /* ignored */
|
PyObject* pipe_attributes; /* ignored */
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
if (! PyArg_ParseTuple(args, "Oi:CreatePipe", &pipe_attributes, &size))
|
if (! PyArg_ParseTuple(args, "Oi:CreatePipe", &pipe_attributes, &size))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -229,8 +238,7 @@ sp_CreatePipe(PyObject* self, PyObject* args)
|
||||||
return PyErr_SetFromWindowsErr(GetLastError());
|
return PyErr_SetFromWindowsErr(GetLastError());
|
||||||
|
|
||||||
return Py_BuildValue(
|
return Py_BuildValue(
|
||||||
"NN", sp_handle_new(read_pipe), sp_handle_new(write_pipe)
|
"NN", sp_handle_new(read_pipe), sp_handle_new(write_pipe));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* helpers for createprocess */
|
/* helpers for createprocess */
|
||||||
|
@ -239,6 +247,7 @@ static int
|
||||||
getint(PyObject* obj, char* name)
|
getint(PyObject* obj, char* name)
|
||||||
{
|
{
|
||||||
PyObject* value;
|
PyObject* value;
|
||||||
|
|
||||||
value = PyObject_GetAttrString(obj, name);
|
value = PyObject_GetAttrString(obj, name);
|
||||||
if (! value) {
|
if (! value) {
|
||||||
PyErr_Clear(); /* FIXME: propagate error? */
|
PyErr_Clear(); /* FIXME: propagate error? */
|
||||||
|
@ -251,6 +260,7 @@ static HANDLE
|
||||||
gethandle(PyObject* obj, char* name)
|
gethandle(PyObject* obj, char* name)
|
||||||
{
|
{
|
||||||
sp_handle_object* value;
|
sp_handle_object* value;
|
||||||
|
|
||||||
value = (sp_handle_object*) PyObject_GetAttrString(obj, name);
|
value = (sp_handle_object*) PyObject_GetAttrString(obj, name);
|
||||||
if (! value) {
|
if (! value) {
|
||||||
PyErr_Clear(); /* FIXME: propagate error? */
|
PyErr_Clear(); /* FIXME: propagate error? */
|
||||||
|
@ -271,11 +281,9 @@ getenvironment(PyObject* environment)
|
||||||
char* p;
|
char* p;
|
||||||
|
|
||||||
/* convert environment dictionary to windows enviroment string */
|
/* convert environment dictionary to windows enviroment string */
|
||||||
|
|
||||||
if (! PyMapping_Check(environment)) {
|
if (! PyMapping_Check(environment)) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
PyExc_TypeError, "environment must be dictionary or None"
|
PyExc_TypeError, "environment must be dictionary or None");
|
||||||
);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,27 +304,31 @@ getenvironment(PyObject* environment)
|
||||||
int ksize, vsize, totalsize;
|
int ksize, vsize, totalsize;
|
||||||
PyObject* key = PyList_GET_ITEM(keys, i);
|
PyObject* key = PyList_GET_ITEM(keys, i);
|
||||||
PyObject* value = PyList_GET_ITEM(values, i);
|
PyObject* value = PyList_GET_ITEM(values, i);
|
||||||
|
|
||||||
if (! PyString_Check(key) || ! PyString_Check(value)) {
|
if (! PyString_Check(key) || ! PyString_Check(value)) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(PyExc_TypeError,
|
||||||
PyExc_TypeError, "environment can only contain strings"
|
"environment can only contain strings");
|
||||||
);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
ksize = PyString_GET_SIZE(key);
|
ksize = PyString_GET_SIZE(key);
|
||||||
vsize = PyString_GET_SIZE(value);
|
vsize = PyString_GET_SIZE(value);
|
||||||
totalsize = (p - PyString_AS_STRING(out)) + ksize + 1 + vsize + 1 + 1;
|
totalsize = (p - PyString_AS_STRING(out)) + ksize + 1 +
|
||||||
|
vsize + 1 + 1;
|
||||||
if (totalsize > PyString_GET_SIZE(out)) {
|
if (totalsize > PyString_GET_SIZE(out)) {
|
||||||
int offset = p - PyString_AS_STRING(out);
|
int offset = p - PyString_AS_STRING(out);
|
||||||
_PyString_Resize(&out, totalsize + 1024);
|
_PyString_Resize(&out, totalsize + 1024);
|
||||||
p = PyString_AS_STRING(out) + offset;
|
p = PyString_AS_STRING(out) + offset;
|
||||||
}
|
}
|
||||||
memcpy(p, PyString_AS_STRING(key), ksize); p += ksize; *p++ = '=';
|
memcpy(p, PyString_AS_STRING(key), ksize);
|
||||||
memcpy(p, PyString_AS_STRING(value), vsize); p += vsize; *p++ = '\0';
|
p += ksize;
|
||||||
|
*p++ = '=';
|
||||||
|
memcpy(p, PyString_AS_STRING(value), vsize);
|
||||||
|
p += vsize;
|
||||||
|
*p++ = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add trailing null byte */
|
/* add trailing null byte */
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
|
|
||||||
_PyString_Resize(&out, p - PyString_AS_STRING(out));
|
_PyString_Resize(&out, p - PyString_AS_STRING(out));
|
||||||
|
|
||||||
/* PyObject_Print(out, stdout, 0); */
|
/* PyObject_Print(out, stdout, 0); */
|
||||||
|
@ -347,11 +359,17 @@ sp_CreateProcess(PyObject* self, PyObject* args)
|
||||||
PyObject* env_mapping;
|
PyObject* env_mapping;
|
||||||
char* current_directory;
|
char* current_directory;
|
||||||
PyObject* startup_info;
|
PyObject* startup_info;
|
||||||
|
|
||||||
if (! PyArg_ParseTuple(args, "zzOOiiOzO:CreateProcess",
|
if (! PyArg_ParseTuple(args, "zzOOiiOzO:CreateProcess",
|
||||||
&application_name, &command_line,
|
&application_name,
|
||||||
&process_attributes, &thread_attributes,
|
&command_line,
|
||||||
&inherit_handles, &creation_flags,
|
&process_attributes,
|
||||||
&env_mapping, ¤t_directory, &startup_info))
|
&thread_attributes,
|
||||||
|
&inherit_handles,
|
||||||
|
&creation_flags,
|
||||||
|
&env_mapping,
|
||||||
|
¤t_directory,
|
||||||
|
&startup_info))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ZeroMemory(&si, sizeof(si));
|
ZeroMemory(&si, sizeof(si));
|
||||||
|
@ -372,11 +390,16 @@ sp_CreateProcess(PyObject* self, PyObject* args)
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
result = CreateProcess(
|
result = CreateProcess(application_name,
|
||||||
application_name, command_line, NULL, NULL, inherit_handles,
|
command_line,
|
||||||
creation_flags, environment ? PyString_AS_STRING(environment) : NULL,
|
NULL,
|
||||||
current_directory, &si, &pi
|
NULL,
|
||||||
);
|
inherit_handles,
|
||||||
|
creation_flags,
|
||||||
|
environment ? PyString_AS_STRING(environment) : NULL,
|
||||||
|
current_directory,
|
||||||
|
&si,
|
||||||
|
&pi);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
Py_XDECREF(environment);
|
Py_XDECREF(environment);
|
||||||
|
@ -384,10 +407,11 @@ sp_CreateProcess(PyObject* self, PyObject* args)
|
||||||
if (! result)
|
if (! result)
|
||||||
return PyErr_SetFromWindowsErr(GetLastError());
|
return PyErr_SetFromWindowsErr(GetLastError());
|
||||||
|
|
||||||
return Py_BuildValue(
|
return Py_BuildValue("NNii",
|
||||||
"NNii", sp_handle_new(pi.hProcess), sp_handle_new(pi.hThread),
|
sp_handle_new(pi.hProcess),
|
||||||
pi.dwProcessId, pi.dwThreadId
|
sp_handle_new(pi.hThread),
|
||||||
);
|
pi.dwProcessId,
|
||||||
|
pi.dwThreadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -416,7 +440,8 @@ sp_WaitForSingleObject(PyObject* self, PyObject* args)
|
||||||
long handle;
|
long handle;
|
||||||
int milliseconds;
|
int milliseconds;
|
||||||
if (! PyArg_ParseTuple(args, "li:WaitForSingleObject",
|
if (! PyArg_ParseTuple(args, "li:WaitForSingleObject",
|
||||||
&handle, &milliseconds))
|
&handle,
|
||||||
|
&milliseconds))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue