diff options
author | Thomas Heller <theller@ctypes.org> | 2006-06-06 11:34:33 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2006-06-06 11:34:33 (GMT) |
commit | ecc3e67b986a1eed404b528ccbc099049c149edb (patch) | |
tree | dbb45566cd40d8fc0fd30c79217f8867d82b4840 /Modules | |
parent | dd2a6bf14f5a0794c14780af72641177f216ee01 (diff) | |
download | cpython-ecc3e67b986a1eed404b528ccbc099049c149edb.zip cpython-ecc3e67b986a1eed404b528ccbc099049c149edb.tar.gz cpython-ecc3e67b986a1eed404b528ccbc099049c149edb.tar.bz2 |
Convert CFieldObject tp_members to tp_getset, since there is no
structmember typecode for Py_ssize_t fields. This should fix some of
the errors on the PPC64 debian machine (64-bit, big endian).
Assigning to readonly fields now raises AttributeError instead of
TypeError, so the testcase has to be changed as well.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/cfield.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 7bef412..17711c2 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1,5 +1,4 @@ #include "Python.h" -#include "structmember.h" #include <ffi.h> #ifdef MS_WIN32 @@ -208,14 +207,29 @@ CField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type) self->index, self->size, src->b_ptr + self->offset); } -static PyMemberDef CField_members[] = { - { "offset", T_UINT, - offsetof(CFieldObject, offset), READONLY, - "offset in bytes of this field"}, - { "size", T_UINT, - offsetof(CFieldObject, size), READONLY, - "size in bytes of this field"}, - { NULL }, +static PyObject * +CField_get_offset(PyObject *self, void *data) +{ +#if (PY_VERSION_HEX < 0x02050000) + return PyInt_FromLong(((CFieldObject *)self)->offset); +#else + return PyInt_FromSsize_t(((CFieldObject *)self)->offset); +#endif +} + +static PyObject * +CField_get_size(PyObject *self, void *data) +{ +#if (PY_VERSION_HEX < 0x02050000) + return PyInt_FromLong(((CFieldObject *)self)->size); +#else + return PyInt_FromSsize_t(((CFieldObject *)self)->size); +#endif +} + +static PyGetSetDef CField_getset[] = { + { "offset", CField_get_offset, NULL, "offset in bytes of this field" }, + { "size", CField_get_offset, NULL, "size in bytes of this field" }, }; static int @@ -298,8 +312,8 @@ PyTypeObject CField_Type = { 0, /* tp_iter */ 0, /* tp_iternext */ 0, /* tp_methods */ - CField_members, /* tp_members */ - 0, /* tp_getset */ + 0, /* tp_members */ + CField_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ (descrgetfunc)CField_get, /* tp_descr_get */ |