Issue #28760: Clean up and fix comments in PyUnicode_AsUnicodeEscapeString().

Patch by Xiang Zhang.
This commit is contained in:
Serhiy Storchaka 2016-11-21 11:47:16 +02:00
commit 50911476f5
1 changed files with 4 additions and 10 deletions

View File

@ -6118,12 +6118,7 @@ PyUnicode_DecodeUnicodeEscape(const char *s,
return result;
}
/* Return a Unicode-Escape string version of the Unicode object.
If quotes is true, the string is enclosed in u"" or u'' quotes as
appropriate.
*/
/* Return a Unicode-Escape string version of the Unicode object. */
PyObject *
PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
@ -6161,10 +6156,10 @@ PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
/* 4 byte characters can take up 10 bytes, 2 byte characters can take up 6
bytes, and 1 byte characters 4. */
expandsize = kind * 2 + 2;
if (len > (PY_SSIZE_T_MAX - 2 - 1) / expandsize) {
if (len > PY_SSIZE_T_MAX / expandsize) {
return PyErr_NoMemory();
}
repr = PyBytes_FromStringAndSize(NULL, 2 + expandsize * len + 1);
repr = PyBytes_FromStringAndSize(NULL, expandsize * len);
if (repr == NULL) {
return NULL;
}
@ -6209,9 +6204,8 @@ PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
*p++ = Py_hexdigits[ch & 0x000F];
}
}
/* U+0000-U+00ff range: Map 16-bit characters to '\uHHHH' */
/* U+0100-U+ffff range: Map 16-bit characters to '\uHHHH' */
else if (ch < 0x10000) {
/* U+0100-U+ffff */
*p++ = '\\';
*p++ = 'u';
*p++ = Py_hexdigits[(ch >> 12) & 0x000F];