# HG changeset patch # Parent 3de678cd184d943f53e9bc0e74feefaa07cc7f55 Document that the UTF-8 representation is null-terminated diff -r 3de678cd184d Doc/c-api/bytes.rst --- a/Doc/c-api/bytes.rst Thu Dec 18 23:47:55 2014 +0100 +++ b/Doc/c-api/bytes.rst Tue Mar 10 10:45:12 2015 +0000 @@ -136,8 +136,9 @@ .. c:function:: char* PyBytes_AsString(PyObject *o) - Return a NUL-terminated representation of the contents of *o*. The pointer - refers to the internal buffer of *o*, not a copy. The data must not be + Return the contents of *o*. The pointer refers to the internal + buffer of *o*. The buffer always has an extra NUL byte appended, + even when the string already contains NULs. The data must not be modified in any way, unless the string was just created using ``PyBytes_FromStringAndSize(NULL, size)``. It must not be deallocated. If *o* is not a string object at all, :c:func:`PyBytes_AsString` returns *NULL* diff -r 3de678cd184d Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst Thu Dec 18 23:47:55 2014 +0100 +++ b/Doc/c-api/unicode.rst Tue Mar 10 10:45:12 2015 +0000 @@ -1045,9 +1045,11 @@ .. c:function:: char* PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *size) - Return a pointer to the default encoding (UTF-8) of the Unicode object, and - store the size of the encoded representation (in bytes) in *size*. *size* - can be *NULL*, in this case no size will be stored. + 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 NUL byte appended (not included in + *size*), even when the string already contains NULs. In the case of an error, *NULL* is returned with an exception set and no *size* is stored.