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:
Victor Stinner 2015-09-22 00:58:32 +02:00
parent 5014920cb7
commit ca9381ea01
2 changed files with 46 additions and 9 deletions

View file

@ -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)