@@ -271,31 +271,22 @@ Return a string that can be used as a key for locale-aware comparisons.");
271271static PyObject *
272272PyLocale_strxfrm (PyObject * self , PyObject * args )
273273{
274- Py_UNICODE * s0 ;
275- Py_ssize_t n0 ;
276- wchar_t * s , * buf = NULL ;
277- size_t n1 , n2 ;
274+ PyObject * str ;
275+ Py_ssize_t n1 ;
276+ wchar_t * s = NULL , * buf = NULL ;
277+ size_t n2 ;
278278 PyObject * result = NULL ;
279- #if Py_UNICODE_SIZE != SIZEOF_WCHAR_T
280- Py_ssize_t i ;
281- #endif
282279
283- if (!PyArg_ParseTuple (args , "u# :strxfrm" , & s0 , & n0 ))
280+ if (!PyArg_ParseTuple (args , "U :strxfrm" , & str ))
284281 return NULL ;
285282
286- #if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
287- s = (wchar_t * ) s0 ;
288- #else
289- s = PyMem_Malloc ((n0 + 1 )* sizeof (wchar_t ));
290- if (!s )
291- return PyErr_NoMemory ();
292- for (i = 0 ; i <=n0 ; i ++ )
293- s [i ] = s0 [i ];
294- #endif
283+ s = PyUnicode_AsWideCharString (str , & n1 );
284+ if (s == NULL )
285+ goto exit ;
295286
296287 /* assume no change in size, first */
297- n1 = wcslen ( s ) + 1 ;
298- buf = PyMem_Malloc (n1 * sizeof (wchar_t ));
288+ n1 = n1 + 1 ;
289+ buf = PyMem_Malloc (n1 * sizeof (wchar_t ));
299290 if (!buf ) {
300291 PyErr_NoMemory ();
301292 goto exit ;
@@ -311,11 +302,11 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
311302 n2 = wcsxfrm (buf , s , n2 + 1 );
312303 }
313304 result = PyUnicode_FromWideChar (buf , n2 );
314- exit :
315- if (buf ) PyMem_Free ( buf );
316- #if Py_UNICODE_SIZE != SIZEOF_WCHAR_T
317- PyMem_Free (s );
318- #endif
305+ exit :
306+ if (buf )
307+ PyMem_Free ( buf );
308+ if (s )
309+ PyMem_Free ( s );
319310 return result ;
320311}
321312#endif
0 commit comments