diff options
author | Victor Stinner <vstinner@python.org> | 2022-03-31 07:59:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-31 07:59:27 (GMT) |
commit | c14d7e4b816134b8e93ece4066a86d229631ce96 (patch) | |
tree | 6b2ac5b9c3e502d77d1ff05bdcc88e918dba1ad4 /Python/traceback.c | |
parent | db4dada5108dd49ebca23e4559a53630a2df8447 (diff) | |
download | cpython-c14d7e4b816134b8e93ece4066a86d229631ce96.zip cpython-c14d7e4b816134b8e93ece4066a86d229631ce96.tar.gz cpython-c14d7e4b816134b8e93ece4066a86d229631ce96.tar.bz2 |
bpo-47164: Add _PyASCIIObject_CAST() macro (GH-32191)
Add macros to cast objects to PyASCIIObject*, PyCompactUnicodeObject*
and PyUnicodeObject*: _PyASCIIObject_CAST(),
_PyCompactUnicodeObject_CAST() and _PyUnicodeObject_CAST(). Using
these new macros make the code more readable and check their argument
with: assert(PyUnicode_Check(op)).
Remove redundant assert(PyUnicode_Check(op)) in macros using directly
or indirectly these new CAST macros.
Replacing existing casts with these macros.
Diffstat (limited to 'Python/traceback.c')
-rw-r--r-- | Python/traceback.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Python/traceback.c b/Python/traceback.c index 6a721cf..f5c1849 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -1073,7 +1073,7 @@ _Py_DumpHexadecimal(int fd, uintptr_t value, Py_ssize_t width) void _Py_DumpASCII(int fd, PyObject *text) { - PyASCIIObject *ascii = (PyASCIIObject *)text; + PyASCIIObject *ascii = _PyASCIIObject_CAST(text); Py_ssize_t i, size; int truncated; int kind; @@ -1087,19 +1087,19 @@ _Py_DumpASCII(int fd, PyObject *text) size = ascii->length; kind = ascii->state.kind; if (kind == PyUnicode_WCHAR_KIND) { - wstr = ((PyASCIIObject *)text)->wstr; + wstr = ascii->wstr; if (wstr == NULL) return; - size = ((PyCompactUnicodeObject *)text)->wstr_length; + size = _PyCompactUnicodeObject_CAST(text)->wstr_length; } else if (ascii->state.compact) { if (ascii->state.ascii) - data = ((PyASCIIObject*)text) + 1; + data = ascii + 1; else - data = ((PyCompactUnicodeObject*)text) + 1; + data = _PyCompactUnicodeObject_CAST(text) + 1; } else { - data = ((PyUnicodeObject *)text)->data.any; + data = _PyUnicodeObject_CAST(text)->data.any; if (data == NULL) return; } |