Commit b2abac76 authored by Tim Peters's avatar Tim Peters

Before this turns into an unreadable mess, follow PEP 7 by using

hard tab indents in C code.
parent ca424bc4
......@@ -71,7 +71,7 @@ sp_handle_detach(sp_handle_object* self, PyObject* args)
{
HANDLE handle;
if (!PyArg_ParseTuple(args, ":Detach"))
if (! PyArg_ParseTuple(args, ":Detach"))
return NULL;
handle = self->handle;
......@@ -85,7 +85,7 @@ sp_handle_detach(sp_handle_object* self, PyObject* args)
static PyObject*
sp_handle_close(sp_handle_object* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ":Close"))
if (! PyArg_ParseTuple(args, ":Close"))
return NULL;
if (self->handle != INVALID_HANDLE_VALUE) {
......@@ -130,7 +130,7 @@ statichere PyTypeObject sp_handle_type = {
"_subprocess_handle", sizeof(sp_handle_object), 0,
(destructor) sp_handle_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc) sp_handle_getattr, /*tp_getattr*/
(getattrfunc) sp_handle_getattr,/*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
......@@ -147,9 +147,9 @@ static PyObject *
sp_GetStdHandle(PyObject* self, PyObject* args)
{
HANDLE handle;
int std_handle;
if (!PyArg_ParseTuple(args, "i:GetStdHandle", &std_handle))
if (! PyArg_ParseTuple(args, "i:GetStdHandle", &std_handle))
return NULL;
Py_BEGIN_ALLOW_THREADS
......@@ -159,7 +159,7 @@ sp_GetStdHandle(PyObject* self, PyObject* args)
if (handle == INVALID_HANDLE_VALUE)
return PyErr_SetFromWindowsErr(GetLastError());
if (!handle) {
if (! handle) {
Py_INCREF(Py_None);
return Py_None;
}
......@@ -171,7 +171,7 @@ sp_GetStdHandle(PyObject* self, PyObject* args)
static PyObject *
sp_GetCurrentProcess(PyObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ":GetCurrentProcess"))
if (! PyArg_ParseTuple(args, ":GetCurrentProcess"))
return NULL;
return sp_handle_new(GetCurrentProcess());
......@@ -189,21 +189,29 @@ sp_DuplicateHandle(PyObject* self, PyObject* args)
int desired_access;
int inherit_handle;
int options = 0;
if (!PyArg_ParseTuple(args, "lllii|i:DuplicateHandle",
&source_process_handle, &source_handle,
if (! PyArg_ParseTuple(args, "lllii|i:DuplicateHandle",
&source_process_handle,
&source_handle,
&target_process_handle,
&desired_access, &inherit_handle, &options))
&desired_access,
&inherit_handle,
&options))
return NULL;
Py_BEGIN_ALLOW_THREADS
result = DuplicateHandle(
(HANDLE) source_process_handle, (HANDLE) source_handle,
(HANDLE) target_process_handle, &target_handle, desired_access,
inherit_handle, options
(HANDLE) source_process_handle,
(HANDLE) source_handle,
(HANDLE) target_process_handle,
&target_handle,
desired_access,
inherit_handle,
options
);
Py_END_ALLOW_THREADS
if (!result)
if (! result)
return PyErr_SetFromWindowsErr(GetLastError());
return sp_handle_new(target_handle);
......@@ -218,19 +226,19 @@ sp_CreatePipe(PyObject* self, PyObject* args)
PyObject* pipe_attributes; /* ignored */
int size;
if (!PyArg_ParseTuple(args, "Oi:CreatePipe", &pipe_attributes, &size))
if (! PyArg_ParseTuple(args, "Oi:CreatePipe", &pipe_attributes, &size))
return NULL;
Py_BEGIN_ALLOW_THREADS
result = CreatePipe(&read_pipe, &write_pipe, NULL, size);
Py_END_ALLOW_THREADS
if (!result)
if (! result)
return PyErr_SetFromWindowsErr(GetLastError());
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 */
......@@ -239,8 +247,9 @@ static int
getint(PyObject* obj, char* name)
{
PyObject* value;
value = PyObject_GetAttrString(obj, name);
if (!value) {
if (! value) {
PyErr_Clear(); /* FIXME: propagate error? */
return 0;
}
......@@ -251,8 +260,9 @@ static HANDLE
gethandle(PyObject* obj, char* name)
{
sp_handle_object* value;
value = (sp_handle_object*) PyObject_GetAttrString(obj, name);
if (!value) {
if (! value) {
PyErr_Clear(); /* FIXME: propagate error? */
return NULL;
}
......@@ -271,11 +281,9 @@ getenvironment(PyObject* environment)
char* p;
/* convert environment dictionary to windows enviroment string */
if (!PyMapping_Check(environment)) {
if (! PyMapping_Check(environment)) {
PyErr_SetString(
PyExc_TypeError, "environment must be dictionary or None"
);
PyExc_TypeError, "environment must be dictionary or None");
return NULL;
}
......@@ -287,7 +295,7 @@ getenvironment(PyObject* environment)
goto error;
out = PyString_FromStringAndSize(NULL, 2048);
if (!out)
if (! out)
goto error;
p = PyString_AS_STRING(out);
......@@ -296,34 +304,38 @@ getenvironment(PyObject* environment)
int ksize, vsize, totalsize;
PyObject* key = PyList_GET_ITEM(keys, i);
PyObject* value = PyList_GET_ITEM(values, i);
if (!PyString_Check(key) || !PyString_Check(value)) {
PyErr_SetString(
PyExc_TypeError, "environment can only contain strings"
);
if (! PyString_Check(key) || ! PyString_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"environment can only contain strings");
goto error;
}
ksize = PyString_GET_SIZE(key);
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)) {
int offset = p - PyString_AS_STRING(out);
_PyString_Resize(&out, totalsize + 1024);
p = PyString_AS_STRING(out) + offset;
}
memcpy(p, PyString_AS_STRING(key), ksize); p += ksize; *p++ = '=';
memcpy(p, PyString_AS_STRING(value), vsize); p += vsize; *p++ = '\0';
memcpy(p, PyString_AS_STRING(key), ksize);
p += ksize;
*p++ = '=';
memcpy(p, PyString_AS_STRING(value), vsize);
p += vsize;
*p++ = '\0';
}
/* add trailing null byte */
*p++ = '\0';
_PyString_Resize(&out, p - PyString_AS_STRING(out));
/* PyObject_Print(out, stdout, 0); */
return out;
error:
error:
Py_XDECREF(out);
Py_XDECREF(keys);
Py_XDECREF(values);
......@@ -347,11 +359,17 @@ sp_CreateProcess(PyObject* self, PyObject* args)
PyObject* env_mapping;
char* current_directory;
PyObject* startup_info;
if (!PyArg_ParseTuple(args, "zzOOiiOzO:CreateProcess",
&application_name, &command_line,
&process_attributes, &thread_attributes,
&inherit_handles, &creation_flags,
&env_mapping, &current_directory, &startup_info))
if (! PyArg_ParseTuple(args, "zzOOiiOzO:CreateProcess",
&application_name,
&command_line,
&process_attributes,
&thread_attributes,
&inherit_handles,
&creation_flags,
&env_mapping,
&current_directory,
&startup_info))
return NULL;
ZeroMemory(&si, sizeof(si));
......@@ -367,27 +385,33 @@ sp_CreateProcess(PyObject* self, PyObject* args)
environment = NULL;
else {
environment = getenvironment(env_mapping);
if (!environment)
if (! environment)
return NULL;
}
Py_BEGIN_ALLOW_THREADS
result = CreateProcess(
application_name, command_line, NULL, NULL, inherit_handles,
creation_flags, environment ? PyString_AS_STRING(environment) : NULL,
current_directory, &si, &pi
);
result = CreateProcess(application_name,
command_line,
NULL,
NULL,
inherit_handles,
creation_flags,
environment ? PyString_AS_STRING(environment) : NULL,
current_directory,
&si,
&pi);
Py_END_ALLOW_THREADS
Py_XDECREF(environment);
if (!result)
if (! result)
return PyErr_SetFromWindowsErr(GetLastError());
return Py_BuildValue(
"NNii", sp_handle_new(pi.hProcess), sp_handle_new(pi.hThread),
pi.dwProcessId, pi.dwThreadId
);
return Py_BuildValue("NNii",
sp_handle_new(pi.hProcess),
sp_handle_new(pi.hThread),
pi.dwProcessId,
pi.dwThreadId);
}
static PyObject *
......@@ -397,12 +421,12 @@ sp_GetExitCodeProcess(PyObject* self, PyObject* args)
BOOL result;
long process;
if (!PyArg_ParseTuple(args, "l:GetExitCodeProcess", &process))
if (! PyArg_ParseTuple(args, "l:GetExitCodeProcess", &process))
return NULL;
result = GetExitCodeProcess((HANDLE) process, &exit_code);
if (!result)
if (! result)
return PyErr_SetFromWindowsErr(GetLastError());
return PyInt_FromLong(exit_code);
......@@ -415,8 +439,9 @@ sp_WaitForSingleObject(PyObject* self, PyObject* args)
long handle;
int milliseconds;
if (!PyArg_ParseTuple(args, "li:WaitForSingleObject",
&handle, &milliseconds))
if (! PyArg_ParseTuple(args, "li:WaitForSingleObject",
&handle,
&milliseconds))
return NULL;
Py_BEGIN_ALLOW_THREADS
......@@ -432,7 +457,7 @@ sp_WaitForSingleObject(PyObject* self, PyObject* args)
static PyObject *
sp_GetVersion(PyObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ":GetVersion"))
if (! PyArg_ParseTuple(args, ":GetVersion"))
return NULL;
return PyInt_FromLong((int) GetVersion());
......@@ -445,13 +470,13 @@ sp_GetModuleFileName(PyObject* self, PyObject* args)
long module;
TCHAR filename[MAX_PATH];
if (!PyArg_ParseTuple(args, "l:GetModuleFileName", &module))
if (! PyArg_ParseTuple(args, "l:GetModuleFileName", &module))
return NULL;
result = GetModuleFileName((HMODULE)module, filename, MAX_PATH);
filename[MAX_PATH-1] = '\0';
if (!result)
if (! result)
return PyErr_SetFromWindowsErr(GetLastError());
return PyString_FromString(filename);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment