Commits

Armin Rigo committed 40051e6

Wrote the test and started to fix it, but realized that we don't support
reversed-endian types at all.

  • Participants
  • Parent commits 542d481

Comments (0)

Files changed (2)

lib_pypy/_ctypes/structure.py

      store_reference, ensure_objects, CArgObject
 import inspect
 
-def names_and_fields(self, _fields_, superclass, anonymous_fields=None):
+def names_and_fields(self, superclass, anonymous_fields=None):
     # _fields_: list of (name, ctype, [optional_bitfield])
+    _fields_ = self._fields_
     if isinstance(_fields_, tuple):
         _fields_ = list(_fields_)
     for f in _fields_:
             raise AttributeError("_fields_ is final")
         if self in [f[1] for f in value]:
             raise AttributeError("Structure or union cannot contain itself")
+        _CDataMeta.__setattr__(self, '_fields_', value)
         names_and_fields(
             self,
-            value, self.__bases__[0],
+            self.__bases__[0],
             self.__dict__.get('_anonymous_', None))
-        _CDataMeta.__setattr__(self, '_fields_', value)
         return
     _CDataMeta.__setattr__(self, name, value)
 
             for item in typedict.get('_anonymous_', []):
                 if item not in dict(typedict['_fields_']):
                     raise AttributeError("Anonymous field not found")
+            setattr(res, '_fields_', typedict['_fields_'])
             names_and_fields(
                 res,
-                typedict['_fields_'], cls[0],
+                cls[0],
                 typedict.get('_anonymous_', None))
 
         return res

pypy/module/test_lib_pypy/ctypes_tests/test_structures.py

         obj = X()
         assert isinstance(obj.items, Array)
 
+    def test_big_endian(self):
+        py.test.skip("xxx: reversed-endian support")
+        class S(BigEndianStructure):
+            _fields_ = [('x', c_short)]
+        obj = S()
+        obj.x = 0x1234
+        assert cast(pointer(obj), POINTER(c_ubyte))[0] == 0x12
+        assert cast(pointer(obj), POINTER(c_ubyte))[1] == 0x34
+
 class TestPointerMember(BaseCTypesTestChecker):
 
     def test_1(self):