diff options
author | Armin Rigo <arigo@tunes.org> | 2015-08-30 10:28:37 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2015-08-30 10:28:37 +0200 |
commit | fc33d5af31444b831311dd28b6a2d47dc35f3bc3 (patch) | |
tree | b280ef19f8319e1e2e8916d7f575feccce8544af | |
parent | be60f2fd29fa0193e3fa351c7a6bc2378a6dc463 (diff) | |
download | cffi-fc33d5af31444b831311dd28b6a2d47dc35f3bc3.tar.gz |
Backed out changeset 663cebc6e784
_io._IOBase is actually a type written in C, so it should be shared
among sub-interpreters anyway
-rw-r--r-- | c/_cffi_backend.c | 2 | ||||
-rw-r--r-- | c/file_emulator.h | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c index 30de173..315ff9e 100644 --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -6333,6 +6333,8 @@ init_cffi_backend(void) 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 index 44c056d..8511203 100644 --- 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) |