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

arigo at codespeak.net arigo at codespeak.net
Sat Mar 20 19:25:49 CET 2010


Author: arigo
Date: Sat Mar 20 19:25:48 2010
New Revision: 72467

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:
Pass more tests.


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:25:48 2010
@@ -30,7 +30,7 @@
 
 
 class W_Array(W_DataShape):
-    def __init__(self, basicffitype, size, itemcode='?'):
+    def __init__(self, basicffitype, size):
         # 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 'basicffitype' possibly
@@ -39,8 +39,6 @@
         self.basicffitype = basicffitype
         self.size = size
         self.alignment = size_alignment(basicffitype)[1]
-        # for the W_Arrays that represent simple types only:
-        self.itemcode = itemcode
 
     def allocate(self, space, length, autofree=False):
         if autofree:
@@ -76,23 +74,12 @@
 PRIMITIVE_ARRAY_TYPES = {}
 for _code in TYPEMAP:
     PRIMITIVE_ARRAY_TYPES[_code] = W_Array(TYPEMAP[_code],
-                                           size_alignment(TYPEMAP[_code])[0],
-                                           _code)
+                                           size_alignment(TYPEMAP[_code])[0])
+    PRIMITIVE_ARRAY_TYPES[_code].itemcode = _code
 ARRAY_OF_PTRS = PRIMITIVE_ARRAY_TYPES['P']
 
 def descr_new_array(space, w_type, w_shape):
-    shape, length = unpack_shape_with_length(space, w_shape)
-    if length == 1:
-        return shape
-    if shape._array_shapes is None:
-        shape._array_shapes = {}
-    try:
-        result = shape._array_shapes[length]
-    except KeyError:
-        ffitype = shape.get_ffi_type()
-        size = shape.size * length
-        result = shape._array_shapes[length] = W_Array(ffitype, size)
-    return result
+    return unpack_shape_with_length(space, w_shape)
 
 W_Array.typedef = TypeDef(
     'Array',

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:25:48 2010
@@ -97,14 +97,29 @@
         return space.interp_w(W_Structure, w_shapetype)
 
 def unpack_shape_with_length(space, w_shape):
-    # allow 'w_shape' to be a letter or any (shape, number).
+    # Allow 'w_shape' to be a letter or any (shape, number).
+    # The result is always a W_Array.
     if space.is_true(space.isinstance(w_shape, space.w_str)):
         letter = space.str_w(w_shape)
-        return letter2tp(space, letter), 1
+        return letter2tp(space, letter)
     else:
         w_shapetype, w_length = space.fixedview(w_shape, expected_length=2)
         length = space.int_w(w_length)
-        return space.interp_w(W_DataShape, w_shapetype), length
+        shape = space.interp_w(W_DataShape, w_shapetype)
+        if shape._array_shapes is None:
+            shape._array_shapes = {}
+        try:
+            result = shape._array_shapes[length]
+        except KeyError:
+            from pypy.module._rawffi.array import W_Array
+            if isinstance(shape, W_Array) and length == 1:
+                result = shape
+            else:
+                ffitype = shape.get_ffi_type()
+                size = shape.size * length
+                result = W_Array(ffitype, size)
+            shape._array_shapes[length] = result
+        return result
 
 def unpack_resshape(space, w_restype):
     if space.is_w(w_restype, space.w_None):
@@ -221,6 +236,7 @@
     _array_shapes = None
     size = 0
     alignment = 0
+    itemcode = '?'
 
     def allocate(self, space, length, autofree=False):
         raise NotImplementedError

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:25:48 2010
@@ -13,7 +13,7 @@
 from pypy.module._rawffi.interp_rawffi import segfault_exception
 from pypy.module._rawffi.interp_rawffi import W_DataShape, W_DataInstance
 from pypy.module._rawffi.interp_rawffi import wrap_value, unwrap_value
-#from pypy.module._rawffi.interp_rawffi import unpack_to_size_alignment
+from pypy.module._rawffi.interp_rawffi import unpack_shape_with_length
 from pypy.rlib import libffi
 from pypy.rlib.rarithmetic import intmask, r_uint
 
@@ -26,7 +26,7 @@
             raise OperationError(space.w_ValueError, space.wrap(
                 "Expected list of 2-size tuples"))
         name = space.str_w(l_w[0])
-        tp = unpack_to_size_alignment(space, l_w[1])
+        tp = unpack_shape_with_length(space, l_w[1])
         fields.append((name, tp))
     return fields
 
@@ -37,7 +37,10 @@
     size = 0
     alignment = 1
     pos = []
-    for fieldname, (letter, fieldsize, fieldalignment) in fields:
+    for fieldname, fieldtype in fields:
+        # fieldtype is a W_Array
+        fieldsize = fieldtype.size
+        fieldalignment = fieldtype.alignment
         size = round_up(size, fieldalignment)
         alignment = max(alignment, fieldalignment)
         pos.append(size)
@@ -163,7 +166,7 @@
             raise segfault_exception(space, "accessing NULL pointer")
         i = self.shape.getindex(space, attr)
         _, tp = self.shape.fields[i]
-        return wrap_value(space, cast_pos, self, i, tp)
+        return wrap_value(space, cast_pos, self, i, tp.itemcode)
     getattr.unwrap_spec = ['self', ObjSpace, str]
 
     def setattr(self, space, attr, w_value):
@@ -171,7 +174,7 @@
             raise segfault_exception(space, "accessing NULL pointer")
         i = self.shape.getindex(space, attr)
         _, tp = self.shape.fields[i]
-        unwrap_value(space, push_field, self, i, tp[0], w_value)
+        unwrap_value(space, push_field, self, i, tp.itemcode, w_value)
     setattr.unwrap_spec = ['self', ObjSpace, str, W_Root]
 
     def descr_fieldaddress(self, space, attr):



More information about the Pypy-commit mailing list