diff options
author | Thomas Heller <theller@ctypes.org> | 2008-04-04 08:35:44 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2008-04-04 08:35:44 (GMT) |
commit | 8e8ba151dde6e36a972ef64240f48d63251c43a5 (patch) | |
tree | d0424670885e5c68f855327ce0e4c9ad8d025c2a /Modules | |
parent | 46c58c17f18b87f4a3d3d363f171cff1715981d1 (diff) | |
download | cpython-8e8ba151dde6e36a972ef64240f48d63251c43a5.zip cpython-8e8ba151dde6e36a972ef64240f48d63251c43a5.tar.gz cpython-8e8ba151dde6e36a972ef64240f48d63251c43a5.tar.bz2 |
Issue #2543: Make ctypes compatible (again) with Python 2.3, 2.4, and 2.5.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 54 | ||||
-rw-r--r-- | Modules/_ctypes/ctypes.h | 10 |
2 files changed, 38 insertions, 26 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 77c15f3..c127a8b 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -139,6 +139,34 @@ char *conversion_mode_errors = NULL; /****************************************************************/ +#if (PY_VERSION_HEX < 0x02040000) +/* Only in Python 2.4 and up */ +static PyObject * +PyTuple_Pack(int n, ...) +{ + int i; + PyObject *o; + PyObject *result; + PyObject **items; + va_list vargs; + + va_start(vargs, n); + result = PyTuple_New(n); + if (result == NULL) + return NULL; + items = ((PyTupleObject *)result)->ob_item; + for (i = 0; i < n; i++) { + o = va_arg(vargs, PyObject *); + Py_INCREF(o); + items[i] = o; + } + va_end(vargs); + return result; +} +#endif + +/****************************************************************/ + typedef struct { PyObject_HEAD PyObject *key; @@ -4432,32 +4460,6 @@ static PyNumberMethods Simple_as_number = { (inquiry)Simple_nonzero, /* nb_nonzero */ }; -#if (PY_VERSION_HEX < 0x02040000) -/* Only in Python 2.4 and up */ -static PyObject * -PyTuple_Pack(int n, ...) -{ - int i; - PyObject *o; - PyObject *result; - PyObject **items; - va_list vargs; - - va_start(vargs, n); - result = PyTuple_New(n); - if (result == NULL) - return NULL; - items = ((PyTupleObject *)result)->ob_item; - for (i = 0; i < n; i++) { - o = va_arg(vargs, PyObject *); - Py_INCREF(o); - items[i] = o; - } - va_end(vargs); - return result; -} -#endif - /* "%s(%s)" % (self.__class__.__name__, self.value) */ static PyObject * Simple_repr(CDataObject *self) diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h index aa09989..7dfdb18 100644 --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -9,8 +9,18 @@ #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) #endif +#if (PY_VERSION_HEX < 0x02060000) +#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) +#define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, +#define PyImport_ImportModuleNoBlock PyImport_ImportModule +#define PyIndex_Check(ob) PyInt_Check(ob) +#endif + + #ifndef MS_WIN32 #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) |