diff options
author | Victor Stinner <vstinner@python.org> | 2022-05-11 22:12:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-11 22:12:42 (GMT) |
commit | d492f0ab2add26d89474b002a9a5a2da306222c5 (patch) | |
tree | f2269166c618c404b951b596c9d78417cd12c730 /Include/cpython/unicodeobject.h | |
parent | 7d3b469e475e6e52ce4f0bad7198bb05ead77b1d (diff) | |
download | cpython-d492f0ab2add26d89474b002a9a5a2da306222c5.zip cpython-d492f0ab2add26d89474b002a9a5a2da306222c5.tar.gz cpython-d492f0ab2add26d89474b002a9a5a2da306222c5.tar.bz2 |
gh-89653: Add assertions to unicodeobject.h functions (#92692)
Diffstat (limited to 'Include/cpython/unicodeobject.h')
-rw-r--r-- | Include/cpython/unicodeobject.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 4d7173f..b271b61 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -28,16 +28,22 @@ static inline int Py_UNICODE_IS_LOW_SURROGATE(Py_UCS4 ch) { // Join two surrogate characters and return a single Py_UCS4 value. static inline Py_UCS4 Py_UNICODE_JOIN_SURROGATES(Py_UCS4 high, Py_UCS4 low) { + assert(Py_UNICODE_IS_HIGH_SURROGATE(high)); + assert(Py_UNICODE_IS_LOW_SURROGATE(low)); return 0x10000 + (((high & 0x03FF) << 10) | (low & 0x03FF)); } -// High surrogate = top 10 bits added to D800 +// High surrogate = top 10 bits added to 0xD800. +// The character must be in the range [U+10000; U+10ffff]. static inline Py_UCS4 Py_UNICODE_HIGH_SURROGATE(Py_UCS4 ch) { + assert(0x10000 <= ch && ch <= 0x10ffff); return (0xD800 - (0x10000 >> 10) + (ch >> 10)); } -// Low surrogate = bottom 10 bits added to DC00 +// Low surrogate = bottom 10 bits added to 0xDC00. +// The character must be in the range [U+10000; U+10ffff]. static inline Py_UCS4 Py_UNICODE_LOW_SURROGATE(Py_UCS4 ch) { + assert(0x10000 <= ch && ch <= 0x10ffff); return (0xDC00 + (ch & 0x3FF)); } |