Commits

Armin Rigo committed 93d9b5d

Move the cast() method to the base class to let it apply
to arrays too (see comments)

Comments (0)

Files changed (1)

pypy/module/_cffi_backend/ctypeptr.py

         self.is_char_ptr_or_array = isinstance(ctitem, W_CTypePrimitiveChar)
         self.is_struct_ptr = isinstance(ctitem, W_CTypeStructOrUnion)
 
-
-class W_CTypePtrBase(W_CTypePtrOrArray):
-    # base class for both pointers and pointers-to-functions
-
     def cast(self, w_ob):
+        # cast to a pointer, to a funcptr, or to an array.
+        # Note that casting to an array is an extension to the C language,
+        # which seems to be necessary in order to sanely get a
+        # <cdata 'int[3]'> at some address.
+        if self.size < 0:
+            return W_CType.cast(self, w_ob)
         space = self.space
         ob = space.interpclass_w(w_ob)
         if (isinstance(ob, cdataobj.W_CData) and
             value = rffi.cast(rffi.CCHARP, value)
         return cdataobj.W_CData(space, value, self)
 
+
+class W_CTypePtrBase(W_CTypePtrOrArray):
+    # base class for both pointers and pointers-to-functions
+
     def convert_to_object(self, cdata):
         ptrdata = rffi.cast(rffi.CCHARPP, cdata)[0]
         return cdataobj.W_CData(self.space, ptrdata, self)