Backport from upstream version: compatibility with older Python

versions.
This commit is contained in:
Thomas Heller 2006-03-15 21:49:52 +00:00
parent f99b8162a2
commit 9998f78d6d
3 changed files with 35 additions and 4 deletions

View File

@ -3674,7 +3674,11 @@ CreateArrayType(PyObject *itemtype, Py_ssize_t length)
if (cache == NULL)
return NULL;
}
#if (PY_VERSION_HEX < 0x02050000)
key = Py_BuildValue("(Oi)", itemtype, length);
#else
key = Py_BuildValue("(On)", itemtype, length);
#endif
if (!key)
return NULL;
result = PyDict_GetItem(cache, key);
@ -3698,7 +3702,11 @@ CreateArrayType(PyObject *itemtype, Py_ssize_t length)
#endif
result = PyObject_CallFunction((PyObject *)&ArrayType_Type,
#if (PY_VERSION_HEX < 0x02050000)
"s(O){s:i,s:O}",
#else
"s(O){s:n,s:O}",
#endif
name,
&Array_Type,
"_length_",

View File

@ -250,11 +250,21 @@ CField_repr(CFieldObject *self)
name = ((PyTypeObject *)self->proto)->tp_name;
if (bits)
result = PyString_FromFormat("<Field type=%s, ofs=%d:%d, bits=%d>",
name, (int)self->offset, size, bits);
result = PyString_FromFormat(
#if (PY_VERSION_HEX < 0x02050000)
"<Field type=%s, ofs=%d:%d, bits=%d>",
#else
"<Field type=%s, ofs=%zd:%d, bits=%d>",
#endif
name, self->offset, size, bits);
else
result = PyString_FromFormat("<Field type=%s, ofs=%d, size=%d>",
name, (int)self->offset, size);
result = PyString_FromFormat(
#if (PY_VERSION_HEX < 0x02050000)
"<Field type=%s, ofs=%d, size=%d>",
#else
"<Field type=%s, ofs=%zd, size=%d>",
#endif
name, self->offset, size);
return result;
}

View File

@ -1,5 +1,18 @@
/******************************************************************/
#if (PY_VERSION_HEX < 0x02050000)
typedef int Py_ssize_t;
#define lenfunc inquiry
#define readbufferproc getreadbufferproc
#define writebufferproc getwritebufferproc
#define segcountproc getsegcountproc
#define charbufferproc getcharbufferproc
#define ssizeargfunc intargfunc
#define ssizessizeargfunc intintargfunc
#define ssizeobjargproc intobjargproc
#define ssizessizeobjargproc intintobjargproc
#endif
#ifndef MS_WIN32
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))