From 44f46f9f389816c154d80a7d3ceddb3730e6eb88 Mon Sep 17 00:00:00 2001 From: Alexey Stepanov Date: Mon, 4 Sep 2023 16:53:13 +0200 Subject: [PATCH] Fix #583: python 3.12 compatibility (#598) * Fix #583: python 3.12 compatibility Replace as pep-0393 recommended: * `PyUnicode_AS_UNICODE` by `PyUnicode_ReadChar` (use Stable API) * Enable PR tests on python 3.12 * Force Limited API following pep-0384 --------- Backported to Fedora rawhide Upstream commit: https://github.com/urwid/urwid/commit/44f46f9f389816c154d80a7d3ceddb3730e6eb88 Co-authored-by: Aleksei Stepanov Signed-off-by: Tomas Tomecek --- source/str_util.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/source/str_util.c b/source/str_util.c index 5ed1356..a8480d7 100644 --- a/source/str_util.c +++ b/source/str_util.c @@ -21,6 +21,8 @@ */ #define PY_SSIZE_T_CLEAN +// Use Limited API for Python 3.7.0 release and newer +#define Py_LIMITED_API 0x030700f0 #include @@ -476,13 +478,11 @@ offs -- offset"; static int Py_IsWideChar(PyObject *text, Py_ssize_t offs) { const unsigned char *str; - Py_UNICODE *ustr; Py_ssize_t ret[2], str_len; if (PyUnicode_Check(text)) //text_py is unicode string { - ustr = PyUnicode_AS_UNICODE(text); - return (Py_GetWidth((long int)ustr[offs]) == 2); + return (Py_GetWidth((long int) PyUnicode_ReadChar(text, offs)) == 2); } #ifndef PYTHON3 @@ -656,15 +656,13 @@ static Py_ssize_t Py_CalcWidth(PyObject *text, Py_ssize_t start_offs, unsigned char * str; Py_ssize_t i, ret[2], str_len; int screencols; - Py_UNICODE *ustr; if (PyUnicode_Check(text)) //text_py is unicode string { - ustr = PyUnicode_AS_UNICODE(text); screencols = 0; for(i=start_offs; i pref_col) { -- 2.41.0