mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
dd2a6bf14f
commit
ecc3e67b98
|
@ -138,8 +138,8 @@ class StructureTestCase(unittest.TestCase):
|
|||
self.failUnlessEqual(X.y.size, sizeof(c_char))
|
||||
|
||||
# readonly
|
||||
self.assertRaises(TypeError, setattr, X.x, "offset", 92)
|
||||
self.assertRaises(TypeError, setattr, X.x, "size", 92)
|
||||
self.assertRaises(AttributeError, setattr, X.x, "offset", 92)
|
||||
self.assertRaises(AttributeError, setattr, X.x, "size", 92)
|
||||
|
||||
class X(Union):
|
||||
_fields_ = [("x", c_int),
|
||||
|
@ -152,8 +152,8 @@ class StructureTestCase(unittest.TestCase):
|
|||
self.failUnlessEqual(X.y.size, sizeof(c_char))
|
||||
|
||||
# readonly
|
||||
self.assertRaises(TypeError, setattr, X.x, "offset", 92)
|
||||
self.assertRaises(TypeError, setattr, X.x, "size", 92)
|
||||
self.assertRaises(AttributeError, setattr, X.x, "offset", 92)
|
||||
self.assertRaises(AttributeError, setattr, X.x, "size", 92)
|
||||
|
||||
# XXX Should we check nested data types also?
|
||||
# offset is always relative to the class...
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue