Description: Fix PyIOBase_Type Author: Thomas Andrejak Last-Update: 2021-08-13 --- libprelude-5.2.0/bindings/python/libpreludecpp-python.i 2020-09-09 16:30:32.510000000 +0200 +++ libprelude-5.2.0/bindings/python/libpreludecpp-python.i 2021-08-13 23:20:11.672221930 +0200 @@ -163,6 +163,26 @@ $1 = _cb_python_log; }; +%{ +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; +} +%} + +%init %{ +if (init_file_emulator() < 0) { + return NULL; +} +%} /* tell swig not to cast void * value */ %typemap(in) void *nocast_file_p %{ @@ -172,8 +192,7 @@ } #else - extern PyTypeObject PyIOBase_Type; - if ( ! PyObject_IsInstance((PyObject *) $input, (PyObject *) &PyIOBase_Type) ) { + if ( ! PyObject_IsInstance((PyObject *) $input, PyIOBase_TypeObj) ) { SWIG_exception_fail(SWIG_RuntimeError, "Argument is not a file object"); } #endif @@ -186,8 +205,7 @@ #if PY_VERSION_HEX < 0x03000000 $1 = PyFile_Check((PyObject *) $input); #else - extern PyTypeObject PyIOBase_Type; - $1 = PyObject_IsInstance((PyObject *) $input, (PyObject *) &PyIOBase_Type); + $1 = PyObject_IsInstance((PyObject *) $input, PyIOBase_TypeObj); #endif %}