mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
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
2 changed files with 29 additions and 15 deletions
|
@ -138,8 +138,8 @@ class StructureTestCase(unittest.TestCase):
|
||||||
self.failUnlessEqual(X.y.size, sizeof(c_char))
|
self.failUnlessEqual(X.y.size, sizeof(c_char))
|
||||||
|
|
||||||
# readonly
|
# readonly
|
||||||
self.assertRaises(TypeError, setattr, X.x, "offset", 92)
|
self.assertRaises(AttributeError, setattr, X.x, "offset", 92)
|
||||||
self.assertRaises(TypeError, setattr, X.x, "size", 92)
|
self.assertRaises(AttributeError, setattr, X.x, "size", 92)
|
||||||
|
|
||||||
class X(Union):
|
class X(Union):
|
||||||
_fields_ = [("x", c_int),
|
_fields_ = [("x", c_int),
|
||||||
|
@ -152,8 +152,8 @@ class StructureTestCase(unittest.TestCase):
|
||||||
self.failUnlessEqual(X.y.size, sizeof(c_char))
|
self.failUnlessEqual(X.y.size, sizeof(c_char))
|
||||||
|
|
||||||
# readonly
|
# readonly
|
||||||
self.assertRaises(TypeError, setattr, X.x, "offset", 92)
|
self.assertRaises(AttributeError, setattr, X.x, "offset", 92)
|
||||||
self.assertRaises(TypeError, setattr, X.x, "size", 92)
|
self.assertRaises(AttributeError, setattr, X.x, "size", 92)
|
||||||
|
|
||||||
# XXX Should we check nested data types also?
|
# XXX Should we check nested data types also?
|
||||||
# offset is always relative to the class...
|
# offset is always relative to the class...
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "structmember.h"
|
|
||||||
|
|
||||||
#include <ffi.h>
|
#include <ffi.h>
|
||||||
#ifdef MS_WIN32
|
#ifdef MS_WIN32
|
||||||
|
@ -208,14 +207,29 @@ CField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type)
|
||||||
self->index, self->size, src->b_ptr + self->offset);
|
self->index, self->size, src->b_ptr + self->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMemberDef CField_members[] = {
|
static PyObject *
|
||||||
{ "offset", T_UINT,
|
CField_get_offset(PyObject *self, void *data)
|
||||||
offsetof(CFieldObject, offset), READONLY,
|
{
|
||||||
"offset in bytes of this field"},
|
#if (PY_VERSION_HEX < 0x02050000)
|
||||||
{ "size", T_UINT,
|
return PyInt_FromLong(((CFieldObject *)self)->offset);
|
||||||
offsetof(CFieldObject, size), READONLY,
|
#else
|
||||||
"size in bytes of this field"},
|
return PyInt_FromSsize_t(((CFieldObject *)self)->offset);
|
||||||
{ NULL },
|
#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
|
static int
|
||||||
|
@ -298,8 +312,8 @@ PyTypeObject CField_Type = {
|
||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
0, /* tp_methods */
|
0, /* tp_methods */
|
||||||
CField_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
CField_getset, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
(descrgetfunc)CField_get, /* tp_descr_get */
|
(descrgetfunc)CField_get, /* tp_descr_get */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue