summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-10-03 21:45:12 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-10-03 21:45:12 (GMT)
commit03490918b7810341b7cdf53e5a45798ad4b6c61e (patch)
tree6132cc3f1a27a536d439387b92fc1f9ec8574941
parent9ce5a835bbb33c8a7f22e8ab4c6c226ecb27b0be (diff)
downloadcpython-03490918b7810341b7cdf53e5a45798ad4b6c61e.zip
cpython-03490918b7810341b7cdf53e5a45798ad4b6c61e.tar.gz
cpython-03490918b7810341b7cdf53e5a45798ad4b6c61e.tar.bz2
Add _PyUnicode_HAS_WSTR_MEMORY() macro
-rw-r--r--Objects/unicodeobject.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 6aebdc0..77cc082 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -151,6 +151,14 @@ extern "C" {
&& _PyUnicode_UTF8(op) \
&& _PyUnicode_UTF8(op) != PyUnicode_DATA(op)))
+/* true if the Unicode object has an allocated wstr memory block
+ (not shared with other data) */
+#define _PyUnicode_HAS_WSTR_MEMORY(op) \
+ (assert(_PyUnicode_CHECK(op)), \
+ (_PyUnicode_WSTR(op) && \
+ (!PyUnicode_IS_READY(op) || \
+ _PyUnicode_WSTR(op) != PyUnicode_DATA(op))))
+
/* Generic helper macro to convert characters of different types.
from_type and to_type have to be valid type names, begin and end
are pointers to the source characters which should be of type
@@ -1238,9 +1246,7 @@ unicode_dealloc(register PyUnicodeObject *unicode)
Py_FatalError("Inconsistent interned string state.");
}
- if (_PyUnicode_WSTR(unicode) &&
- (!PyUnicode_IS_READY(unicode) ||
- _PyUnicode_WSTR(unicode) != PyUnicode_DATA(unicode)))
+ if (_PyUnicode_HAS_WSTR_MEMORY(unicode))
PyObject_DEL(_PyUnicode_WSTR(unicode));
if (_PyUnicode_HAS_UTF8_MEMORY(unicode))
PyObject_DEL(_PyUnicode_UTF8(unicode));
@@ -12061,8 +12067,7 @@ unicode__sizeof__(PyUnicodeObject *v)
}
/* If the wstr pointer is present, account for it unless it is shared
with the data pointer. Check if the data is not shared. */
- if (_PyUnicode_WSTR(v) &&
- (PyUnicode_DATA(v) != _PyUnicode_WSTR(v)))
+ if (_PyUnicode_HAS_WSTR_MEMORY(v))
size += (PyUnicode_WSTR_LENGTH(v) + 1) * sizeof(wchar_t);
if (_PyUnicode_HAS_UTF8_MEMORY(v))
size += PyUnicode_UTF8_LENGTH(v) + 1;