From fe0c155c4fbcc9b5e9fa94bc1ada88287c7cc6e8 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 3 Oct 2011 02:59:31 +0200 Subject: [PATCH] Write _PyUnicode_Dump() to help debugging --- Objects/unicodeobject.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 8f710bd29d2..00572a79836 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -515,6 +515,29 @@ void *_PyUnicode_data(void *unicode){ printf("compact data %p\n", _PyUnicode_COMPACT_DATA(unicode)); return PyUnicode_DATA(unicode); } + +void +_PyUnicode_Dump(PyObject *op) +{ + PyASCIIObject *ascii = (PyASCIIObject *)op; + printf("%s: len=%zu, wstr=%p", + unicode_kind_name(op), + ascii->length, + ascii->wstr); + if (!ascii->state.ascii) { + PyCompactUnicodeObject *compact = (PyCompactUnicodeObject *)op; + printf(" (%zu), utf8=%p (%zu)", + compact->wstr_length, + compact->utf8, + compact->utf8_length); + } + if (!ascii->state.compact) { + PyUnicodeObject *unicode = (PyUnicodeObject *)op; + printf(", data=%p", + unicode->data.any); + } + printf("\n"); +} #endif PyObject *