diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-09-29 10:30:43 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-09-29 10:30:43 (GMT) |
commit | 449057f2fabb417c1bc553e9fc67425b5d24affb (patch) | |
tree | eda316277064c7ea6b89509a16a42919115e2b79 | |
parent | 255dfdb5ce5b93240a1edd724e1c7a479862ef7d (diff) | |
download | cpython-449057f2fabb417c1bc553e9fc67425b5d24affb.zip cpython-449057f2fabb417c1bc553e9fc67425b5d24affb.tar.gz cpython-449057f2fabb417c1bc553e9fc67425b5d24affb.tar.bz2 |
Issue #9979: Use PyUnicode_AsWideCharString() for _locale.strcoll()
It simplifies the code and prepare the surrogates support.
-rw-r--r-- | Modules/_localemodule.c | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 2394206..67d16f4 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -242,29 +242,16 @@ PyLocale_strcoll(PyObject* self, PyObject* args) { PyObject *os1, *os2, *result = NULL; wchar_t *ws1 = NULL, *ws2 = NULL; - Py_ssize_t len1, len2; if (!PyArg_ParseTuple(args, "UU:strcoll", &os1, &os2)) return NULL; /* Convert the unicode strings to wchar[]. */ - len1 = PyUnicode_GET_SIZE(os1) + 1; - ws1 = PyMem_MALLOC(len1 * sizeof(wchar_t)); - if (!ws1) { - PyErr_NoMemory(); - goto done; - } - if (PyUnicode_AsWideChar((PyUnicodeObject*)os1, ws1, len1) == -1) + ws1 = PyUnicode_AsWideCharString((PyUnicodeObject*)os1, NULL); + if (ws1 == NULL) goto done; - ws1[len1 - 1] = 0; - len2 = PyUnicode_GET_SIZE(os2) + 1; - ws2 = PyMem_MALLOC(len2 * sizeof(wchar_t)); - if (!ws2) { - PyErr_NoMemory(); - goto done; - } - if (PyUnicode_AsWideChar((PyUnicodeObject*)os2, ws2, len2) == -1) + ws2 = PyUnicode_AsWideCharString((PyUnicodeObject*)os2, NULL); + if (ws2 == NULL) goto done; - ws2[len2 - 1] = 0; /* Collate the strings. */ result = PyLong_FromLong(wcscoll(ws1, ws2)); done: |