Use more portable PyUnicode_AsUTF8* methods.
This supports the use of Py_LIMITED_API and also uses PyUnicode_AsUTF8AndSize if Py_LIMITED_API is set to 3.10 or newer.
This commit is contained in:
parent
df716b8f00
commit
1f40d38e56
1 changed files with 8 additions and 1 deletions
|
|
@ -34,7 +34,14 @@ SWIGINTERN char*
|
||||||
SWIG_Python_str_AsChar(PyObject *str)
|
SWIG_Python_str_AsChar(PyObject *str)
|
||||||
{
|
{
|
||||||
#if PY_VERSION_HEX >= 0x03030000
|
#if PY_VERSION_HEX >= 0x03030000
|
||||||
return (char *)PyUnicode_AsUTF8(str);
|
# if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
|
||||||
|
return (char*)PyUnicode_AsUTF8AndSize(str, NULL);
|
||||||
|
# else
|
||||||
|
PyObject* bytes = PyUnicode_AsUTF8String(str);
|
||||||
|
char* chars = PyBytes_AsString(bytes);
|
||||||
|
Py_DECREF(bytes);
|
||||||
|
return chars;
|
||||||
|
# endif
|
||||||
#else
|
#else
|
||||||
return PyString_AsString(str);
|
return PyString_AsString(str);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue