mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
and back to the "magic" formula (with a comment) it is
This commit is contained in:
parent
d2b0217944
commit
1518e8713d
1 changed files with 3 additions and 15 deletions
|
@ -6164,21 +6164,9 @@ PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
|
||||||
kind = PyUnicode_KIND(unicode);
|
kind = PyUnicode_KIND(unicode);
|
||||||
data = PyUnicode_DATA(unicode);
|
data = PyUnicode_DATA(unicode);
|
||||||
len = PyUnicode_GET_LENGTH(unicode);
|
len = PyUnicode_GET_LENGTH(unicode);
|
||||||
expandsize = 0;
|
/* 4 byte characters can take up 10 bytes, 2 byte characters can take up 6
|
||||||
switch (kind) {
|
bytes, and 1 byte characters 4. */
|
||||||
case PyUnicode_1BYTE_KIND:
|
expandsize = kind * 2 + 2;
|
||||||
expandsize = 4;
|
|
||||||
break;
|
|
||||||
case PyUnicode_2BYTE_KIND:
|
|
||||||
expandsize = 6;
|
|
||||||
break;
|
|
||||||
case PyUnicode_4BYTE_KIND:
|
|
||||||
expandsize = 10;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len > PY_SSIZE_T_MAX / expandsize)
|
if (len > PY_SSIZE_T_MAX / expandsize)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue