diff options
author | Thomas Heller <theller@ctypes.org> | 2008-07-24 11:16:45 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2008-07-24 11:16:45 (GMT) |
commit | ba55936b8ad3788527a959cbb0281a86a4f1af15 (patch) | |
tree | e57df595e65c6868f9bd2bd0f3e4e4b02deafae9 | |
parent | 340739e216788d132ffd985c7dc26bd3368ff80b (diff) | |
download | cpython-ba55936b8ad3788527a959cbb0281a86a4f1af15.zip cpython-ba55936b8ad3788527a959cbb0281a86a4f1af15.tar.gz cpython-ba55936b8ad3788527a959cbb0281a86a4f1af15.tar.bz2 |
Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 8 | ||||
-rw-r--r-- | Modules/_ctypes/ctypes.h | 10 |
2 files changed, 16 insertions, 2 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 9c7355a..a6be815 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -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 }; /* diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h index 96db12f..cce733b 100644 --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -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 |