@@ -338,16 +338,21 @@ APIs:
338338
339339.. c :function :: Py_UNICODE* PyUnicode_AsUnicode (PyObject *unicode)
340340
341- Return a read-only pointer to the Unicode object's internal :c:type: `Py_UNICODE `
342- buffer, *NULL * if *unicode * is not a Unicode object.
341+ Return a read-only pointer to the Unicode object's internal
342+ :c:type: `Py_UNICODE ` buffer, *NULL * if *unicode * is not a Unicode object.
343+ Note that the resulting :c:type: `Py_UNICODE* ` string may contain embedded
344+ null characters, which would cause the string to be truncated when used in
345+ most C functions.
343346
344347
345348.. c :function :: Py_UNICODE* PyUnicode_AsUnicodeCopy (PyObject *unicode)
346349
347350 Create a copy of a Unicode string ending with a nul character. Return *NULL *
348351 and raise a :exc: `MemoryError ` exception on memory allocation failure,
349- otherwise return a new allocated buffer (use :c:func: `PyMem_Free ` to free the
350- buffer).
352+ otherwise return a new allocated buffer (use :c:func: `PyMem_Free ` to free
353+ the buffer). Note that the resulting :c:type:`Py_UNICODE*` string may contain
354+ embedded null characters, which would cause the string to be truncated when
355+ used in most C functions.
351356
352357 .. versionadded:: 3.2
353358
@@ -447,7 +452,8 @@ used, passing :c:func:`PyUnicode_FSDecoder` as the conversion function:
447452
448453 Encode a Unicode object to :c:data: `Py_FileSystemDefaultEncoding ` with the
449454 ``'surrogateescape' `` error handler, or ``'strict' `` on Windows, and return
450- :class: `bytes `.
455+ :class: `bytes `. Note that the resulting :class: `bytes ` object may contain
456+ null bytes.
451457
452458 If :c:data: `Py_FileSystemDefaultEncoding ` is not set, fall back to the
453459 locale encoding.
@@ -476,7 +482,9 @@ wchar_t Support
476482 copied or -1 in case of an error. Note that the resulting :c:type:`wchar_t`
477483 string may or may not be 0-terminated. It is the responsibility of the caller
478484 to make sure that the :c:type:`wchar_t` string is 0-terminated in case this is
479- required by the application.
485+ required by the application. Also, note that the :c:type:`wchar_t*` string
486+ might contain null characters, which would cause the string to be truncated
487+ when used with most C functions.
480488
481489
482490.. c:function:: wchar_t* PyUnicode_AsWideCharString(PyObject *unicode, Py_ssize_t *size)
@@ -486,9 +494,11 @@ wchar_t Support
486494 of wide characters (excluding the trailing 0-termination character) into
487495 *\*size*.
488496
489- Returns a buffer allocated by :c:func:`PyMem_Alloc` (use :c:func: `PyMem_Free `
490- to free it) on success. On error, returns *NULL*, *\*size* is undefined and
491- raises a :exc:`MemoryError`.
497+ Returns a buffer allocated by :c:func:`PyMem_Alloc` (use
498+ :c:func: `PyMem_Free ` to free it) on success. On error, returns *NULL*,
499+ *\*size* is undefined and raises a :exc:`MemoryError`. Note that the
500+ resulting :c:type:`wchar_t*` string might contain null characters, which
501+ would cause the string to be truncated when used with most C functions.
492502
493503 .. versionadded:: 3.2
494504
0 commit comments