summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatus Valo <matusvalo@users.noreply.github.com>2022-12-08 09:23:58 +0100
committerGitHub <noreply@github.com>2022-12-08 09:23:58 +0100
commit3b1597ce99b9534bccc644c3bdf4fa2b54267e92 (patch)
tree2290352d1cb9dda92f1b66897429b79ff3941996
parent011c19875b68ea79c583b6d6c238694777cddd0c (diff)
downloadcython-3b1597ce99b9534bccc644c3bdf4fa2b54267e92.tar.gz
Add PyUnicode_AsUTF8AndSize to cpython imports [0.29.x] (#5164)
Backport of https://github.com/cython/cython/pull/5163
-rw-r--r--Cython/Includes/cpython/unicode.pxd18
1 files changed, 17 insertions, 1 deletions
diff --git a/Cython/Includes/cpython/unicode.pxd b/Cython/Includes/cpython/unicode.pxd
index ad01ed64d..2072c8cb2 100644
--- a/Cython/Includes/cpython/unicode.pxd
+++ b/Cython/Includes/cpython/unicode.pxd
@@ -314,9 +314,25 @@ cdef extern from *:
# raised by the codec.
bytes PyUnicode_EncodeUTF8(Py_UNICODE *s, Py_ssize_t size, char *errors)
- # Encode a Unicode objects using UTF-8 and return the result as Python string object. Error handling is ``strict''. Return NULL if an exception was raised by the codec.
+ # Encode a Unicode objects using UTF-8 and return the result as Python bytes object. Error handling is ``strict''. Return NULL if an exception was raised by the codec.
bytes PyUnicode_AsUTF8String(object unicode)
+
+ # Return a pointer to the UTF-8 encoding of the Unicode object,
+ # and store the size of the encoded representation (in bytes) in size.
+ # The size argument can be NULL; in this case no size will be stored.
+ # The returned buffer always has an extra null byte appended
+ # (not included in size), regardless of whether there are any
+ # other null code points.
+
+ # In the case of an error, NULL is returned with an exception set and
+ # no size is stored.
+
+ # This caches the UTF-8 representation of the string in the Unicode
+ # object, and subsequent calls will return a pointer to the same buffer.
+ # The caller is not responsible for deallocating the buffer
+ const char* PyUnicode_AsUTF8AndSize(object unicode, Py_ssize_t *size)
+
# These are the UTF-16 codec APIs:
# Decode length bytes from a UTF-16 encoded buffer string and