Skip to content

Commit

Permalink
rename to PyUnicode_EXPORT_ALLOW_COPY
Browse files Browse the repository at this point in the history
Pass flags in requested_formats.
  • Loading branch information
vstinner committed Sep 23, 2024
1 parent b94da87 commit 064dd74
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions peps/pep-0756.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ Add the following API to the limited C API version 3.14::
int32_t PyUnicode_Export(
PyObject *unicode,
int32_t requested_formats,
uint32_t flags,
Py_buffer *view);
PyObject* PyUnicode_Import(
const void *data,
Expand All @@ -110,7 +109,6 @@ API::
int32_t PyUnicode_Export(
PyObject *unicode,
int32_t requested_formats,
uint32_t flags,
Py_buffer *view)

Export the contents of the *unicode* string in one of the *requested_formats*.
Expand Down Expand Up @@ -152,23 +150,22 @@ flags.

Note that future versions of Python may introduce additional formats.

By default, if the ``PyUnicode_EXPORT_COPY`` flag is not set in
*flags*, no memory is copied and no conversion is done.
By default, no memory is copied and no conversion is done.

If the ``PyUnicode_EXPORT_COPY`` flag is set in *flags*, the function
can copy memory to provide the requested format and convert from a format
to another.
If the ``PyUnicode_EXPORT_ALLOW_COPY`` flag is set in
*requested_formats*, the function can copy memory to provide the
requested format and convert from a format to another.

The ``PyUnicode_EXPORT_COPY`` flag is needed to export to
The ``PyUnicode_EXPORT_ALLOW_COPY`` flag is needed to export to
``PyUnicode_FORMAT_UTF8`` a string containing surrogate characters.

Available flags:

========================= ======== ===================================
Flag Value Description
========================= ======== ===================================
``PyUnicode_EXPORT_COPY`` ``0x01`` Allow memory copies and conversions
========================= ======== ===================================
=============================== ============ ===================================
Flag Value Description
=============================== ============ ===================================
``PyUnicode_EXPORT_ALLOW_COPY`` ``0x010000`` Allow memory copies and conversions
=============================== ============ ===================================


.. _export-complexity:
Expand All @@ -179,7 +176,7 @@ Export complexity
By default, an export has a complexity of *O*\ (1): no memory is copied
and no conversion is done.

If the ``PyUnicode_EXPORT_COPY`` flag is set, there are cases when a
If the ``PyUnicode_EXPORT_ALLOW_COPY`` flag is set, there are cases when a
copy is needed, *O*\ (*n*) complexity:

* If only UCS-2 is requested and the native format is UCS-1.
Expand Down

0 comments on commit 064dd74

Please sign in to comment.