]> granicus.if.org Git - python/commitdiff
Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
authorThomas Heller <theller@ctypes.org>
Thu, 24 Jul 2008 11:16:45 +0000 (11:16 +0000)
committerThomas Heller <theller@ctypes.org>
Thu, 24 Jul 2008 11:16:45 +0000 (11:16 +0000)
Modules/_ctypes/_ctypes.c
Modules/_ctypes/ctypes.h

index 9c7355ac9bf1890d11642f762f71a3f09f88e318..a6be81511aa0b7a45a26d42128bab7b9e54ed218 100644 (file)
@@ -1863,8 +1863,8 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
                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 @@ static PyMemberDef CData_members[] = {
        { 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 @@ static int CData_NewGetBuffer(PyObject *_self, Py_buffer *view, int flags)
        view->internal = NULL;
        return 0;
 }
+#endif
 
 static Py_ssize_t CData_GetSegcount(PyObject *_self, Py_ssize_t *lenp)
 {
@@ -2554,8 +2556,10 @@ static PyBufferProcs CData_as_buffer = {
        (writebufferproc)CData_GetBuffer,
        (segcountproc)CData_GetSegcount,
        (charbufferproc)NULL,
+#if (PY_VERSION_HEX >= 0x02060000)
        (getbufferproc)CData_NewGetBuffer,
        (releasebufferproc)NULL,
+#endif
 };
 
 /*
index 96db12f25595dde9d4786300f7cd4b31485ba592..cce733b3456618c90cf0d2da652eda4cfe9bf8c3 100644 (file)
@@ -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 @@ typedef int Py_ssize_t;
 #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