[Python-checkins] cpython: Check size of wchar_t using the preprocessor
victor.stinner
python-checkins at python.org
Wed Sep 28 22:34:21 CEST 2011
http://hg.python.org/cpython/rev/b021f1b03f96
changeset: 72502:b021f1b03f96
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Wed Sep 28 22:34:18 2011 +0200
summary:
Check size of wchar_t using the preprocessor
files:
Objects/unicodeobject.c | 58 ++++++++++++++---------------
1 files changed, 28 insertions(+), 30 deletions(-)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -830,36 +830,34 @@
assert(num_surrogates == 0 &&
"FindMaxCharAndNumSurrogatePairs() messed up");
- if (sizeof(wchar_t) == 2) {
- /* We can share representations and are done. */
- unicode->data.any = _PyUnicode_WSTR(unicode);
- PyUnicode_2BYTE_DATA(unicode)[_PyUnicode_WSTR_LENGTH(unicode)] = '\0';
- _PyUnicode_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode);
- _PyUnicode_STATE(unicode).kind = PyUnicode_2BYTE_KIND;
- unicode->_base.utf8 = NULL;
- unicode->_base.utf8_length = 0;
- }
- else {
- assert(sizeof(wchar_t) == 4);
-
- unicode->data.any = PyObject_MALLOC(
- 2 * (_PyUnicode_WSTR_LENGTH(unicode) + 1));
- if (!unicode->data.any) {
- PyErr_NoMemory();
- return -1;
- }
- _PyUnicode_CONVERT_BYTES(wchar_t, Py_UCS2,
- _PyUnicode_WSTR(unicode), end,
- PyUnicode_2BYTE_DATA(unicode));
- PyUnicode_2BYTE_DATA(unicode)[_PyUnicode_WSTR_LENGTH(unicode)] = '\0';
- _PyUnicode_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode);
- _PyUnicode_STATE(unicode).kind = PyUnicode_2BYTE_KIND;
- unicode->_base.utf8 = NULL;
- unicode->_base.utf8_length = 0;
- PyObject_FREE(_PyUnicode_WSTR(unicode));
- _PyUnicode_WSTR(unicode) = NULL;
- _PyUnicode_WSTR_LENGTH(unicode) = 0;
- }
+#if SIZEOF_WCHAR_T == 2
+ /* We can share representations and are done. */
+ unicode->data.any = _PyUnicode_WSTR(unicode);
+ PyUnicode_2BYTE_DATA(unicode)[_PyUnicode_WSTR_LENGTH(unicode)] = '\0';
+ _PyUnicode_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode);
+ _PyUnicode_STATE(unicode).kind = PyUnicode_2BYTE_KIND;
+ unicode->_base.utf8 = NULL;
+ unicode->_base.utf8_length = 0;
+#else
+ /* sizeof(wchar_t) == 4 */
+ unicode->data.any = PyObject_MALLOC(
+ 2 * (_PyUnicode_WSTR_LENGTH(unicode) + 1));
+ if (!unicode->data.any) {
+ PyErr_NoMemory();
+ return -1;
+ }
+ _PyUnicode_CONVERT_BYTES(wchar_t, Py_UCS2,
+ _PyUnicode_WSTR(unicode), end,
+ PyUnicode_2BYTE_DATA(unicode));
+ PyUnicode_2BYTE_DATA(unicode)[_PyUnicode_WSTR_LENGTH(unicode)] = '\0';
+ _PyUnicode_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode);
+ _PyUnicode_STATE(unicode).kind = PyUnicode_2BYTE_KIND;
+ unicode->_base.utf8 = NULL;
+ unicode->_base.utf8_length = 0;
+ PyObject_FREE(_PyUnicode_WSTR(unicode));
+ _PyUnicode_WSTR(unicode) = NULL;
+ _PyUnicode_WSTR_LENGTH(unicode) = 0;
+#endif
}
/* maxchar exeeds 16 bit, wee need 4 bytes for unicode characters */
else {
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list