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

victor.stinner python-checkins at python.org
Mon Dec 12 01:25:58 CET 2011


http://hg.python.org/cpython/rev/d36c4ec5342b
changeset:   73939:d36c4ec5342b
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Mon Dec 12 01:24:20 2011 +0100
summary:
  PyUnicode_IS_ASCII() macro ensures that the string is ready

It has no sense to check if a not ready string is ASCII or not.

files:
  Include/unicodeobject.h |  12 +++++++-----
  1 files changed, 7 insertions(+), 5 deletions(-)


diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -424,10 +424,12 @@
 #define SSTATE_INTERNED_IMMORTAL 2
 
 /* Return true if the string contains only ASCII characters, or 0 if not. The
-   string may be compact (PyUnicode_IS_COMPACT_ASCII) or not. No type checks
-   or Ready calls are performed. */
-#define PyUnicode_IS_ASCII(op)                 \
-    (((PyASCIIObject*)op)->state.ascii)
+   string may be compact (PyUnicode_IS_COMPACT_ASCII) or not, but must be
+   ready. */
+#define PyUnicode_IS_ASCII(op)                   \
+    (assert(PyUnicode_Check(op)),                \
+     assert(PyUnicode_IS_READY(op)),             \
+     ((PyASCIIObject*)op)->state.ascii)
 
 /* Return true if the string is compact or 0 if not.
    No type checks or Ready calls are performed. */
@@ -437,7 +439,7 @@
 /* Return true if the string is a compact ASCII string (use PyASCIIObject
    structure), or 0 if not.  No type checks or Ready calls are performed. */
 #define PyUnicode_IS_COMPACT_ASCII(op)                 \
-    (PyUnicode_IS_ASCII(op) && PyUnicode_IS_COMPACT(op))
+    (((PyASCIIObject*)op)->state.ascii && PyUnicode_IS_COMPACT(op))
 
 enum PyUnicode_Kind {
 /* String contains only wstr byte characters.  This is only possible

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


More information about the Python-checkins mailing list