mirror of
https://github.com/python/cpython.git
synced 2025-07-15 15:25:29 +00:00
Issue #24870: Add _PyUnicodeWriter_PrepareKind() macro
Add a macro which ensures that the writer has at least the requested kind.
This commit is contained in:
parent
5014920cb7
commit
ca9381ea01
2 changed files with 46 additions and 9 deletions
|
@ -942,6 +942,23 @@ PyAPI_FUNC(int)
|
|||
_PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
|
||||
Py_ssize_t length, Py_UCS4 maxchar);
|
||||
|
||||
/* Prepare the buffer to have at least the kind KIND.
|
||||
For example, kind=PyUnicode_2BYTE_KIND ensures that the writer will
|
||||
support characters in range U+000-U+FFFF.
|
||||
|
||||
Return 0 on success, raise an exception and return -1 on error. */
|
||||
#define _PyUnicodeWriter_PrepareKind(WRITER, KIND) \
|
||||
(assert((KIND) != PyUnicode_WCHAR_KIND), \
|
||||
(KIND) <= (WRITER)->kind \
|
||||
? 0 \
|
||||
: _PyUnicodeWriter_PrepareKindInternal((WRITER), (KIND)))
|
||||
|
||||
/* Don't call this function directly, use the _PyUnicodeWriter_PrepareKind()
|
||||
macro instead. */
|
||||
PyAPI_FUNC(int)
|
||||
_PyUnicodeWriter_PrepareKindInternal(_PyUnicodeWriter *writer,
|
||||
enum PyUnicode_Kind kind);
|
||||
|
||||
/* Append a Unicode character.
|
||||
Return 0 on success, raise an exception and return -1 on error. */
|
||||
PyAPI_FUNC(int)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue