Author serhiy.storchaka
Recipients ncoghlan, serhiy.storchaka
Date 2016-11-22.07:55:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1479801324.65.0.962202188144.issue28769@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-11-22 07:55:24serhiy.storchakasetrecipients: + serhiy.storchaka, ncoghlan
2016-11-22 07:55:24serhiy.storchakasetmessageid: <1479801324.65.0.962202188144.issue28769@psf.upfronthosting.co.za>
2016-11-22 07:55:24serhiy.storchakalinkissue28769 messages
2016-11-22 07:55:24serhiy.storchakacreate