[pypy-commit] cffi default: Backed out changeset 663cebc6e784

arigo noreply at buildbot.pypy.org
Sun Aug 30 10:27:55 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r2267:ad3140a30a7b
Date: 2015-08-30 10:28 +0200
http://bitbucket.org/cffi/cffi/changeset/ad3140a30a7b/

Log:	Backed out changeset 663cebc6e784

	_io._IOBase is actually a type written in C, so it should be shared
	among sub-interpreters anyway

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -6333,6 +6333,8 @@
         INITERROR;
 
 #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,8 +1,21 @@
 
 /* Emulation of PyFile_Check() and PyFile_AsFile() for Python 3. */
 
+static PyObject *PyIOBase_TypeObj;
 
-#define PyFile_Check(p)  PyObject_HasAttrString(p, "_checkSeekable")
+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, PyIOBase_TypeObj)
 
 
 static void _close_file_capsule(PyObject *ob_capsule)


More information about the pypy-commit mailing list