Strict Python stable abi conformance fix for PyUnicode_GetLength

PyUnicode_GetLength is officially documented as being in the stable abi
from python-3.7 onwards. It is is actually available in the Python
headers when compiling with Py_LIMITED_API set to 0x03030000 (python-3.3)
and later. This change ensures it is only used when Py_LIMITED_API is
set to 0x03070000 (python-3.7) and later for strict conformance.
This commit is contained in:
William S Fulton 2024-03-16 11:42:14 +00:00
parent 29b1bdb8a4
commit fb41e7290e
1 changed files with 4 additions and 0 deletions

View File

@ -30,7 +30,11 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
%#endif
if (isunicode) {
%#if PY_VERSION_HEX >= 0x03030000
%# if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000
Py_ssize_t len = PyUnicode_GetLength(obj);
%# else
Py_ssize_t len = PyUnicode_AsWideChar(SWIGPY_UNICODE_ARG(obj), NULL, 0) - 1;
%# endif
%#else
Py_ssize_t len = PyUnicode_GetSize(obj);
%#endif