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

fijal at codespeak.net fijal at codespeak.net
Thu Jan 17 00:09:21 CET 2008


Author: fijal
Date: Thu Jan 17 00:09:20 2008
New Revision: 50695

Modified:
   pypy/dist/pypy/lib/_ctypes/array.py
   pypy/dist/pypy/lib/_ctypes/basics.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
Log:
A bit of wacking to make the tests just commited work a bit


Modified: pypy/dist/pypy/lib/_ctypes/array.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/array.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/array.py	Thu Jan 17 00:09:20 2008
@@ -6,11 +6,10 @@
 class ArrayMeta(_CDataMeta):
     def __new__(self, name, cls, typedict):
         res = type.__new__(self, name, cls, typedict)
-        res._ffiletter = 'P'
         if '_type_' in typedict:
             ffiarray = _rawffi.Array(typedict['_type_']._ffiletter)
             res._ffiarray = ffiarray
-            if typedict['_type_']._type_ == 'c':
+            if getattr(typedict['_type_'], '_type_', None) == 'c':
                 def getvalue(self):
                     return _rawffi.charp2string(self._buffer.buffer,
                                                 self._length_)
@@ -41,8 +40,12 @@
         size, alignment = self._ffiarray.gettypecode(self._length_)
         return size
 
+    def _alignmentofinstances(self):
+        return self._type_._alignmentofinstances()
+
 class Array(_CData):
     __metaclass__ = ArrayMeta
+    _ffiletter = 'P'
 
     def __init__(self, *args):
         self._buffer = self._ffiarray(self._length_)

Modified: pypy/dist/pypy/lib/_ctypes/basics.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/basics.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/basics.py	Thu Jan 17 00:09:20 2008
@@ -73,8 +73,13 @@
     return tp._sizeofinstances()
 
 def alignment(tp):
-    ffitp = tp._type_
-    return _rawffi.alignment(ffitp)
+    if not isinstance(tp, _CDataMeta):
+        if isinstance(tp, _CData):
+            tp = type(tp)
+        else:
+            raise TypeError("ctypes type or instance expected, got %r" % (
+                type(tp).__name__,))
+    return tp._alignmentofinstances()
 
 def byref(cdata):
     from ctypes import pointer

Modified: pypy/dist/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/function.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/function.py	Thu Jan 17 00:09:20 2008
@@ -11,6 +11,8 @@
 
     _argtypes_ = None
     _restype_ = None
+    _ffiletter = 'P'
+    _buffer = 0
 
     def _getargtypes(self):
         return self._argtypes_
@@ -48,6 +50,9 @@
             return restype._CData_output(resarray)
 
     def _getfuncptr(self, argtypes, restype):
+        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)
 

Modified: pypy/dist/pypy/lib/_ctypes/pointer.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/pointer.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/pointer.py	Thu Jan 17 00:09:20 2008
@@ -48,9 +48,15 @@
     def _sizeofinstances(self):
         return _rawffi.sizeof('P')
 
+    def _alignmentofinstances(self):
+        return _rawffi.alignment('P')
+
     def _is_pointer_like(self):
         return True
 
+    def set_type(self, TP):
+        pass # XXX???
+
     from_address = cdata_from_address
 
 class _Pointer(_CData):

Modified: pypy/dist/pypy/lib/_ctypes/primitive.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/primitive.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/primitive.py	Thu Jan 17 00:09:20 2008
@@ -116,6 +116,9 @@
     def _sizeofinstances(self):
         return _rawffi.sizeof(self._type_)
 
+    def _alignmentofinstances(self):
+        return _rawffi.alignment(self._type_)
+
     def _is_pointer_like(self):
         return self._type_ in "sPzUZXO"
 

Modified: pypy/dist/pypy/lib/_ctypes/structure.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/structure.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/structure.py	Thu Jan 17 00:09:20 2008
@@ -41,7 +41,7 @@
     def __setattr__(self, name, value):
         if name == '_fields_':
             if self.__dict__.get('_fields_', None):
-                raise TypeError("Fields already final")
+                raise AttributeError("_fields_ is final")
             self._names, rawfields, self._fieldtypes = names_and_fields(
                 value, self.__bases__[0])
             self._ffistruct = _rawffi.Structure(rawfields)
@@ -59,8 +59,12 @@
             return 0
         return self._ffistruct.size
 
+    def _alignmentofinstances(self):
+        return self._ffistruct.alignment
+
 class Structure(_CData):
     __metaclass__ = StructureMeta
+    _ffiletter = 'P'
 
     def _subarray(self, fieldtype, name):
         """Return a _rawffi array of length 1 whose address is the same as



More information about the Pypy-commit mailing list