New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate PyUnicode_AsUnicode(): emit a DeprecationWarning #66467
Comments
With the PEP-393 implemented in Python 3.3, PyUnicode_AsUnicode() and all similar functions have to convert the compact string to a heavy wchar_t* string (UCS-4 on Linux: 4 bytes per character, UTF-16 on Windows: 2 or 4 bytes per character) which is stored in the string. The heavy "Py_UNICODE*" storage is kept until the string is destroyed, which may only occur at Python exit. To reduce the memory footprint, it would be nice to promote the usage of the PEP-393 and start to emit a DeprecationWarning warning. The Py_UNICODE type and all related functions are already deprecated in the documentation. The deprecate PyUnicode_AsUnicode(), we should stop using it in Python itself. For example, PyUnicode_AsWideCharString() can be used to encode filenames on Windows, it doesn't store the encoded string in the Python object. See for example path_converter() in posixmodule.c. |
Here is the first step: issue bpo-22323, "rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString()" (to not call PyUnicode_AsUnicode() anymore). |
It would be better to emit a warning only at compile time. End user of compiled extension can't do anything with a warning emitted at run time, only its author can avoid it. |
DeprecatedWarning warnings are silent by default. So it will not annoy users. |
Sorry I lost track of this issue, I just close it. Note: Serhiy recently worked on wchar_t functions of PyUnicodeObject to detect embedded null characters, see for example bpo-30708. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: