[Python-checkins] cpython: _PyUnicode_CheckConsistency() checks utf8 field consistency
victor.stinner
python-checkins at python.org
Mon Oct 3 14:51:26 CEST 2011
http://hg.python.org/cpython/rev/ec481f3f79cd
changeset: 72617:ec481f3f79cd
user: Victor Stinner <vstinner at wyplay.com>
date: Mon Oct 03 14:42:39 2011 +0200
summary:
_PyUnicode_CheckConsistency() checks utf8 field consistency
files:
Include/unicodeobject.h | 2 ++
Objects/unicodeobject.c | 6 ++++++
2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -225,6 +225,7 @@
* compact = 1
* ready = 1
* ascii = 0
+ * utf8 != data
- string created by the legacy API (not ready):
@@ -246,6 +247,7 @@
* 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().
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -293,11 +293,13 @@
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 @@
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;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list