[pypy-commit] pypy ffi-backend: Move the cast() method to the base class to let it apply
arigo
noreply at buildbot.pypy.org
Thu Jul 26 13:31:34 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r56472:93d9b5db6622
Date: 2012-07-26 13:25 +0200
http://bitbucket.org/pypy/pypy/changeset/93d9b5db6622/
Log: Move the cast() method to the base class to let it apply to arrays
too (see comments)
diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -27,11 +27,13 @@
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
@@ -42,6 +44,10 @@
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)
More information about the pypy-commit
mailing list