]> granicus.if.org Git - python/commitdiff
_PyUnicode_CheckConsistency() checks utf8 field consistency
authorVictor Stinner <vstinner@wyplay.com>
Mon, 3 Oct 2011 12:42:39 +0000 (14:42 +0200)
committerVictor Stinner <vstinner@wyplay.com>
Mon, 3 Oct 2011 12:42:39 +0000 (14:42 +0200)
Include/unicodeobject.h
Objects/unicodeobject.c

index d7c9fa773c7652e21da029c6324cd854bc03c904..1b6d1c94e12745d7608a3059f550b14fd61af43f 100644 (file)
@@ -225,6 +225,7 @@ typedef struct {
          * compact = 1
          * ready = 1
          * ascii = 0
+         * utf8 != data
 
        - string created by the legacy API (not ready):
 
@@ -246,6 +247,7 @@ typedef struct {
          * compact = 0
          * ready = 1
          * data.any is not NULL
+         * utf8 = data if ascii is 1
 
        String created by the legacy API becomes ready when calling
        PyUnicode_READY().
index c3e1f290e1231b8cdfe56ecdfe509b0becd9ddec..1d90f69be06deb74e59960c4572025248c76c58f 100644 (file)
@@ -293,11 +293,13 @@ _PyUnicode_CheckConsistency(void *op)
         assert(ascii->state.ready == 1);
     }
     else if (ascii->state.compact == 1) {
+        PyCompactUnicodeObject *compact = (PyCompactUnicodeObject *)op;
         assert(kind == PyUnicode_1BYTE_KIND
                || kind == PyUnicode_2BYTE_KIND
                || kind == PyUnicode_4BYTE_KIND);
         assert(ascii->state.ascii == 0);
         assert(ascii->state.ready == 1);
+        assert (compact->utf8 != (void*)(compact + 1));
     } else {
         PyCompactUnicodeObject *compact = (PyCompactUnicodeObject *)op;
         PyUnicodeObject *unicode = (PyUnicodeObject *)op;
@@ -318,6 +320,10 @@ _PyUnicode_CheckConsistency(void *op)
             assert(ascii->state.compact == 0);
             assert(ascii->state.ready == 1);
             assert(unicode->data.any != NULL);
+            if (ascii->state.ascii)
+                assert (compact->utf8 == unicode->data.any);
+            else
+                assert (compact->utf8 != unicode->data.any);
         }
     }
     return 1;