File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
zookeeper-contrib/zookeeper-contrib-zkpython/src/c Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 1616 * limitations under the License.
1717 */
1818
19+ #define PY_SSIZE_T_CLEAN
1920#include <Python.h>
2021#include <zookeeper.h>
2122#include <assert.h>
@@ -1466,6 +1467,19 @@ PyObject *pyzoo_set_debug_level(PyObject *self, PyObject *args)
14661467}
14671468
14681469static PyObject * log_stream = NULL ;
1470+ #if PY_MAJOR_VERSION >= 3
1471+ static PyObject * PyIOBase_TypeObj ;
1472+ static int init_file_emulator (void )
1473+ {
1474+ PyObject * io = PyImport_ImportModule ("_io" );
1475+ if (io == NULL )
1476+ return -1 ;
1477+ PyIOBase_TypeObj = PyObject_GetAttrString (io , "_IOBase" );
1478+ if (PyIOBase_TypeObj == NULL )
1479+ return -1 ;
1480+ return 0 ;
1481+ }
1482+ #endif
14691483
14701484/* Set the output file-like object for logging output. Returns Py_None */
14711485PyObject * pyzoo_set_log_stream (PyObject * self , PyObject * args )
@@ -1477,8 +1491,11 @@ PyObject *pyzoo_set_log_stream(PyObject *self, PyObject *args)
14771491 }
14781492
14791493#if PY_MAJOR_VERSION >= 3
1480- extern PyTypeObject PyIOBase_Type ;
1481- if (!PyObject_IsInstance (pystream , (PyObject * )& PyIOBase_Type )) {
1494+ if (init_file_emulator () < 0 ) {
1495+ return NULL ;
1496+ }
1497+
1498+ if (!PyObject_IsInstance (pystream , PyIOBase_TypeObj )) {
14821499#else
14831500 if (!PyFile_Check (pystream )) {
14841501#endif
You can’t perform that action at this time.
0 commit comments