[pypy-svn] r52247 - pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes

pedronis at codespeak.net pedronis at codespeak.net
Fri Mar 7 14:35:26 CET 2008


Author: pedronis
Date: Fri Mar  7 14:35:24 2008
New Revision: 52247

Modified:
   pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/array.py
   pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/function.py
   pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/pointer.py
   pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/primitive.py
   pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/structure.py
   pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/union.py
Log:
all ctypes tests pass again except test_anon, for the new world it seems we really would like the notion
of anonmyous _rawffi.Structure which would have no fields but only size and alignment information.



Modified: pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/array.py
==============================================================================
--- pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/array.py	(original)
+++ pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/array.py	Fri Mar  7 14:35:24 2008
@@ -57,7 +57,8 @@
                 res.value = property(getvalue, setvalue)
                 
             if '_length_' in typedict:
-                res._ffishape = ffiarray.gettypecode(typedict['_length_'])
+                res._ffishape = (ffiarray, typedict['_length_'])
+                res._fficompositesize = res._sizeofinstances()
         else:
             res._ffiarray = None
         return res
@@ -65,7 +66,7 @@
     from_address = cdata_from_address
 
     def _sizeofinstances(self):
-        size, alignment = self._ffiarray.gettypecode(self._length_)
+        size, alignment = self._ffiarray.size_alignment(self._length_)
         return size
 
     def _alignmentofinstances(self):
@@ -128,7 +129,7 @@
 
 class Array(_CData):
     __metaclass__ = ArrayMeta
-    _ffiargshape = _ffiletter = 'P'
+    _ffiargshape = 'P'
     _needs_free = False
 
     def __init__(self, *args):
@@ -164,13 +165,13 @@
         if getattr(value, '_objects', None):
             store_reference(self, index, value._objects)
         arg = self._type_._CData_value(value)
-        if not isinstance(self._type_._ffishape, tuple):
+        if self._type_._fficompositesize is None:
             self._buffer[index] = arg
             # something more sophisticated, cannot set field directly
         else:
             from ctypes import memmove
             dest = self._buffer.itemaddress(index)
-            memmove(dest, arg, self._type_._ffishape[0])
+            memmove(dest, arg, self._type_._fficompositesize)
 
     def __getitem__(self, index):
         if isinstance(index, slice):

Modified: pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/function.py	(original)
+++ pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/function.py	Fri Mar  7 14:35:24 2008
@@ -17,8 +17,9 @@
 
     _argtypes_ = None
     _restype_ = None
-    _ffiargshape = _ffiletter = 'P'
+    _ffiargshape = 'P'
     _ffishape = 'P'
+    _fficompositesize = None
     _needs_free = False
 
     def _getargtypes(self):
@@ -48,7 +49,7 @@
         elif callable(argument):
             self.callable = argument
             argtypes = [arg._ffiargshape for arg in self._argtypes_]
-            restype = self._restype_._ffiletter
+            restype = self._restype_._ffiargshape
             self._ptr = _rawffi.CallbackPtr(argument, argtypes, restype)
             self._needs_free = True
             self._buffer = self._ptr.byptr()
@@ -91,10 +92,7 @@
             import ctypes
             restype = ctypes.c_int
         argshapes = [arg._ffiargshape for arg in argtypes]
-        if isinstance(restype._ffiargshape, str): # xxx refactor
-            resshape = restype._ffiargshape
-        else:
-            resshape = restype._ffistruct
+        resshape = restype._ffiargshape
         return self.dll._handle.ptr(self.name, argshapes, resshape)
 
     def _guess_argtypes(self, args):

Modified: pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/pointer.py
==============================================================================
--- pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/pointer.py	(original)
+++ pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/pointer.py	Fri Mar  7 14:35:24 2008
@@ -14,8 +14,8 @@
             align      = _rawffi.alignment('P'),
             length     = 1,
             _ffiargshape = 'P',
-            _ffiletter = 'P',
             _ffishape  = 'P',
+            _fficompositesize = None
         )
         # XXX check if typedict['_type_'] is any sane
         # XXX remember about paramfunc

Modified: pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/primitive.py
==============================================================================
--- pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/primitive.py	(original)
+++ pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/primitive.py	Fri Mar  7 14:35:24 2008
@@ -55,9 +55,9 @@
         default = TP_TO_DEFAULT[tp]
         ffiarray = _rawffi.Array(tp)
         result = type.__new__(self, name, bases, dct)
-        result._ffiletter = tp
         result._ffiargshape = tp
         result._ffishape = tp
+        result._fficompositesize = None
         result._ffiarray = ffiarray
         if tp == 'z':
             # c_char_p

Modified: pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/structure.py
==============================================================================
--- pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/structure.py	(original)
+++ pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/structure.py	Fri Mar  7 14:35:24 2008
@@ -38,7 +38,8 @@
             self.__dict__.get('_anonymous_', None))
         self._ffistruct = _rawffi.Structure(rawfields)
         _CDataMeta.__setattr__(self, '_fields_', value)
-        self._ffiargshape = self._ffishape = self._ffistruct.gettypecode()
+        self._ffiargshape = self._ffishape = (self._ffistruct, 1)
+        self._fficompositesize = self._ffistruct.size
         return
     _CDataMeta.__setattr__(self, name, value)
 
@@ -104,8 +105,9 @@
                 typedict['_fields_'], cls[0], False,
                 typedict.get('_anonymous_', None))
             res._ffistruct = _rawffi.Structure(rawfields)
-            res._ffishape = res._ffistruct.gettypecode()
+            res._ffishape = (res._ffistruct, 1)
             res._ffiargshape = res._ffishape
+            res._fficompositesize = res._ffistruct.size
 
         def __init__(self, *args, **kwds):
             if not hasattr(self, '_ffistruct'):
@@ -184,10 +186,10 @@
             key = keepalive_key(getattr(self.__class__, name).offset)
             store_reference(self, key, value._objects)
         arg = fieldtype._CData_value(value)
-        if isinstance(fieldtype._ffishape, tuple):
+        if fieldtype._fficompositesize is not None:
             from ctypes import memmove
             dest = self._buffer.fieldaddress(name)
-            memmove(dest, arg._buffer.buffer, fieldtype._ffishape[0])
+            memmove(dest, arg._buffer.buffer, fieldtype._fficompositesize)
         else:
             self._buffer.__setattr__(name, arg)
 

Modified: pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/union.py
==============================================================================
--- pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/union.py	(original)
+++ pypy/branch/rawffi-shape-cleanup/pypy/lib/_ctypes/union.py	Fri Mar  7 14:35:24 2008
@@ -16,6 +16,7 @@
             res._ffishape = (res._sizeofinstances(),
                              res._alignmentofinstances())
             res._ffiargshape = res._ffishape
+            res._fficompositesize = res._sizeofinstances()
             # we need to create an array of size one for each
             # of our elements
             res._ffiarrays = {}
@@ -61,6 +62,7 @@
             _CDataMeta.__setattr__(self, '_fields_', value)
             self._ffiargshape = self._ffishape = (self._sizeofinstances(),
                                                   self._alignmentofinstances())
+            self._fficompositesize = self._sizeofinstances()
             return
         _CDataMeta.__setattr__(self, name, value)
 



More information about the Pypy-commit mailing list