[Python-checkins] r46689 - in python/trunk: Lib/ctypes/test/test_structures.py Modules/_ctypes/cfield.c

thomas.heller python-checkins at python.org
Tue Jun 6 13:34:34 CEST 2006


Author: thomas.heller
Date: Tue Jun  6 13:34:33 2006
New Revision: 46689

Modified:
   python/trunk/Lib/ctypes/test/test_structures.py
   python/trunk/Modules/_ctypes/cfield.c
Log:
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.

Modified: python/trunk/Lib/ctypes/test/test_structures.py
==============================================================================
--- python/trunk/Lib/ctypes/test/test_structures.py	(original)
+++ python/trunk/Lib/ctypes/test/test_structures.py	Tue Jun  6 13:34:33 2006
@@ -138,8 +138,8 @@
         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 @@
         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...

Modified: python/trunk/Modules/_ctypes/cfield.c
==============================================================================
--- python/trunk/Modules/_ctypes/cfield.c	(original)
+++ python/trunk/Modules/_ctypes/cfield.c	Tue Jun  6 13:34:33 2006
@@ -1,5 +1,4 @@
 #include "Python.h"
-#include "structmember.h"
 
 #include <ffi.h>
 #ifdef MS_WIN32
@@ -208,14 +207,29 @@
 			 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 @@
 	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 */


More information about the Python-checkins mailing list