[Python-checkins] r65217 - in python/trunk/Modules/_ctypes: _ctypes.c ctypes.h

thomas.heller python-checkins at python.org
Thu Jul 24 13:16:45 CEST 2008


Author: thomas.heller
Date: Thu Jul 24 13:16:45 2008
New Revision: 65217

Log:
Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.

Modified:
   python/trunk/Modules/_ctypes/_ctypes.c
   python/trunk/Modules/_ctypes/ctypes.h

Modified: python/trunk/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/trunk/Modules/_ctypes/_ctypes.c	(original)
+++ python/trunk/Modules/_ctypes/_ctypes.c	Thu Jul 24 13:16:45 2008
@@ -1863,8 +1863,8 @@
 		return NULL;
 	}
 	if (PyString_Check(proto)) {
-		proto_str = PyBytes_AS_STRING(proto);
-		proto_len = PyBytes_GET_SIZE(proto);
+		proto_str = PyString_AS_STRING(proto);
+		proto_len = PyString_GET_SIZE(proto);
 	} else {
 		PyErr_SetString(PyExc_TypeError,
 			"class must define a '_type_' string attribute");
@@ -2506,6 +2506,7 @@
 	{ NULL },
 };
 
+#if (PY_VERSION_HEX >= 0x02060000)
 static int CData_NewGetBuffer(PyObject *_self, Py_buffer *view, int flags)
 {
 	CDataObject *self = (CDataObject *)_self;
@@ -2530,6 +2531,7 @@
 	view->internal = NULL;
 	return 0;
 }
+#endif
 
 static Py_ssize_t CData_GetSegcount(PyObject *_self, Py_ssize_t *lenp)
 {
@@ -2554,8 +2556,10 @@
 	(writebufferproc)CData_GetBuffer,
 	(segcountproc)CData_GetSegcount,
 	(charbufferproc)NULL,
+#if (PY_VERSION_HEX >= 0x02060000)
 	(getbufferproc)CData_NewGetBuffer,
 	(releasebufferproc)NULL,
+#endif
 };
 
 /*

Modified: python/trunk/Modules/_ctypes/ctypes.h
==============================================================================
--- python/trunk/Modules/_ctypes/ctypes.h	(original)
+++ python/trunk/Modules/_ctypes/ctypes.h	Thu Jul 24 13:16:45 2008
@@ -6,11 +6,19 @@
 #   include <alloca.h>
 #endif
 
+#if (PY_VERSION_HEX < 0x02040000)
+#define PyDict_CheckExact(ob) (Py_TYPE(ob) == &PyDict_Type)
+#endif
+
 #if (PY_VERSION_HEX < 0x02050000)
 typedef int Py_ssize_t;
 #define PyInt_FromSsize_t PyInt_FromLong
 #define PyNumber_AsSsize_t(ob, exc) PyInt_AsLong(ob)
 #define PyIndex_Check(ob) PyInt_Check(ob)
+typedef Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **);
+typedef Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **);
+typedef Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *);
+typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, char **);
 #endif
 
 #if (PY_VERSION_HEX < 0x02060000)
@@ -18,6 +26,8 @@
 #define PyVarObject_HEAD_INIT(type, size) \
 	PyObject_HEAD_INIT(type) size,
 #define PyImport_ImportModuleNoBlock PyImport_ImportModule
+#define PyLong_FromSsize_t PyInt_FromLong
+#define Py_TPFLAGS_HAVE_NEWBUFFER 0
 #endif
 
 


More information about the Python-checkins mailing list