diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-02 18:33:18 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-02 18:33:18 (GMT) |
commit | 37943769ef7594c9fb6a0c23ff4094376b49c3ea (patch) | |
tree | 6ea2efd59b4976dc902a22f814e25c3383947ec9 /Include | |
parent | fe0c155c4fbcc9b5e9fa94bc1ada88287c7cc6e8 (diff) | |
download | cpython-37943769ef7594c9fb6a0c23ff4094376b49c3ea.zip cpython-37943769ef7594c9fb6a0c23ff4094376b49c3ea.tar.gz cpython-37943769ef7594c9fb6a0c23ff4094376b49c3ea.tar.bz2 |
PyUnicode_READ_CHAR() ensures that the string is ready
Diffstat (limited to 'Include')
-rw-r--r-- | Include/unicodeobject.h | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index 314dee4..99dcdd8 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 |