New submission from Serhiy Storchaka: PyUnicode_AsUTF8AndSize() and PyUnicode_AsUTF8() return a reference to cached readonly UTF-8 representation of a string. Changing the content of the UTF-8 representation is an error. Proposed patch makes these functions returning "const char *" rather of "char *" to force this restriction.
This is backward-incompatible change. Since PyUnicode_AsUTF8AndSize() and PyUnicode_AsUTF8() can return an error, it is more likely that the result is saved in a local variable rather than passing to other function. If the type of this variable is "char *" rather than "const char *", this would cause a compiler error. The fix is simple -- just add the const qualifier to the local variable declaration (more preferable) or cast the result of PyUnicode_AsUTF8AndSize() or PyUnicode_AsUTF8() to "char *". Both functions are not in stable API. ---------- components: Interpreter Core files: PyUnicode_AsUTF8-const.patch keywords: patch messages: 281439 nosy: ncoghlan, serhiy.storchaka priority: normal severity: normal stage: patch review status: open title: Make PyUnicode_AsUTF8 returning "const char *" rather of "char *" type: enhancement versions: Python 3.7 Added file: http://bugs.python.org/file45596/PyUnicode_AsUTF8-const.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28769> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com