[Python-checkins] cpython: PyUnicode_READ_CHAR() ensures that the string is ready

victor.stinner python-checkins at python.org
Mon Oct 3 03:45:21 CEST 2011


http://hg.python.org/cpython/rev/3a0af974f1b5
changeset:   72598:3a0af974f1b5
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Sun Oct 02 20:33:18 2011 +0200
summary:
  PyUnicode_READ_CHAR() ensures that the string is ready

files:
  Include/unicodeobject.h |  18 ++++++++++--------
  1 files changed, 10 insertions(+), 8 deletions(-)


diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -429,14 +429,16 @@
    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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list