[issue35295] Please clarify whether PyUnicode_AsUTF8AndSize() or PyUnicode_AsUTF8String() is preferred

Inada Naoki report at bugs.python.org
Thu Feb 4 22:53:56 EST 2021


Inada Naoki <songofacandy at gmail.com> added the comment:

> 1a. Declare both functions equally acceptable. Remove comments claiming that PyUnicode_AsUTF8AndSize() should be avoided.
>
> 1b. 1a, and change the implementation of PyUnicode_AsUTF8AndSize() to avoid allocating the string twice if it needs to be materialized, so that PyUnicode_AsUTF8AndSize() is never significantly slower than PyUnicode_AsUTF8String().

I think 1b is the best approach.

PyUnicode_AsUTF8AndSize() is optimized already. See GH-18327.
And it becomes limited API. See bpo-41784.

So we should just remove the outdated comments.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35295>
_______________________________________


More information about the Python-bugs-list mailing list