[pypy-commit] pypy ffi-backend: Fixes

arigo noreply at buildbot.pypy.org
Tue Jun 26 19:02:58 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r55836:3fb001ffefe5
Date: 2012-06-26 19:02 +0200
http://bitbucket.org/pypy/pypy/changeset/3fb001ffefe5/

Log:	Fixes

diff --git a/pypy/module/_ffi_backend/ctypefunc.py b/pypy/module/_ffi_backend/ctypefunc.py
--- a/pypy/module/_ffi_backend/ctypefunc.py
+++ b/pypy/module/_ffi_backend/ctypefunc.py
@@ -2,10 +2,10 @@
 Function pointers.
 """
 
-from pypy.module._ffi_backend.ctypeptr import W_CTypePtrOrArray
+from pypy.module._ffi_backend.ctypeptr import W_CTypePtrBase
 
 
-class W_CTypeFunctionPtr(W_CTypePtrOrArray):
+class W_CTypeFunc(W_CTypePtrBase):
 
     def __init__(self, space, fargs, fresult, ellipsis):
         argnames = ['(*)(']
@@ -20,7 +20,8 @@
         argnames.append(')')
         extra = ''.join(argnames)
         #
-        W_CTypePtrOrArray.__init__(self, space, extra, 2, 
+        W_CTypePtrBase.__init__(self, space, extra, 2, fresult)
+        self.can_cast_anything = False
         self.ellipsis = ellipsis
         
         if not ellipsis:
diff --git a/pypy/module/_ffi_backend/ctypeptr.py b/pypy/module/_ffi_backend/ctypeptr.py
--- a/pypy/module/_ffi_backend/ctypeptr.py
+++ b/pypy/module/_ffi_backend/ctypeptr.py
@@ -16,10 +16,13 @@
     def __init__(self, space, size, extra, extra_position, ctitem):
         name, name_position = ctitem.insert_name(extra, extra_position)
         W_CType.__init__(self, space, size, name, name_position)
+        # this is the "underlying type":
+        #  - for pointers, it is the pointed-to type
+        #  - for arrays, it is the array item type
+        #  - for functions, it is the return type
         self.ctitem = ctitem
-
-    def cast_anything(self):
-        return self.ctitem is not None and self.ctitem.cast_anything
+        # overridden to False in W_CTypeFunc
+        self.can_cast_anything = ctitem.cast_anything
 
 
 class W_CTypePtrBase(W_CTypePtrOrArray):
@@ -52,7 +55,8 @@
             raise self._convert_error("compatible pointer", w_ob)
         other = ob.ctype
         if (isinstance(other, W_CTypePtrOrArray) and
-             (self is other or self.cast_anything() or other.cast_anything())):
+             (self is other or
+              self.can_cast_anything or other.can_cast_anything)):
             pass    # compatible types
         else:
             raise self._convert_error("compatible pointer", w_ob)
diff --git a/pypy/module/_ffi_backend/newtype.py b/pypy/module/_ffi_backend/newtype.py
--- a/pypy/module/_ffi_backend/newtype.py
+++ b/pypy/module/_ffi_backend/newtype.py
@@ -5,6 +5,7 @@
 
 from pypy.module._ffi_backend import ctypeobj, ctypeprim, ctypeptr, ctypearray
 from pypy.module._ffi_backend import ctypestruct, ctypevoid, ctypeenum
+from pypy.module._ffi_backend import ctypefunc
 
 
 def alignment(TYPE):
@@ -221,5 +222,5 @@
         raise operationerrfmt(space.w_TypeError,
                               "invalid result type: '%s'", fresult.name)
     #
-    fct = ctypefunc.W_CTypeFunc(fargs, fresult, ellipsis)
+    fct = ctypefunc.W_CTypeFunc(space, fargs, fresult, ellipsis)
     return fct


More information about the pypy-commit mailing list