Commit c3c74156 authored by Victor Stinner's avatar Victor Stinner

Add _PyUnicode_DATA_ANY(op) private macro

parent a464fc14
...@@ -131,11 +131,11 @@ extern "C" { ...@@ -131,11 +131,11 @@ extern "C" {
#define _PyUnicode_GET_LENGTH(op) \ #define _PyUnicode_GET_LENGTH(op) \
(assert(PyUnicode_Check(op)), \ (assert(PyUnicode_Check(op)), \
((PyASCIIObject *)(op))->length) ((PyASCIIObject *)(op))->length)
#define _PyUnicode_DATA_ANY(op) (((PyUnicodeObject*)(op))->data.any)
/* The Unicode string has been modified: reset the hash */ /* The Unicode string has been modified: reset the hash */
#define _PyUnicode_DIRTY(op) do { _PyUnicode_HASH(op) = -1; } while (0) #define _PyUnicode_DIRTY(op) do { _PyUnicode_HASH(op) = -1; } while (0)
/* This dictionary holds all interned unicode strings. Note that references /* This dictionary holds all interned unicode strings. Note that references
to strings in this dictionary are *not* counted in the string's ob_refcnt. to strings in this dictionary are *not* counted in the string's ob_refcnt.
When the interned string reaches a refcnt of 0 the string deallocation When the interned string reaches a refcnt of 0 the string deallocation
...@@ -441,7 +441,7 @@ _PyUnicode_New(Py_ssize_t length) ...@@ -441,7 +441,7 @@ _PyUnicode_New(Py_ssize_t length)
_PyUnicode_STATE(unicode).compact = 0; _PyUnicode_STATE(unicode).compact = 0;
_PyUnicode_STATE(unicode).ready = 0; _PyUnicode_STATE(unicode).ready = 0;
_PyUnicode_STATE(unicode).ascii = 0; _PyUnicode_STATE(unicode).ascii = 0;
unicode->data.any = NULL; _PyUnicode_DATA_ANY(unicode) = NULL;
_PyUnicode_LENGTH(unicode) = 0; _PyUnicode_LENGTH(unicode) = 0;
_PyUnicode_UTF8(unicode) = NULL; _PyUnicode_UTF8(unicode) = NULL;
_PyUnicode_UTF8_LENGTH(unicode) = 0; _PyUnicode_UTF8_LENGTH(unicode) = 0;
...@@ -815,7 +815,7 @@ _PyUnicode_Ready(PyObject *obj) ...@@ -815,7 +815,7 @@ _PyUnicode_Ready(PyObject *obj)
assert(!PyUnicode_IS_COMPACT(obj)); assert(!PyUnicode_IS_COMPACT(obj));
assert(_PyUnicode_KIND(obj) == PyUnicode_WCHAR_KIND); assert(_PyUnicode_KIND(obj) == PyUnicode_WCHAR_KIND);
assert(_PyUnicode_WSTR(unicode) != NULL); assert(_PyUnicode_WSTR(unicode) != NULL);
assert(unicode->data.any == NULL); assert(_PyUnicode_DATA_ANY(unicode) == NULL);
assert(_PyUnicode_UTF8(unicode) == NULL); assert(_PyUnicode_UTF8(unicode) == NULL);
/* Actually, it should neither be interned nor be anything else: */ /* Actually, it should neither be interned nor be anything else: */
assert(_PyUnicode_STATE(unicode).interned == SSTATE_NOT_INTERNED); assert(_PyUnicode_STATE(unicode).interned == SSTATE_NOT_INTERNED);
...@@ -830,8 +830,8 @@ _PyUnicode_Ready(PyObject *obj) ...@@ -830,8 +830,8 @@ _PyUnicode_Ready(PyObject *obj)
return -1; return -1;
if (maxchar < 256) { if (maxchar < 256) {
unicode->data.any = PyObject_MALLOC(_PyUnicode_WSTR_LENGTH(unicode) + 1); _PyUnicode_DATA_ANY(unicode) = PyObject_MALLOC(_PyUnicode_WSTR_LENGTH(unicode) + 1);
if (!unicode->data.any) { if (!_PyUnicode_DATA_ANY(unicode)) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
} }
...@@ -842,7 +842,7 @@ _PyUnicode_Ready(PyObject *obj) ...@@ -842,7 +842,7 @@ _PyUnicode_Ready(PyObject *obj)
_PyUnicode_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode); _PyUnicode_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode);
_PyUnicode_STATE(unicode).kind = PyUnicode_1BYTE_KIND; _PyUnicode_STATE(unicode).kind = PyUnicode_1BYTE_KIND;
if (maxchar < 128) { if (maxchar < 128) {
_PyUnicode_UTF8(unicode) = unicode->data.any; _PyUnicode_UTF8(unicode) = _PyUnicode_DATA_ANY(unicode);
_PyUnicode_UTF8_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode); _PyUnicode_UTF8_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode);
} }
else { else {
...@@ -861,7 +861,7 @@ _PyUnicode_Ready(PyObject *obj) ...@@ -861,7 +861,7 @@ _PyUnicode_Ready(PyObject *obj)
#if SIZEOF_WCHAR_T == 2 #if SIZEOF_WCHAR_T == 2
/* We can share representations and are done. */ /* We can share representations and are done. */
unicode->data.any = _PyUnicode_WSTR(unicode); _PyUnicode_DATA_ANY(unicode) = _PyUnicode_WSTR(unicode);
PyUnicode_2BYTE_DATA(unicode)[_PyUnicode_WSTR_LENGTH(unicode)] = '\0'; PyUnicode_2BYTE_DATA(unicode)[_PyUnicode_WSTR_LENGTH(unicode)] = '\0';
_PyUnicode_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode); _PyUnicode_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode);
_PyUnicode_STATE(unicode).kind = PyUnicode_2BYTE_KIND; _PyUnicode_STATE(unicode).kind = PyUnicode_2BYTE_KIND;
...@@ -869,9 +869,9 @@ _PyUnicode_Ready(PyObject *obj) ...@@ -869,9 +869,9 @@ _PyUnicode_Ready(PyObject *obj)
_PyUnicode_UTF8_LENGTH(unicode) = 0; _PyUnicode_UTF8_LENGTH(unicode) = 0;
#else #else
/* sizeof(wchar_t) == 4 */ /* sizeof(wchar_t) == 4 */
unicode->data.any = PyObject_MALLOC( _PyUnicode_DATA_ANY(unicode) = PyObject_MALLOC(
2 * (_PyUnicode_WSTR_LENGTH(unicode) + 1)); 2 * (_PyUnicode_WSTR_LENGTH(unicode) + 1));
if (!unicode->data.any) { if (!_PyUnicode_DATA_ANY(unicode)) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
} }
...@@ -894,8 +894,8 @@ _PyUnicode_Ready(PyObject *obj) ...@@ -894,8 +894,8 @@ _PyUnicode_Ready(PyObject *obj)
/* in case the native representation is 2-bytes, we need to allocate a /* in case the native representation is 2-bytes, we need to allocate a
new normalized 4-byte version. */ new normalized 4-byte version. */
length_wo_surrogates = _PyUnicode_WSTR_LENGTH(unicode) - num_surrogates; length_wo_surrogates = _PyUnicode_WSTR_LENGTH(unicode) - num_surrogates;
unicode->data.any = PyObject_MALLOC(4 * (length_wo_surrogates + 1)); _PyUnicode_DATA_ANY(unicode) = PyObject_MALLOC(4 * (length_wo_surrogates + 1));
if (!unicode->data.any) { if (!_PyUnicode_DATA_ANY(unicode)) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
} }
...@@ -914,7 +914,7 @@ _PyUnicode_Ready(PyObject *obj) ...@@ -914,7 +914,7 @@ _PyUnicode_Ready(PyObject *obj)
#else #else
assert(num_surrogates == 0); assert(num_surrogates == 0);
unicode->data.any = _PyUnicode_WSTR(unicode); _PyUnicode_DATA_ANY(unicode) = _PyUnicode_WSTR(unicode);
_PyUnicode_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode); _PyUnicode_LENGTH(unicode) = _PyUnicode_WSTR_LENGTH(unicode);
_PyUnicode_UTF8(unicode) = NULL; _PyUnicode_UTF8(unicode) = NULL;
_PyUnicode_UTF8_LENGTH(unicode) = 0; _PyUnicode_UTF8_LENGTH(unicode) = 0;
...@@ -961,8 +961,8 @@ unicode_dealloc(register PyUnicodeObject *unicode) ...@@ -961,8 +961,8 @@ unicode_dealloc(register PyUnicodeObject *unicode)
Py_TYPE(unicode)->tp_free((PyObject *)unicode); Py_TYPE(unicode)->tp_free((PyObject *)unicode);
} }
else { else {
if (unicode->data.any) if (_PyUnicode_DATA_ANY(unicode))
PyObject_DEL(unicode->data.any); PyObject_DEL(_PyUnicode_DATA_ANY(unicode));
Py_TYPE(unicode)->tp_free((PyObject *)unicode); Py_TYPE(unicode)->tp_free((PyObject *)unicode);
} }
} }
...@@ -11657,7 +11657,7 @@ unicode__sizeof__(PyUnicodeObject *v) ...@@ -11657,7 +11657,7 @@ unicode__sizeof__(PyUnicodeObject *v)
/* If it is a two-block object, account for base object, and /* If it is a two-block object, account for base object, and
for character block if present. */ for character block if present. */
size = sizeof(PyUnicodeObject); size = sizeof(PyUnicodeObject);
if (v->data.any) if (_PyUnicode_DATA_ANY(v))
size += (PyUnicode_GET_LENGTH(v) + 1) * size += (PyUnicode_GET_LENGTH(v) + 1) *
PyUnicode_CHARACTER_SIZE(v); PyUnicode_CHARACTER_SIZE(v);
} }
...@@ -12477,7 +12477,7 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -12477,7 +12477,7 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
_PyUnicode_UTF8_LENGTH(self) = 0; _PyUnicode_UTF8_LENGTH(self) = 0;
_PyUnicode_UTF8(self) = NULL; _PyUnicode_UTF8(self) = NULL;
_PyUnicode_WSTR_LENGTH(self) = 0; _PyUnicode_WSTR_LENGTH(self) = 0;
self->data.any = NULL; _PyUnicode_DATA_ANY(self) = NULL;
share_utf8 = 0; share_utf8 = 0;
share_wstr = 0; share_wstr = 0;
...@@ -12509,7 +12509,7 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -12509,7 +12509,7 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
goto onError; goto onError;
} }
self->data.any = data; _PyUnicode_DATA_ANY(self) = data;
if (share_utf8) { if (share_utf8) {
_PyUnicode_UTF8_LENGTH(self) = length; _PyUnicode_UTF8_LENGTH(self) = length;
_PyUnicode_UTF8(self) = data; _PyUnicode_UTF8(self) = data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment