summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-11-21 09:47:16 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-11-21 09:47:16 (GMT)
commit50911476f551b224f3bb2897578a276576bc4a30 (patch)
treeb694fe0cdb7b3a46717202cef1f1e708cd9a9dcc /Objects
parentf80e740b7708d732162df8df9d8d7b7df68360c3 (diff)
parentac0720eaa4308038dc5e910f29e2561acae6d126 (diff)
downloadcpython-50911476f551b224f3bb2897578a276576bc4a30.zip
cpython-50911476f551b224f3bb2897578a276576bc4a30.tar.gz
cpython-50911476f551b224f3bb2897578a276576bc4a30.tar.bz2
Issue #28760: Clean up and fix comments in PyUnicode_AsUnicodeEscapeString().
Patch by Xiang Zhang.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 0e88fca..e88a126 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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];