Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZOOKEEPER-4871: ZooKeeper python module (zkpython) is incompatible with Python 3.12 #2199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions zookeeper-contrib/zookeeper-contrib-zkpython/src/c/zookeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <zookeeper.h>
#include <assert.h>
Expand Down Expand Up @@ -1466,6 +1467,19 @@ PyObject *pyzoo_set_debug_level(PyObject *self, PyObject *args)
}

static PyObject *log_stream = NULL;
#if PY_MAJOR_VERSION >= 3
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;
}
#endif

/* Set the output file-like object for logging output. Returns Py_None */
PyObject *pyzoo_set_log_stream(PyObject *self, PyObject *args)
Expand All @@ -1477,8 +1491,11 @@ PyObject *pyzoo_set_log_stream(PyObject *self, PyObject *args)
}

#if PY_MAJOR_VERSION >= 3
extern PyTypeObject PyIOBase_Type;
if (!PyObject_IsInstance(pystream, (PyObject *)&PyIOBase_Type)) {
if (init_file_emulator() < 0) {
return NULL;
}
Comment on lines +1494 to +1496
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about it's at the right place. Init should only be called once, but now it will be called every time somebody sets the log stream, which usually happens once, still must be a better place for this.


if (!PyObject_IsInstance(pystream, PyIOBase_TypeObj)) {
#else
if(!PyFile_Check(pystream)) {
#endif
Expand Down
Loading