diff options
| author | Victor Stinner <victor.stinner@gmail.com> | 2015-09-22 00:58:32 +0200 |
|---|---|---|
| committer | Victor Stinner <victor.stinner@gmail.com> | 2015-09-22 00:58:32 +0200 |
| commit | ca9381ea01211e79f5bc6078b95e177f1c04f52b (patch) | |
| tree | d324c7a17fef115fc94486e76c96a031b81d1ca3 /Include | |
| parent | 5014920cb72768bc54924e55e7004e79fcad94f7 (diff) | |
| download | cpython-git-ca9381ea01211e79f5bc6078b95e177f1c04f52b.tar.gz | |
Issue #24870: Add _PyUnicodeWriter_PrepareKind() macro
Add a macro which ensures that the writer has at least the requested kind.
Diffstat (limited to 'Include')
| -rw-r--r-- | Include/unicodeobject.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index 33e8f19af0..d0e0142614 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -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) |
