Commits

Armin Rigo  committed 65574fb

Change 'ffi.new("FILE**", f)' into 'ffi.cast("FILE*", f)'.

  • Participants
  • Parent commits 58a810a

Comments (0)

Files changed (2)

File c/_cffi_backend.c

         CTypeDescrObject *ctinit;
 
         if (!CData_Check(init)) {
-            if (PyFile_Check(init) &&
-                (ct->ct_itemdescr->ct_flags & CT_IS_FILE)) {
-                *(FILE **)data = PyFile_AsFile(init);
-                return 0;
-            }
             expected = "cdata pointer";
             goto cannot_convert;
         }
         /* from a unicode, we add the null terminator */
         length = _my_PyUnicode_SizeAsWideChar(init) + 1;
     }
-    else if (PyFile_Check(init) &&
-             (ctptr->ct_itemdescr->ct_flags & CT_IS_FILE)) {
+    else if (PyFile_Check(init) && (ctitem->ct_flags & CT_IS_FILE)) {
         output_data[0] = (char *)PyFile_AsFile(init);
         return 1;
     }
                 return new_simple_cdata(cdsrc->c_data, ct);
             }
         }
+        if (PyFile_Check(ob) && (ct->ct_flags & CT_POINTER) &&
+                  (ct->ct_itemdescr->ct_flags & CT_IS_FILE)) {
+            return new_simple_cdata((char *)PyFile_AsFile(ob), ct);
+        }
         value = _my_PyLong_AsUnsignedLongLong(ob, 0);
         if (value == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())
             return NULL;
     #
     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")
     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()
     #