Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r58463:cc32c57f0892
Date: 2012-10-26 16:32 +0200
http://bitbucket.org/pypy/pypy/changeset/cc32c57f0892/

Log:    Update to cffi rev. 65574fb4a819.

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
@@ -148,15 +148,7 @@
 
 class W_CTypePtrBase(W_CTypePtrOrArray):
     # base class for both pointers and pointers-to-functions
-    _attrs_ = ['is_file']
-    _immutable_fields_ = ['is_file']
-
-    def __init__(self, space, size, extra, extra_position, ctitem,
-                 could_cast_anything=True, is_file=False):
-        W_CTypePtrOrArray.__init__(self, space, size,
-                                   extra, extra_position, ctitem,
-                                   could_cast_anything=could_cast_anything)
-        self.is_file = is_file
+    _attrs_ = []
 
     def convert_to_object(self, cdata):
         ptrdata = rffi.cast(rffi.CCHARPP, cdata)[0]
@@ -166,11 +158,6 @@
         space = self.space
         ob = space.interpclass_w(w_ob)
         if not isinstance(ob, cdataobj.W_CData):
-            if self.is_file:
-                result = self.prepare_file(w_ob)
-                if result:
-                    rffi.cast(rffi.CCHARPP, cdata)[0] = result
-                    return
             raise self._convert_error("cdata pointer", w_ob)
         other = ob.ctype
         if not isinstance(other, W_CTypePtrBase):
@@ -185,23 +172,14 @@
 
         rffi.cast(rffi.CCHARPP, cdata)[0] = ob._cdata
 
-    def prepare_file(self, w_ob):
-        from pypy.module._file.interp_file import W_File
-        from pypy.module._cffi_backend import ctypefunc
-        ob = self.space.interpclass_w(w_ob)
-        if isinstance(ob, W_File):
-            return prepare_file_argument(self.space, ob)
-        else:
-            return lltype.nullptr(rffi.CCHARP.TO)
-
     def _alignof(self):
         from pypy.module._cffi_backend import newtype
         return newtype.alignment_of_pointer
 
 
 class W_CTypePointer(W_CTypePtrBase):
-    _attrs_ = []
-    _immutable_fields_ = []
+    _attrs_ = ['is_file']
+    _immutable_fields_ = ['is_file']
 
     def __init__(self, space, ctitem):
         from pypy.module._cffi_backend import ctypearray
@@ -210,9 +188,8 @@
             extra = "(*)"    # obscure case: see test_array_add
         else:
             extra = " *"
-        is_file = (ctitem.name == "struct _IO_FILE")
-        W_CTypePtrBase.__init__(self, space, size, extra, 2, ctitem,
-                                is_file=is_file)
+        self.is_file = (ctitem.name == "struct _IO_FILE")
+        W_CTypePtrBase.__init__(self, space, size, extra, 2, ctitem)
 
     def newp(self, w_init):
         space = self.space
@@ -260,6 +237,22 @@
         p = rffi.ptradd(cdata, i * self.ctitem.size)
         return cdataobj.W_CData(space, p, self)
 
+    def cast(self, w_ob):
+        if self.is_file:
+            value = self.prepare_file(w_ob)
+            if value:
+                return cdataobj.W_CData(self.space, value, self)
+        return W_CTypePtrBase.cast(self, w_ob)
+
+    def prepare_file(self, w_ob):
+        from pypy.module._file.interp_file import W_File
+        from pypy.module._cffi_backend import ctypefunc
+        ob = self.space.interpclass_w(w_ob)
+        if isinstance(ob, W_File):
+            return prepare_file_argument(self.space, ob)
+        else:
+            return lltype.nullptr(rffi.CCHARP.TO)
+
     def _prepare_pointer_call_argument(self, w_init, cdata):
         space = self.space
         if (space.isinstance_w(w_init, space.w_list) or
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py 
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -2271,7 +2271,6 @@
     #
     BFILE = new_struct_type("_IO_FILE")
     BFILEP = new_pointer_type(BFILE)
-    BFILEPP = new_pointer_type(BFILEP)
     BChar = new_primitive_type("char")
     BCharP = new_pointer_type(BChar)
     BInt = new_primitive_type("int")
@@ -2285,12 +2284,12 @@
     fdr, fdw = posix.pipe()
     fw1 = posix.fdopen(fdw, 'wb', 256)
     #
-    fw1p = newp(BFILEPP, fw1)
+    fw1p = cast(BFILEP, fw1)
     fw1.write(b"X")
     fw1.flush()
-    res = fputs(b"hello\n", fw1p[0])
+    res = fputs(b"hello\n", fw1p)
     assert res >= 0
-    res = fileno(fw1p[0])
+    res = fileno(fw1p)
     assert res == fdw
     fw1.close()
     #
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to