Mercurial > cpython-lru_cache-weakref
diff Objects/unicodeobject.c @ 73188:01df2267fc2d
PyUnicode_AsUnicodeCopy() uses PyUnicode_AsUnicodeAndSize() to get directly the length
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sun, 23 Oct 2011 20:10:08 +0200 |
| parents | d8c36928d35b |
| children | 80a7ab9ac29f |
line wrap: on
line diff
--- a/Objects/unicodeobject.c Sun Oct 23 20:07:00 2011 +0200 +++ b/Objects/unicodeobject.c Sun Oct 23 20:10:08 2011 +0200 @@ -14210,21 +14210,21 @@ PyUnicode_AsUnicodeCopy(PyObject *unicode) { Py_UNICODE *u, *copy; - Py_ssize_t size; + Py_ssize_t len, size; if (!PyUnicode_Check(unicode)) { PyErr_BadArgument(); return NULL; } - u = PyUnicode_AsUnicode(unicode); + u = PyUnicode_AsUnicodeAndSize(unicode, &len); if (u == NULL) return NULL; /* Ensure we won't overflow the size. */ - if (PyUnicode_GET_SIZE(unicode) > ((PY_SSIZE_T_MAX / sizeof(Py_UNICODE)) - 1)) { + if (len > ((PY_SSIZE_T_MAX / sizeof(Py_UNICODE)) - 1)) { PyErr_NoMemory(); return NULL; } - size = PyUnicode_GET_SIZE(unicode) + 1; /* copy the nul character */ + size = len + 1; /* copy the null character */ size *= sizeof(Py_UNICODE); copy = PyMem_Malloc(size); if (copy == NULL) {
