Index: Modules/_localemodule.c =================================================================== --- Modules/_localemodule.c (revision 59482) +++ Modules/_localemodule.c (working copy) @@ -250,6 +250,7 @@ static PyObject* PyLocale_strxfrm(PyObject* self, PyObject* args) { +#if !defined(HAVE_WCSXFRM) char *s, *buf; size_t n1, n2; PyObject *result; @@ -273,6 +274,43 @@ result = PyUnicode_FromString(buf); PyMem_Free(buf); return result; +#else + PyObject *s, *result = NULL; + wchar_t *buf = NULL, *ws = NULL; + int len; + size_t len2; + if (!PyArg_UnpackTuple(args, "strxfrm", 1, 1, &s)) + return NULL; + /* Argument must be unicode, or it's an error. */ + if (!PyUnicode_Check(s)) { + PyErr_SetString(PyExc_ValueError, "strxfrm arguments must be strings"); + } + /* Convert the unicode string to wchar[]. */ + len = PyUnicode_GET_SIZE(s) + 1; + ws = PyMem_MALLOC(len * sizeof(wchar_t)); + if (!ws) { + PyErr_NoMemory(); + goto done; + } + if (PyUnicode_AsWideChar((PyUnicodeObject*)s, ws, len) == -1) + goto done; + ws[len - 1] = 0; + + /* Get the transformation. */ + len2 = wcsxfrm(NULL, ws, 0) + 1; + buf = PyMem_MALLOC(len2 * sizeof(wchar_t)); + if (!buf) { + PyErr_NoMemory(); + goto done; + } + wcsxfrm(buf, ws, len2); + result = PyUnicode_FromWideChar(buf, len2 - 1); + done: + /* Deallocate everything. */ + if (ws) PyMem_FREE(ws); + if (buf) PyMem_FREE(buf); + return result; +#endif } #if defined(MS_WINDOWS)