Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e30c0a1

Browse files
author
Victor Stinner
committed
Fix gdb/libpython.py for not ready Unicode strings
_PyUnicode_CheckConsistency() checks also hash and length value for not ready Unicode strings.
1 parent 2fc507f commit e30c0a1

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

Include/unicodeobject.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,24 @@ typedef struct {
231231
* utf8_length = 0 if utf8 is NULL
232232
* wstr is shared with data and wstr_length=length
233233
if kind=PyUnicode_2BYTE_KIND and sizeof(wchar_t)=2
234-
or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_4)=4
234+
or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_t)=4
235235
* wstr_length = 0 if wstr is NULL
236236
* (data starts just after the structure)
237237
238238
- legacy string, not ready:
239239
240240
* structure = PyUnicodeObject
241+
* length = 0 (use wstr_length)
242+
* hash = -1
241243
* kind = PyUnicode_WCHAR_KIND
242244
* compact = 0
243245
* ascii = 0
244246
* ready = 0
247+
* interned = SSTATE_NOT_INTERNED
245248
* wstr is not NULL
246249
* data.any is NULL
247250
* utf8 is NULL
248251
* utf8_length = 0
249-
* interned = SSTATE_NOT_INTERNED
250252
251253
- legacy string, ready:
252254
@@ -258,7 +260,7 @@ typedef struct {
258260
* data.any is not NULL
259261
* utf8 is shared and utf8_length = length with data.any if ascii = 1
260262
* utf8_length = 0 if utf8 is NULL
261-
* wstr is shared and wstr_length = length with data.any
263+
* wstr is shared with data.any and wstr_length = length
262264
if kind=PyUnicode_2BYTE_KIND and sizeof(wchar_t)=2
263265
or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_4)=4
264266
* wstr_length = 0 if wstr is NULL

Objects/unicodeobject.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,21 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
328328
assert(ascii->state.ascii == 0);
329329
assert(ascii->state.ready == 1);
330330
assert (compact->utf8 != data);
331-
} else {
331+
}
332+
else {
332333
PyUnicodeObject *unicode = (PyUnicodeObject *)op;
333334

334335
data = unicode->data.any;
335336
if (kind == PyUnicode_WCHAR_KIND) {
337+
assert(ascii->length == 0);
338+
assert(ascii->hash == -1);
336339
assert(ascii->state.compact == 0);
337340
assert(ascii->state.ascii == 0);
338341
assert(ascii->state.ready == 0);
342+
assert(ascii->state.interned == SSTATE_NOT_INTERNED);
339343
assert(ascii->wstr != NULL);
340344
assert(data == NULL);
341345
assert(compact->utf8 == NULL);
342-
assert(ascii->state.interned == SSTATE_NOT_INTERNED);
343346
}
344347
else {
345348
assert(kind == PyUnicode_1BYTE_KIND

Tools/gdb/libpython.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,6 @@ def char_width(self):
11231123
return _type_Py_UNICODE.sizeof
11241124

11251125
def proxyval(self, visited):
1126-
# From unicodeobject.h:
1127-
# Py_ssize_t length; /* Length of raw Unicode data in buffer */
1128-
# Py_UNICODE *str; /* Raw Unicode buffer */
11291126
if _is_pep393:
11301127
# Python 3.3 and newer
11311128
may_have_surrogates = False
@@ -1138,8 +1135,6 @@ def proxyval(self, visited):
11381135
# string is not ready
11391136
may_have_surrogates = True
11401137
field_str = ascii['wstr']
1141-
if not is_compact_ascii:
1142-
field_length = compact('wstr_length')
11431138
else:
11441139
if is_compact_ascii:
11451140
field_str = ascii.address + 1

0 commit comments

Comments
 (0)