[Python-checkins] cpython (3.6): Issue #28760: Clean up and fix comments in PyUnicode_AsUnicodeEscapeString().
serhiy.storchaka
python-checkins at python.org
Mon Nov 21 04:47:29 EST 2016
https://hg.python.org/cpython/rev/2d0ce3f4dfbd
changeset: 105270:2d0ce3f4dfbd
branch: 3.6
parent: 105268:00870a1d0c25
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Nov 21 11:46:51 2016 +0200
summary:
Issue #28760: Clean up and fix comments in PyUnicode_AsUnicodeEscapeString().
Patch by Xiang Zhang.
files:
Objects/unicodeobject.c | 14 ++++----------
1 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -6134,12 +6134,7 @@
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)
@@ -6177,10 +6172,10 @@
/* 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;
}
@@ -6225,9 +6220,8 @@
*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];
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list