[pypy-svn] r72465 - pypy/branch/rawffi-64/pypy/module/_rawffi

arigo at codespeak.net arigo at codespeak.net
Sat Mar 20 19:10:36 CET 2010


Author: arigo
Date: Sat Mar 20 19:10:35 2010
New Revision: 72465

Modified:
   pypy/branch/rawffi-64/pypy/module/_rawffi/array.py
   pypy/branch/rawffi-64/pypy/module/_rawffi/interp_rawffi.py
   pypy/branch/rawffi-64/pypy/module/_rawffi/structure.py
Log:
A bit of progress.


Modified: pypy/branch/rawffi-64/pypy/module/_rawffi/array.py
==============================================================================
--- pypy/branch/rawffi-64/pypy/module/_rawffi/array.py	(original)
+++ pypy/branch/rawffi-64/pypy/module/_rawffi/array.py	Sat Mar 20 19:10:35 2010
@@ -13,6 +13,7 @@
 from pypy.module._rawffi.interp_rawffi import W_DataShape, W_DataInstance
 from pypy.module._rawffi.interp_rawffi import unwrap_value, wrap_value
 from pypy.module._rawffi.interp_rawffi import TYPEMAP
+from pypy.module._rawffi.interp_rawffi import size_alignment
 from pypy.module._rawffi.interp_rawffi import unpack_shape_with_length
 from pypy.rlib.rarithmetic import intmask, r_uint
 
@@ -29,14 +30,15 @@
 
 
 class W_Array(W_DataShape):
-    def __init__(self, basicffitype, multiplier=1, itemcode='?'):
-        # 'multiplier' is not the length of the array!
+    def __init__(self, basicffitype, size, itemcode='?'):
         # A W_Array represent the C type '*T', which can also represent
         # the type of pointers to arrays of T.  So the following fields
-        # are used to describe T only.  It is 'multiplier' times the
-        # 'basicffitype'.
+        # are used to describe T only.  It is 'basicffitype' possibly
+        # repeated until reaching the length 'size'.
+        assert size > 0
         self.basicffitype = basicffitype
-        self.multiplier = multiplier
+        self.size = size
+        self.alignment = size_alignment(basicffitype)[1]
         # for the W_Arrays that represent simple types only:
         self.itemcode = itemcode
 
@@ -45,12 +47,9 @@
             return W_ArrayInstanceAutoFree(space, self, length)
         return W_ArrayInstance(space, self, length)
 
-    def get_basic_ffi_type(self):
+    def get_ffi_type(self):
         return self.basicffitype
 
-    def get_ffi_type_with_length(self):
-        return self.basicffitype, self.multiplier
-
     def descr_call(self, space, length, w_items=None, autofree=False):
         result = self.allocate(space, length, autofree)
         if not space.is_w(w_items, space.w_None):
@@ -76,7 +75,9 @@
 
 PRIMITIVE_ARRAY_TYPES = {}
 for _code in TYPEMAP:
-    PRIMITIVE_ARRAY_TYPES[_code] = W_Array(TYPEMAP[_code], itemcode=_code)
+    PRIMITIVE_ARRAY_TYPES[_code] = W_Array(TYPEMAP[_code],
+                                           size_alignment(TYPEMAP[_code])[0],
+                                           _code)
 ARRAY_OF_PTRS = PRIMITIVE_ARRAY_TYPES['P']
 
 def descr_new_array(space, w_type, w_shape):
@@ -88,8 +89,9 @@
     try:
         result = shape._array_shapes[length]
     except KeyError:
-        ffitype, lbase = shape.get_ffi_type_with_length()
-        result = shape._array_shapes[length] = W_Array(ffitype, lbase*length)
+        ffitype = shape.get_ffi_type()
+        size = shape.size * length
+        result = shape._array_shapes[length] = W_Array(ffitype, size)
     return result
 
 W_Array.typedef = TypeDef(
@@ -176,7 +178,7 @@
         if not space.is_true(space.isinstance(w_slice, space.w_slice)):
             raise OperationError(space.w_TypeError,
                                  space.wrap('index must be int or slice'))
-        letter, _, _ = self.shape.itemtp
+        letter = self.shape.itemcode
         if letter != 'c':
             raise OperationError(space.w_TypeError,
                                  space.wrap("only 'c' arrays support slicing"))

Modified: pypy/branch/rawffi-64/pypy/module/_rawffi/interp_rawffi.py
==============================================================================
--- pypy/branch/rawffi-64/pypy/module/_rawffi/interp_rawffi.py	(original)
+++ pypy/branch/rawffi-64/pypy/module/_rawffi/interp_rawffi.py	Sat Mar 20 19:10:35 2010
@@ -143,9 +143,9 @@
             else:
                 raise
         argshapes = unpack_argshapes(space, w_argtypes)
-        ffi_argtypes = [shape.get_basic_ffi_type() for shape in argshapes]
+        ffi_argtypes = [shape.get_ffi_type() for shape in argshapes]
         if resshape is not None:
-            ffi_restype = resshape.get_basic_ffi_type()
+            ffi_restype = resshape.get_ffi_type()
         else:
             ffi_restype = ffi_type_void
 
@@ -221,16 +221,13 @@
     _array_shapes = None
     size = 0
     alignment = 0
-    
+
     def allocate(self, space, length, autofree=False):
         raise NotImplementedError
 
-    def get_basic_ffi_type(self):
+    def get_ffi_type(self):
         raise NotImplementedError
 
-    def get_ffi_type_with_length(self):
-        return self.get_basic_ffi_type(), 1     # default implementation
-
     def descr_size_alignment(self, space, n=1):
         return space.newtuple([space.wrap(self.size * n),
                                space.wrap(self.alignment)])

Modified: pypy/branch/rawffi-64/pypy/module/_rawffi/structure.py
==============================================================================
--- pypy/branch/rawffi-64/pypy/module/_rawffi/structure.py	(original)
+++ pypy/branch/rawffi-64/pypy/module/_rawffi/structure.py	Sat Mar 20 19:10:35 2010
@@ -100,9 +100,7 @@
     descr_fieldoffset.unwrap_spec = ['self', ObjSpace, str]
 
     # get the corresponding ffi_type
-    ffi_type = lltype.nullptr(libffi.FFI_TYPE_P.TO)
-
-    def get_basic_ffi_type(self):
+    def get_ffi_type(self):
         if not self.ffi_type:
             self.ffi_type = libffi.make_struct_ffitype(self.size,
                                                        self.alignment)



More information about the Pypy-commit mailing list