[Python-checkins] r55995 - python/branches/release25-maint/Modules/_ctypes python/branches/release25-maint/Modules/_ctypes/callproc.c python/branches/release25-maint/Modules/_ctypes/ctypes.h

thomas.heller python-checkins at python.org
Fri Jun 15 19:10:45 CEST 2007


Author: thomas.heller
Date: Fri Jun 15 19:10:41 2007
New Revision: 55995

Modified:
   python/branches/release25-maint/Modules/_ctypes/   (props changed)
   python/branches/release25-maint/Modules/_ctypes/callproc.c
   python/branches/release25-maint/Modules/_ctypes/ctypes.h
Log:
Merged revisions 55896 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk/Modules/_ctypes

........
  r55896 | thomas.heller | 2007-06-11 17:58:33 +0200 (Mo, 11 Jun 2007) | 3 lines
  
  Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
  or "K" codes.
........


Modified: python/branches/release25-maint/Modules/_ctypes/callproc.c
==============================================================================
--- python/branches/release25-maint/Modules/_ctypes/callproc.c	(original)
+++ python/branches/release25-maint/Modules/_ctypes/callproc.c	Fri Jun 15 19:10:41 2007
@@ -1029,6 +1029,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
@@ -1112,7 +1121,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());
@@ -1235,7 +1244,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,
@@ -1252,7 +1261,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(handle, name);
 	if (!ptr) {
@@ -1277,8 +1287,8 @@
 	PyObject *result;
 
 	if (!PyArg_ParseTuple(args,
-			      PY_VOID_P_CODE "O!",
-			      &func,
+			      "O&O!",
+			      &_parse_voidp, &func,
 			      &PyTuple_Type, &arguments))
 		return NULL;
 
@@ -1308,8 +1318,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/branches/release25-maint/Modules/_ctypes/ctypes.h
==============================================================================
--- python/branches/release25-maint/Modules/_ctypes/ctypes.h	(original)
+++ python/branches/release25-maint/Modules/_ctypes/ctypes.h	Fri Jun 15 19:10:41 2007
@@ -23,12 +23,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 *, unsigned size);


More information about the Python-checkins mailing list