Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r1062:787eed4dde30
Date: 2012-11-24 16:57 +0100
http://bitbucket.org/cffi/cffi/changeset/787eed4dde30/

Log:    Trying blindly a fix for Python 3 on Windows.

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -4993,6 +4993,8 @@
     init_errno();
 
 #if PY_MAJOR_VERSION >= 3
+    if (init_file_emulator() < 0)
+        INITERROR;
     return m;
 #endif
 }
diff --git a/c/file_emulator.h b/c/file_emulator.h
--- a/c/file_emulator.h
+++ b/c/file_emulator.h
@@ -1,13 +1,24 @@
 
 /* Emulation of PyFile_Check() and PyFile_AsFile() for Python 3. */
 
-extern PyTypeObject PyIOBase_Type;
+static PyObject *PyIOBase_TypeObj;
 
+static int init_file_emulator(void)
+{
+    PyObject *io = PyImport_ImportModule("_io");
+    if (io == NULL)
+        return -1;
+    PyIOBase_TypeObj = PyObject_GetAttrString(io, "_IOBase");
+    if (PyIOBase_TypeObj == NULL)
+        return -1;
+    return 0;
+}
 
-#define PyFile_Check(p)  PyObject_IsInstance(p, (PyObject *)&PyIOBase_Type)
 
+#define PyFile_Check(p)  PyObject_IsInstance(p, PyIOBase_TypeObj)
 
-void _close_file_capsule(PyObject *ob_capsule)
+
+static void _close_file_capsule(PyObject *ob_capsule)
 {
     FILE *f = (FILE *)PyCapsule_GetPointer(ob_capsule, "FILE");
     if (f != NULL)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to