diff --git a/src/CXX/Python3/Objects.hxx b/src/CXX/Python3/Objects.hxx index 5d15b4b2de..08f77df6c1 100644 --- a/src/CXX/Python3/Objects.hxx +++ b/src/CXX/Python3/Objects.hxx @@ -2135,13 +2135,20 @@ namespace Py // Queries virtual size_type size() const { - return PyUnicode_GET_SIZE( ptr() ); + return PyUnicode_GetLength( ptr() ); + } + +#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 9 + const Py_UNICODE *unicode_data() const + { + return PyUnicode_AS_UNICODE( ptr() ); } unicodestring as_unicodestring() const { - return unicodestring( PyUnicode_AS_UNICODE( ptr() ), PyUnicode_GET_SIZE( ptr() ) ); + return unicodestring( unicode_data(), PyUnicode_GetLength( ptr() ) ); } +#endif operator std::string() const { @@ -2154,11 +2161,6 @@ namespace Py Bytes b( encode( encoding, error ) ); return b.as_std_string(); } - - const Py_UNICODE *unicode_data() const - { - return PyUnicode_AS_UNICODE( ptr() ); - } }; // ==================================================