summaryrefslogtreecommitdiffstats
path: root/Include/unicodeobject.h
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-09-21 22:58:32 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-09-21 22:58:32 (GMT)
commitca9381ea01211e79f5bc6078b95e177f1c04f52b (patch)
treed324c7a17fef115fc94486e76c96a031b81d1ca3 /Include/unicodeobject.h
parent5014920cb72768bc54924e55e7004e79fcad94f7 (diff)
downloadcpython-ca9381ea01211e79f5bc6078b95e177f1c04f52b.zip
cpython-ca9381ea01211e79f5bc6078b95e177f1c04f52b.tar.gz
cpython-ca9381ea01211e79f5bc6078b95e177f1c04f52b.tar.bz2
Issue #24870: Add _PyUnicodeWriter_PrepareKind() macro
Add a macro which ensures that the writer has at least the requested kind.
Diffstat (limited to 'Include/unicodeobject.h')
-rw-r--r--Include/unicodeobject.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index 33e8f19..d0e0142 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)