[pypy-svn] r51796 - pypy/dist/pypy/lib/_ctypes

pedronis at codespeak.net pedronis at codespeak.net
Fri Feb 22 16:17:53 CET 2008


Author: pedronis
Date: Fri Feb 22 16:17:53 2008
New Revision: 51796

Modified:
   pypy/dist/pypy/lib/_ctypes/array.py
   pypy/dist/pypy/lib/_ctypes/function.py
   pypy/dist/pypy/lib/_ctypes/pointer.py
   pypy/dist/pypy/lib/_ctypes/primitive.py
   pypy/dist/pypy/lib/_ctypes/structure.py
   pypy/dist/pypy/lib/_ctypes/union.py
Log:
introduce _ffiargshape, use this for arguments instead of _ffiletter, this is really a (size,align) tuple for structures now.

_ffiletter should go away once we have added support for functions returning structs.



Modified: pypy/dist/pypy/lib/_ctypes/array.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/array.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/array.py	Fri Feb 22 16:17:53 2008
@@ -125,7 +125,7 @@
 
 class Array(_CData):
     __metaclass__ = ArrayMeta
-    _ffiletter = 'P'
+    _ffiargshape = _ffiletter = 'P'
     _needs_free = False
 
     def __init__(self, *args):

Modified: pypy/dist/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/function.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/function.py	Fri Feb 22 16:17:53 2008
@@ -17,7 +17,7 @@
 
     _argtypes_ = None
     _restype_ = None
-    _ffiletter = 'P'
+    _ffiargshape = _ffiletter = 'P'
     _ffishape = 'P'
     _needs_free = False
 
@@ -47,7 +47,7 @@
             # XXX finish this one, we need to be able to jump there somehow
         elif callable(argument):
             self.callable = argument
-            argtypes = [arg._ffiletter for arg in self._argtypes_]
+            argtypes = [arg._ffiargshape for arg in self._argtypes_]
             restype = self._restype_._ffiletter
             self._ptr = _rawffi.CallbackPtr(argument, argtypes, restype)
             self._needs_free = True
@@ -90,8 +90,8 @@
         if restype is None:
             import ctypes
             restype = ctypes.c_int
-        argletters = [arg._ffiletter for arg in argtypes]
-        return self.dll._handle.ptr(self.name, argletters, restype._ffiletter)
+        argshapes = [arg._ffiargshape for arg in argtypes]
+        return self.dll._handle.ptr(self.name, argshapes, restype._ffiletter)
 
     def _guess_argtypes(self, args):
         from _ctypes import _CData

Modified: pypy/dist/pypy/lib/_ctypes/pointer.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/pointer.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/pointer.py	Fri Feb 22 16:17:53 2008
@@ -13,6 +13,7 @@
             size       = _rawffi.sizeof('P'),
             align      = _rawffi.alignment('P'),
             length     = 1,
+            _ffiargshape = 'P',
             _ffiletter = 'P',
             _ffishape  = 'P',
         )

Modified: pypy/dist/pypy/lib/_ctypes/primitive.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/primitive.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/primitive.py	Fri Feb 22 16:17:53 2008
@@ -56,6 +56,7 @@
         ffiarray = _rawffi.Array(tp)
         result = type.__new__(self, name, bases, dct)
         result._ffiletter = tp
+        result._ffiargshape = tp
         result._ffishape = tp
         result._ffiarray = ffiarray
         if tp == 'z':

Modified: pypy/dist/pypy/lib/_ctypes/structure.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/structure.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/structure.py	Fri Feb 22 16:17:53 2008
@@ -13,7 +13,6 @@
     alignment = 1
     pos = []
     for fieldname, ctype in fields:
-        letter = ctype._ffiletter
         fieldsize = ctypes.sizeof(ctype)
         fieldalignment = ctypes.alignment(ctype)
         size = round_up(size, fieldalignment)
@@ -39,7 +38,7 @@
             self.__dict__.get('_anonymous_', None))
         self._ffistruct = _rawffi.Structure(rawfields)
         _CDataMeta.__setattr__(self, '_fields_', value)
-        self._ffishape = self._ffistruct.gettypecode()
+        self._ffiargshape = self._ffishape = self._ffistruct.gettypecode()
         return
     _CDataMeta.__setattr__(self, name, value)
 
@@ -106,7 +105,7 @@
                 typedict.get('_anonymous_', None))
             res._ffistruct = _rawffi.Structure(rawfields)
             res._ffishape = res._ffistruct.gettypecode()
-            res._ffiletter = res._ffishape
+            res._ffiargshape = res._ffishape
 
         def __init__(self, *args, **kwds):
             if not hasattr(self, '_ffistruct'):

Modified: pypy/dist/pypy/lib/_ctypes/union.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/union.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/union.py	Fri Feb 22 16:17:53 2008
@@ -15,6 +15,7 @@
                 typedict.get('_anonymous_', None))
             res._ffishape = (res._sizeofinstances(),
                              res._alignmentofinstances())
+            res._ffiargshape = res._ffishape
             # we need to create an array of size one for each
             # of our elements
             res._ffiarrays = {}
@@ -58,14 +59,13 @@
             for name, field in self._fieldtypes.iteritems():
                 self._ffiarrays[name] = _rawffi.Array(field.ctype._ffishape)
             _CDataMeta.__setattr__(self, '_fields_', value)
-            self._ffishape = (self._sizeofinstances(),
-                             self._alignmentofinstances())
+            self._ffiargshape = self._ffishape = (self._sizeofinstances(),
+                                                  self._alignmentofinstances())
             return
         _CDataMeta.__setattr__(self, name, value)
 
 class Union(_CData):
     __metaclass__ = UnionMeta
-    _ffiletter = 'P'
     _needs_free = False
 
     def __getattr__(self, name):



More information about the Pypy-commit mailing list