summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2022-05-17 11:00:04 +0200
committerStefan Behnel <stefan_ml@behnel.de>2022-05-17 11:00:04 +0200
commitbd605086aa053beb35d1bc4e7d3d07f51b93c8e2 (patch)
treeedbdc3ba78ee99d25bc1fa3af1d5333d6b383ba8
parent63bd40d7e9436d7e5ea784e1935bae095c6ca205 (diff)
downloadpython-lxml-bd605086aa053beb35d1bc4e7d3d07f51b93c8e2.tar.gz
Adapt to PyUnicode wstr removal in Py3.12.
See https://peps.python.org/pep-0623/
-rw-r--r--src/lxml/python.pxd17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/lxml/python.pxd b/src/lxml/python.pxd
index 62307aa1..45918c88 100644
--- a/src/lxml/python.pxd
+++ b/src/lxml/python.pxd
@@ -6,6 +6,23 @@ cdef extern from *:
cdef bint PEP393_ENABLED "CYTHON_PEP393_ENABLED"
cdef extern from "Python.h":
+ """
+ #if defined(CYTHON_PEP393_ENABLED) && CYTHON_PEP393_ENABLED
+ #if PY_VERSION_HEX >= 0x030C0000 && !defined(PyUnicode_IS_READY)
+ #define PyUnicode_IS_READY(s) (1)
+ #define PyUnicode_READY(s) (0)
+ #define PyUnicode_AS_DATA(s) (0)
+ #define PyUnicode_GET_DATA_SIZE(s) (0)
+ #define PyUnicode_GET_SIZE(s) (0)
+ #endif
+ #elif PY_VERSION_HEX <= 0x03030000
+ #define PyUnicode_IS_READY(op) (0)
+ #define PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
+ #define PyUnicode_KIND(u) (sizeof(Py_UNICODE))
+ #define PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
+ #endif
+ """
+
ctypedef struct PyObject
cdef int PY_SSIZE_T_MAX
cdef int PY_VERSION_HEX