This is an automated email from the ASF dual-hosted git repository.
andor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git
The following commit(s) were added to refs/heads/master by this push:
new e3abfde9a ZOOKEEPER-4871: ZooKeeper python module (zkpython) is
incompatible with Python 3.12
e3abfde9a is described below
commit e3abfde9ad9003fa9d126173ddb8b1f45d13930a
Author: Andor Molnár <[email protected]>
AuthorDate: Wed Sep 17 15:51:15 2025 -0500
ZOOKEEPER-4871: ZooKeeper python module (zkpython) is incompatible with
Python 3.12
Author: anmolnar
Closes #2199 from anmolnar/ZOOKEEPER-4871
---
.../zookeeper-contrib-zkpython/src/c/zookeeper.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/zookeeper-contrib/zookeeper-contrib-zkpython/src/c/zookeeper.c
b/zookeeper-contrib/zookeeper-contrib-zkpython/src/c/zookeeper.c
index ee8a75a03..f534749ce 100644
--- a/zookeeper-contrib/zookeeper-contrib-zkpython/src/c/zookeeper.c
+++ b/zookeeper-contrib/zookeeper-contrib-zkpython/src/c/zookeeper.c
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <zookeeper.h>
#include <assert.h>
@@ -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)
@@ -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;
+ }
+
+ if (!PyObject_IsInstance(pystream, PyIOBase_TypeObj)) {
#else
if(!PyFile_Check(pystream)) {
#endif