Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions Doc/c-api/arg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@

There are three ways strings and buffers can be converted to C:

* Formats such as ``y*`` and ``s*`` fill a :c:type:`Py_buffer` structure.
* Formats such as ``"y*"`` and ``"s*"`` fill a :c:type:`Py_buffer` structure.
This locks the underlying buffer so that the caller can subsequently use
the buffer even inside a :c:type:`Py_BEGIN_ALLOW_THREADS`
block without the risk of mutable data being resized or destroyed.
As a result, **you have to call** :c:func:`PyBuffer_Release` after you have
finished processing the data (or in any early abort case).

* The ``es``, ``es#``, ``et`` and ``et#`` formats allocate the result buffer.
**You have to call** :c:func:`PyMem_Free` after you have finished
* The ``"es"``, ``"es#"``, ``"et"`` and ``"et#"`` formats allocate the result
buffer. **You have to call** :c:func:`PyMem_Free` after you have finished
processing the data (or in any early abort case).

* .. _c-arg-borrowed-buffer:
Expand All @@ -77,7 +77,7 @@
whether the input object is immutable (e.g. whether it would honor a request
for a writable buffer, or whether another thread can mutate the data).

``s`` (:class:`str`) [const char \*]
``"s"`` (:c:type:`PyUnicodeObject\*`) [:c:type:`const char\*`]

Check warning on line 80 in Doc/c-api/arg.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

Unparseable C cross-reference: 'PyUnicodeObject*'

Check warning on line 80 in Doc/c-api/arg.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

c:type reference target not found: PyUnicodeObject* [ref.type]

Check warning on line 80 in Doc/c-api/arg.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

Unparseable C cross-reference: 'const char*'

Check warning on line 80 in Doc/c-api/arg.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

c:type reference target not found: const char* [ref.type]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are warnings if you look at the Files Changes tab. Examples:

  • Unparseable C cross-reference: 'PyUnicodeObject*'
  • Unparseable C cross-reference: 'const char*'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, a lot has changed since your patch

Convert a Unicode object to a C pointer to a character string.
A pointer to an existing string is stored in the character pointer
variable whose address you pass. The C string is NUL-terminated.
Expand All @@ -90,43 +90,43 @@
This format does not accept :term:`bytes-like objects
<bytes-like object>`. If you want to accept
filesystem paths and convert them to C character strings, it is
preferable to use the ``O&`` format with :c:func:`PyUnicode_FSConverter`
preferable to use the ``"O&"`` format with :c:func:`PyUnicode_FSConverter`
as *converter*.

.. versionchanged:: 3.5
Previously, :exc:`TypeError` was raised when embedded null code points
were encountered in the Python string.

``s*`` (:class:`str` or :term:`bytes-like object`) [Py_buffer]
``"s*"`` (:c:type:`PyUnicodeObject\*`, :c:type:`PyBytesObject\*`, :c:type:`PyByteArrayObject\*` or :term:`bytes-like object`) [:c:type:`Py_buffer`]

Check warning on line 100 in Doc/c-api/arg.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

Unparseable C cross-reference: 'PyUnicodeObject*'

Check warning on line 100 in Doc/c-api/arg.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

c:type reference target not found: PyUnicodeObject* [ref.type]

Check warning on line 100 in Doc/c-api/arg.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

Unparseable C cross-reference: 'PyBytesObject*'

Check warning on line 100 in Doc/c-api/arg.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

c:type reference target not found: PyBytesObject* [ref.type]

Check warning on line 100 in Doc/c-api/arg.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

Unparseable C cross-reference: 'PyByteArrayObject*'

Check warning on line 100 in Doc/c-api/arg.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

c:type reference target not found: PyByteArrayObject* [ref.type]
This format accepts Unicode objects as well as bytes-like objects.
It fills a :c:type:`Py_buffer` structure provided by the caller.
In this case the resulting C string may contain embedded NUL bytes.
Unicode objects are converted to C strings using ``'utf-8'`` encoding.

