[pypy-svn] r50877 - in pypy/dist/pypy/lib: _ctypes app_test/ctypes

fijal at codespeak.net fijal at codespeak.net
Tue Jan 22 14:10:20 CET 2008


Author: fijal
Date: Tue Jan 22 14:10:19 2008
New Revision: 50877

Modified:
   pypy/dist/pypy/lib/_ctypes/structure.py
   pypy/dist/pypy/lib/app_test/ctypes/test_unions.py
Log:
unions of structures, a test and support


Modified: pypy/dist/pypy/lib/_ctypes/structure.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/structure.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/structure.py	Tue Jan 22 14:10:19 2008
@@ -116,6 +116,13 @@
     def _alignmentofinstances(self):
         return self._ffistruct.alignment
 
+    def _CData_output(self, resarray):
+        assert isinstance(resarray, _rawffi.ArrayInstance)
+        res = self.__new__(self)
+        ffistruct = self._ffistruct.fromaddress(resarray.buffer)
+        res.__dict__['_buffer'] = ffistruct
+        return res.__ctypes_from_outparam__()
+
 class Structure(_CData):
     __metaclass__ = StructureMeta
     _ffiletter = 'P'

Modified: pypy/dist/pypy/lib/app_test/ctypes/test_unions.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_unions.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_unions.py	Tue Jan 22 14:10:19 2008
@@ -10,3 +10,18 @@
         stuff.y = ord('x')
         assert stuff.x == 'x'
 
+    def test_union_of_structures(self):
+        class Stuff(Structure):
+            _fields_ = [('x', c_int)]
+
+        class Stuff2(Structure):
+            _fields_ = [('x', c_int)]
+
+        class UnionofStuff(Union):
+            _fields_ = [('one', Stuff),
+                        ('two', Stuff2)]
+
+        u = UnionofStuff()
+        u.one.x = 3
+        assert u.two.x == 3
+        



More information about the Pypy-commit mailing list