Index: PC/_subprocess.c =================================================================== --- PC/_subprocess.c (revision 65146) +++ PC/_subprocess.c (working copy) @@ -69,6 +69,16 @@ return (PyObject*) self; } +#if sizeof(HANDLE) == sizeof(long) +#define HANDLE_TO_PYNUM(handle) PyInt_FromLong((long) handle) +#define PY_HANDLE_PARAM "l" +#elif sizeof(HANDLE) == sizeof(long long) +#define HANDLE_TO_PYNUM(handle) PyLong_FromLongLong((long long) handle) +#define PY_HANDLE_PARAM "L" +#else +#error "Don't know how to convert between a HANDLE and a Python number." +#endif + static PyObject* sp_handle_detach(sp_handle_object* self, PyObject* args) { @@ -82,7 +92,7 @@ self->handle = NULL; /* note: return the current handle, as an integer */ - return PyInt_FromLong((long) handle); + return HANDLE_TO_PYNUM(handle); } static PyObject* @@ -122,7 +132,7 @@ static PyObject* sp_handle_as_int(sp_handle_object* self) { - return PyInt_FromLong((long) self->handle); + return HANDLE_TO_PYNUM(self->handle); } static PyNumberMethods sp_handle_as_number; @@ -168,7 +178,7 @@ } /* note: returns integer, not handle object */ - return PyInt_FromLong((long) handle); + return HANDLE_TO_PYNUM(handle); } static PyObject * @@ -186,14 +196,16 @@ HANDLE target_handle; BOOL result; - long source_process_handle; - long source_handle; - long target_process_handle; + HANDLE source_process_handle; + HANDLE source_handle; + HANDLE target_process_handle; int desired_access; int inherit_handle; int options = 0; - if (! PyArg_ParseTuple(args, "lllii|i:DuplicateHandle", + if (! PyArg_ParseTuple(args, + PY_HANDLE_PARAM PY_HANDLE_PARAM PY_HANDLE_PARAM + "ii|i:DuplicateHandle", &source_process_handle, &source_handle, &target_process_handle, @@ -204,9 +216,9 @@ Py_BEGIN_ALLOW_THREADS result = DuplicateHandle( - (HANDLE) source_process_handle, - (HANDLE) source_handle, - (HANDLE) target_process_handle, + source_process_handle, + source_handle, + target_process_handle, &target_handle, desired_access, inherit_handle, @@ -436,13 +448,13 @@ { BOOL result; - long process; + HANDLE process; int exit_code; - if (! PyArg_ParseTuple(args, "li:TerminateProcess", &process, - &exit_code)) + if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM "i:TerminateProcess", + &process, &exit_code)) return NULL; - result = TerminateProcess((HANDLE) process, exit_code); + result = TerminateProcess(process, exit_code); if (! result) return PyErr_SetFromWindowsErr(GetLastError()); @@ -457,11 +469,11 @@ DWORD exit_code; BOOL result; - long process; - if (! PyArg_ParseTuple(args, "l:GetExitCodeProcess", &process)) + HANDLE process; + if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM ":GetExitCodeProcess", &process)) return NULL; - result = GetExitCodeProcess((HANDLE) process, &exit_code); + result = GetExitCodeProcess(process, &exit_code); if (! result) return PyErr_SetFromWindowsErr(GetLastError()); @@ -474,15 +486,15 @@ { DWORD result; - long handle; + HANDLE handle; int milliseconds; - if (! PyArg_ParseTuple(args, "li:WaitForSingleObject", + if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM "i:WaitForSingleObject", &handle, &milliseconds)) return NULL; Py_BEGIN_ALLOW_THREADS - result = WaitForSingleObject((HANDLE) handle, (DWORD) milliseconds); + result = WaitForSingleObject(handle, (DWORD) milliseconds); Py_END_ALLOW_THREADS if (result == WAIT_FAILED) @@ -504,13 +516,18 @@ sp_GetModuleFileName(PyObject* self, PyObject* args) { BOOL result; - long module; + HMODULE module; TCHAR filename[MAX_PATH]; - if (! PyArg_ParseTuple(args, "l:GetModuleFileName", &module)) +#if sizeof(HMODULE) != sizeof(HANDLE) +#error "Code can't assume sizeof(HMODULE) == sizeof(HANDLE)." +#endif + + if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM ":GetModuleFileName", + &module)) return NULL; - result = GetModuleFileName((HMODULE)module, filename, MAX_PATH); + result = GetModuleFileName(module, filename, MAX_PATH); filename[MAX_PATH-1] = '0円'; if (! result)