[3.6] bpo-31393: Fix the use of PyUnicode_READY(). (GH-3451). (#3453)

(cherry picked from commit e3b2b4b8d9)
This commit is contained in:
Serhiy Storchaka 2017-09-08 10:43:54 +03:00 committed by GitHub
parent 9f2b3d4c28
commit ddb536ba7b
5 changed files with 30 additions and 15 deletions

View file

@ -1464,7 +1464,10 @@ idna_converter(PyObject *obj, struct maybe_idna *data)
len = PyByteArray_Size(obj);
}
else if (PyUnicode_Check(obj)) {
if (PyUnicode_READY(obj) == 0 && PyUnicode_IS_COMPACT_ASCII(obj)) {
if (PyUnicode_READY(obj) == -1) {
return 0;
}
if (PyUnicode_IS_COMPACT_ASCII(obj)) {
data->buf = PyUnicode_DATA(obj);
len = PyUnicode_GET_LENGTH(obj);
}