Index: Modules/_ctypes/callproc.c =================================================================== --- Modules/_ctypes/callproc.c (revision 55100) +++ Modules/_ctypes/callproc.c (working copy) @@ -1128,10 +1128,10 @@ Free the handle of an executable previously loaded by LoadLibrary.\n"; static PyObject *free_library(PyObject *self, PyObject *args) { - HMODULE hMod; - if (!PyArg_ParseTuple(args, "i:FreeLibrary", &hMod)) + void *hMod; + if (!PyArg_ParseTuple(args, PY_VOIDP_T_CODE ":FreeLibrary", &hMod)) return NULL; - if (!FreeLibrary(hMod)) + if (!FreeLibrary((HMODULE)hMod)) return PyErr_SetFromWindowsErr(GetLastError()); Py_INCREF(Py_None); return Py_None; @@ -1250,11 +1250,11 @@ static PyObject *py_dl_close(PyObject *self, PyObject *args) { - int handle; + void *handle; - if (!PyArg_ParseTuple(args, "i:dlclose", &handle)) + if (!PyArg_ParseTuple(args, PY_VOIDP_T_CODE ":dlclose", &handle)) return NULL; - if (dlclose((void*)handle)) { + if (dlclose(handle)) { PyErr_SetString(PyExc_OSError, ctypes_dlerror()); return NULL; @@ -1266,10 +1266,10 @@ static PyObject *py_dl_sym(PyObject *self, PyObject *args) { char *name; - int handle; + void *handle; void *ptr; - if (!PyArg_ParseTuple(args, "is:dlsym", &handle, &name)) + if (!PyArg_ParseTuple(args, PY_VOIDP_T_CODE "s:dlsym", &handle, &name)) return NULL; ptr = ctypes_dlsym((void*)handle, name); if (!ptr) { @@ -1277,7 +1277,7 @@ ctypes_dlerror()); return NULL; } - return Py_BuildValue("i", ptr); + return PyLong_FromVoidPtr(ptr); } #endif @@ -1289,12 +1289,12 @@ static PyObject * call_function(PyObject *self, PyObject *args) { - int func; + void *func; PyObject *arguments; PyObject *result; if (!PyArg_ParseTuple(args, - "iO!", + PY_VOIDP_T_CODE "O!", &func, &PyTuple_Type, &arguments)) return NULL; @@ -1320,12 +1320,12 @@ static PyObject * call_cdeclfunction(PyObject *self, PyObject *args) { - int func; + void *func; PyObject *arguments; PyObject *result; if (!PyArg_ParseTuple(args, - "iO!", + PY_VOIDP_T_CODE "O!", &func, &PyTuple_Type, &arguments)) return NULL; Index: Modules/_ctypes/ctypes.h =================================================================== --- Modules/_ctypes/ctypes.h (revision 55100) +++ Modules/_ctypes/ctypes.h (working copy) @@ -6,6 +6,12 @@ typedef int Py_ssize_t; #endif +#if SIZEOF_VOID_P == SIZEOF_LONG +#define PY_VOIDP_T_CODE "k" +#elif SIZEOF_VOID_P == SIZEOF_LONG_LONG +#define PY_VOIDP_T_CODE "K" +#endif + #ifndef MS_WIN32 #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b))