From: Victor Stinner Date: Sun, 2 Oct 2011 18:33:18 +0000 (+0200) Subject: PyUnicode_READ_CHAR() ensures that the string is ready X-Git-Tag: v3.3.0a1~1384 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=37943769ef7594c9fb6a0c23ff4094376b49c3ea;p=python PyUnicode_READ_CHAR() ensures that the string is ready --- diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index 314dee455b..99dcdd8b77 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -429,14 +429,16 @@ PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type; PyUnicode_READ_CHAR, for multiple consecutive reads callers should cache kind and use PyUnicode_READ instead. */ #define PyUnicode_READ_CHAR(unicode, index) \ - ((Py_UCS4) \ - (PyUnicode_KIND((unicode)) == PyUnicode_1BYTE_KIND ? \ - ((const Py_UCS1 *)(PyUnicode_DATA((unicode))))[(index)] : \ - (PyUnicode_KIND((unicode)) == PyUnicode_2BYTE_KIND ? \ - ((const Py_UCS2 *)(PyUnicode_DATA((unicode))))[(index)] : \ - ((const Py_UCS4 *)(PyUnicode_DATA((unicode))))[(index)] \ - ) \ - )) + (assert(PyUnicode_Check(unicode)), \ + assert(PyUnicode_IS_READY(unicode)), \ + (Py_UCS4) \ + (PyUnicode_KIND((unicode)) == PyUnicode_1BYTE_KIND ? \ + ((const Py_UCS1 *)(PyUnicode_DATA((unicode))))[(index)] : \ + (PyUnicode_KIND((unicode)) == PyUnicode_2BYTE_KIND ? \ + ((const Py_UCS2 *)(PyUnicode_DATA((unicode))))[(index)] : \ + ((const Py_UCS4 *)(PyUnicode_DATA((unicode))))[(index)] \ + ) \ + )) /* Returns the length of the unicode string. The caller has to make sure that the string has it's canonical representation set before calling