Author: Armin Rigo <[email protected]>
Branch:
Changeset: r56017:40051e63af13
Date: 2012-07-10 20:20 +0200
http://bitbucket.org/pypy/pypy/changeset/40051e63af13/
Log: Wrote the test and started to fix it, but realized that we don't
support reversed-endian types at all.
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ b/lib_pypy/_ctypes/structure.py
@@ -4,8 +4,9 @@
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_:
@@ -131,11 +132,11 @@
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)
@@ -154,9 +155,10 @@
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
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
@@ -433,6 +433,15 @@
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):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit