[Python-checkins] r55896 - python/trunk/Modules/_ctypes/callproc.c python/trunk/Modules/_ctypes/ctypes.h

thomas.heller python-checkins at python.org
Mon Jun 11 17:58:38 CEST 2007


Author: thomas.heller
Date: Mon Jun 11 17:58:33 2007
New Revision: 55896

Modified:
   python/trunk/Modules/_ctypes/callproc.c
   python/trunk/Modules/_ctypes/ctypes.h
Log:
Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
or "K" codes.


Modified: python/trunk/Modules/_ctypes/callproc.c
==============================================================================
--- python/trunk/Modules/_ctypes/callproc.c	(original)
+++ python/trunk/Modules/_ctypes/callproc.c	Mon Jun 11 17:58:33 2007
@@ -1046,6 +1046,15 @@
 	return retval;
 }
 
+static int
+_parse_voidp(PyObject *obj, void **address)
+{
+	*address = PyLong_AsVoidPtr(obj);
+	if (*address == NULL)
+		return 0;
+	return 1;
+}
+
 #ifdef MS_WIN32
 
 #ifdef _UNICODE
@@ -1133,7 +1142,7 @@
 static PyObject *free_library(PyObject *self, PyObject *args)
 {
 	void *hMod;
-	if (!PyArg_ParseTuple(args, PY_VOID_P_CODE ":FreeLibrary", &hMod))
+	if (!PyArg_ParseTuple(args, "O&:FreeLibrary", &_parse_voidp, &hMod))
 		return NULL;
 	if (!FreeLibrary((HMODULE)hMod))
 		return PyErr_SetFromWindowsErr(GetLastError());
@@ -1256,7 +1265,7 @@
 {
 	void *handle;
 
-	if (!PyArg_ParseTuple(args, PY_VOID_P_CODE ":dlclose", &handle))
+	if (!PyArg_ParseTuple(args, "O&:dlclose", &_parse_voidp, &handle))
 		return NULL;
 	if (dlclose(handle)) {
 		PyErr_SetString(PyExc_OSError,
@@ -1273,7 +1282,8 @@
 	void *handle;
 	void *ptr;
 
-	if (!PyArg_ParseTuple(args, PY_VOID_P_CODE "s:dlsym", &handle, &name))
+	if (!PyArg_ParseTuple(args, "O&s:dlsym",
+			      &_parse_voidp, &handle, &name))
 		return NULL;
 	ptr = ctypes_dlsym((void*)handle, name);
 	if (!ptr) {
@@ -1298,8 +1308,8 @@
 	PyObject *result;
 
 	if (!PyArg_ParseTuple(args,
-			      PY_VOID_P_CODE "O!",
-			      &func,
+			      "O&O!",
+			      &_parse_voidp, &func,
 			      &PyTuple_Type, &arguments))
 		return NULL;
 
@@ -1329,8 +1339,8 @@
 	PyObject *result;
 
 	if (!PyArg_ParseTuple(args,
-			      PY_VOID_P_CODE "O!",
-			      &func,
+			      "O&O!",
+			      &_parse_voidp, &func,
 			      &PyTuple_Type, &arguments))
 		return NULL;
 

Modified: python/trunk/Modules/_ctypes/ctypes.h
==============================================================================
--- python/trunk/Modules/_ctypes/ctypes.h	(original)
+++ python/trunk/Modules/_ctypes/ctypes.h	Mon Jun 11 17:58:33 2007
@@ -24,12 +24,6 @@
 #define PY_LONG_LONG LONG_LONG
 #endif
 
-#if SIZEOF_VOID_P == SIZEOF_LONG
-#define PY_VOID_P_CODE "k"
-#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P == SIZEOF_LONG_LONG)
-#define PY_VOID_P_CODE "K"
-#endif
-
 typedef struct tagPyCArgObject PyCArgObject;
 typedef struct tagCDataObject CDataObject;
 typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size);


More information about the Python-checkins mailing list