mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Add an optional size argument to _Py_char2wchar()
_Py_char2wchar() callers usually need the result size in characters. Since it's trivial to compute it in _Py_char2wchar() (O(1) whereas wcslen() is O(n)), add an option to get it.
This commit is contained in:
parent
0a1b8cba90
commit
168e117e0a
5 changed files with 26 additions and 17 deletions
|
@ -486,10 +486,12 @@ Py_Main(int argc, wchar_t **argv)
|
|||
/* Use utf-8 on Mac OS X */
|
||||
unicode = PyUnicode_FromString(p);
|
||||
#else
|
||||
wchar_t *wchar = _Py_char2wchar(p);
|
||||
wchar_t *wchar;
|
||||
size_t len;
|
||||
wchar = _Py_char2wchar(p, &len);
|
||||
if (wchar == NULL)
|
||||
continue;
|
||||
unicode = PyUnicode_FromWideChar(wchar, wcslen(wchar));
|
||||
unicode = PyUnicode_FromWideChar(wchar, len);
|
||||
PyMem_Free(wchar);
|
||||
#endif
|
||||
if (unicode == NULL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue