diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index d9b54bce83202d..df45819102db1e 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -266,6 +266,12 @@ static inline void* PyUnicode_DATA(PyObject *op) { } #define PyUnicode_DATA(op) PyUnicode_DATA(_PyObject_CAST(op)) +/* Symbol to reexport PyUnicode_DATA without needing to read the contents + of the structure directly. +*/ +PyAPI_FUNC(void *) PyUnicode_Data(PyObject *op); +PyAPI_FUNC(int) PyUnicode_GetKind(PyObject *op); + /* Return pointers to the canonical representation cast to unsigned char, Py_UCS2, or Py_UCS4 for direct character access. No checks are performed, use PyUnicode_KIND() before to ensure diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 0a569a950e88e2..d431b0de65a5b0 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3863,6 +3863,22 @@ _PyUnicode_AsUTF8NoNUL(PyObject *unicode) return s; } +void* PyUnicode_Data(PyObject *unicode) { + if (!PyUnicode_Check(unicode)) { + PyErr_BadArgument(); + return NULL; + } + return PyUnicode_DATA(unicode); +} + +int PyUnicode_GetKind(PyObject *unicode) { + if (!PyUnicode_Check(unicode)) { + PyErr_BadArgument(); + return -1; + } + return PyUnicode_KIND(unicode); +} + /* PyUnicode_GetSize() has been deprecated since Python 3.3 because it returned length of Py_UNICODE.