``s#`` (:class:`str`, read-only :term:`bytes-like object`) [const char \*, :c:type:`Py_ssize_t`]
Like ``s*``, except that it provides a :ref:`borrowed buffer <c-arg-borrowed-buffer>`.
``"s#"`` (:c:type:`PyUnicodeObject\*`, :c:type:`PyBytesObject\*` or read-only :term:`bytes-like object`) [:c:type:`const char\*`, :c:type:`int` or :c:type:`Py_ssize_t`]
Like ``"s*"``, except that it provides a :ref:`borrowed buffer <c-arg-borrowed-buffer>`.
The result is stored into two C variables,
the first one a pointer to a C string, the second one its length.
The string may contain embedded null bytes. Unicode objects are converted
to C strings using ``'utf-8'`` encoding.

``z`` (:class:`str` or ``None``) [const char \*]
Like ``s``, but the Python object may also be ``None``, in which case the C
pointer is set to ``NULL``.
It is the same as ``s?`` with the C pointer was initialized to ``NULL``.
``"z"`` (:c:type:`PyUnicodeObject\*` or :c:type:`Py_None`) [:c:type:`const char\*`]
Like ``"s"``, but the Python object may also be :c:type:`Py_None`,
in which case the C pointer is set to ``NULL``.
It is the same as ``"s?"`` with the C pointer was initialized to ``NULL``.

``z*`` (:class:`str`, :term:`bytes-like object` or ``None``) [Py_buffer]
Like ``s*``, but the Python object may also be ``None``, in which case the
``"z*"`` (:c:type:`PyUnicodeObject\*`, :c:type:`PyBytesObject\*`, :c:type:`PyByteArrayObject\*`, :term:`bytes-like object`, or :c:type:`Py_None`) [:c:type:`Py_buffer`]
Like ``"s*"``, but the Python object may also be :c:type:`Py_None`, in which case the
``buf`` member of the :c:type:`Py_buffer` structure is set to ``NULL``.
It is the same as ``s*?`` with the ``buf`` member of the :c:type:`Py_buffer`
It is the same as ``"s*?"`` with the ``buf`` member of the :c:type:`Py_buffer`
structure was initialized to ``NULL``.

``z#`` (:class:`str`, read-only :term:`bytes-like object` or ``None``) [const char \*, :c:type:`Py_ssize_t`]
Like ``s#``, but the Python object may also be ``None``, in which case the C
pointer is set to ``NULL``.
It is the same as ``s#?`` with the C pointer was initialized to ``NULL``.
``"z#"`` (:c:type:`PyUnicodeObject\*`, :c:type:`PyBytesObject\*`, read-only :term:`bytes-like object` or :c:type:`Py_None`) [:c:type:`const char\*`, :c:type:`int`]
Like ``"s#"``, but the Python object may also be :c:type:`Py_None`, in which
case the C pointer is set to ``NULL``.
It is the same as ``"s#?"`` with the C pointer was initialized to ``NULL``.

``y`` (read-only :term:`bytes-like object`) [const char \*]
``"y"`` (:c:type:`PyBytesObject\*` or read-only :term:`bytes-like object`) [:c:type:`const char\*`]
This format converts a bytes-like object to a C pointer to a
:ref:`borrowed <c-arg-borrowed-buffer>` character string;
it does not accept Unicode objects. The bytes buffer must not
Expand All @@ -137,8 +137,8 @@
Previously, :exc:`TypeError` was raised when embedded null bytes were
encountered in the bytes buffer.

``y*`` (:term:`bytes-like object`) [Py_buffer]
This variant on ``s*`` doesn't accept Unicode objects, only
``"y*"`` (:c:type:`PyBytesObject\*`, :c:type:`PyByteArrayObject\*`, or :term:`bytes-like object`) [:c:type:`Py_buffer\*`]
This variant on ``"s*"`` doesn't accept Unicode objects, only
bytes-like objects. **This is the recommended way to accept
binary data.**

Expand Down
Loading