[Python-checkins] cpython: Fix gdb/libpython.py for not ready Unicode strings

victor.stinner python-checkins at python.org
Fri Nov 4 20:52:33 CET 2011


http://hg.python.org/cpython/rev/b3543ef9b445
changeset:   73356:b3543ef9b445
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Fri Nov 04 20:54:05 2011 +0100
summary:
  Fix gdb/libpython.py for not ready Unicode strings

_PyUnicode_CheckConsistency() checks also hash and length value for not ready
Unicode strings.

files:
  Include/unicodeobject.h |  8 +++++---
  Objects/unicodeobject.c |  7 +++++--
  Tools/gdb/libpython.py  |  5 -----
  3 files changed, 10 insertions(+), 10 deletions(-)


diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -231,22 +231,24 @@
          * utf8_length = 0 if utf8 is NULL
          * wstr is shared with data and wstr_length=length
            if kind=PyUnicode_2BYTE_KIND and sizeof(wchar_t)=2
-           or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_4)=4
+           or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_t)=4
          * wstr_length = 0 if wstr is NULL
          * (data starts just after the structure)
 
        - legacy string, not ready:
 
          * structure = PyUnicodeObject
+         * length = 0 (use wstr_length)
+         * hash = -1
          * kind = PyUnicode_WCHAR_KIND
          * compact = 0
          * ascii = 0
          * ready = 0
+         * interned = SSTATE_NOT_INTERNED
          * wstr is not NULL
          * data.any is NULL
          * utf8 is NULL
          * utf8_length = 0
-         * interned = SSTATE_NOT_INTERNED
 
        - legacy string, ready:
 
@@ -258,7 +260,7 @@
          * data.any is not NULL
          * utf8 is shared and utf8_length = length with data.any if ascii = 1
          * utf8_length = 0 if utf8 is NULL
-         * wstr is shared and wstr_length = length with data.any
+         * wstr is shared with data.any and wstr_length = length
            if kind=PyUnicode_2BYTE_KIND and sizeof(wchar_t)=2
            or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_4)=4
          * wstr_length = 0 if wstr is NULL
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -328,18 +328,21 @@
             assert(ascii->state.ascii == 0);
             assert(ascii->state.ready == 1);
             assert (compact->utf8 != data);
-        } else {
+        }
+        else {
             PyUnicodeObject *unicode = (PyUnicodeObject *)op;
 
             data = unicode->data.any;
             if (kind == PyUnicode_WCHAR_KIND) {
+                assert(ascii->length == 0);
+                assert(ascii->hash == -1);
                 assert(ascii->state.compact == 0);
                 assert(ascii->state.ascii == 0);
                 assert(ascii->state.ready == 0);
+                assert(ascii->state.interned == SSTATE_NOT_INTERNED);
                 assert(ascii->wstr != NULL);
                 assert(data == NULL);
                 assert(compact->utf8 == NULL);
-                assert(ascii->state.interned == SSTATE_NOT_INTERNED);
             }
             else {
                 assert(kind == PyUnicode_1BYTE_KIND
diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py
--- a/Tools/gdb/libpython.py
+++ b/Tools/gdb/libpython.py
@@ -1123,9 +1123,6 @@
         return _type_Py_UNICODE.sizeof
 
     def proxyval(self, visited):
-        # From unicodeobject.h:
-        #     Py_ssize_t length;  /* Length of raw Unicode data in buffer */
-        #     Py_UNICODE *str;    /* Raw Unicode buffer */
         if _is_pep393:
             # Python 3.3 and newer
             may_have_surrogates = False
@@ -1138,8 +1135,6 @@
                 # string is not ready
                 may_have_surrogates = True
                 field_str = ascii['wstr']
-                if not is_compact_ascii:
-                    field_length = compact('wstr_length')
             else:
                 if is_compact_ascii:
                     field_str = ascii.address + 1

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


More information about the Python-checkins mailing list