summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-11-04 19:54:05 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-11-04 19:54:05 (GMT)
commite30c0a1014fb8f7978f608d6c7f430842f685075 (patch)
tree09eb1d83e739f2508f81e5ddc5739ddefa001957
parent2fc507fe45e4e3cf4f332ff496a4aed9adf345d1 (diff)
downloadcpython-e30c0a1014fb8f7978f608d6c7f430842f685075.zip
cpython-e30c0a1014fb8f7978f608d6c7f430842f685075.tar.gz
cpython-e30c0a1014fb8f7978f608d6c7f430842f685075.tar.bz2
Fix gdb/libpython.py for not ready Unicode strings
_PyUnicode_CheckConsistency() checks also hash and length value for not ready Unicode strings.
-rw-r--r--Include/unicodeobject.h8
-rw-r--r--Objects/unicodeobject.c7
-rw-r--r--Tools/gdb/libpython.py5
3 files changed, 10 insertions, 10 deletions
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index 8e29f34..58c1f55 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -231,22 +231,24 @@ typedef struct {
* 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 @@ typedef struct {
* 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
index fa6563b..ef9bb03 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -328,18 +328,21 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
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
index 43a0f20..3fea68f 100644
--- a/Tools/gdb/libpython.py
+++ b/Tools/gdb/libpython.py
@@ -1123,9 +1123,6 @@ class PyUnicodeObjectPtr(PyObjectPtr):
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 @@ class PyUnicodeObjectPtr(PyObjectPtr):
# 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