summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-11-23 01:05:49 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-11-23 01:05:49 (GMT)
commit5944c369314a4e57e997eb855f45ccde96e37db7 (patch)
tree25c02f2f88683ce5bb1e8dce465aaa41f738d59c /Objects
parent02686751931e6cd267f60c65b59744c7dff50cd2 (diff)
downloadcpython-5944c369314a4e57e997eb855f45ccde96e37db7.zip
cpython-5944c369314a4e57e997eb855f45ccde96e37db7.tar.gz
cpython-5944c369314a4e57e997eb855f45ccde96e37db7.tar.bz2
cave to those who like readable code
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index a7d9e12..ab59e21 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -6164,7 +6164,21 @@ PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
kind = PyUnicode_KIND(unicode);
data = PyUnicode_DATA(unicode);
len = PyUnicode_GET_LENGTH(unicode);
- expandsize = kind * 2 + 2;
+ expandsize = 0;
+ switch (kind) {
+ case PyUnicode_1BYTE_KIND:
+ 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)
return PyErr_NoMemory();