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
|
@ -1783,17 +1783,18 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
|
|||
/* locale encoding with surrogateescape */
|
||||
wchar_t *wchar;
|
||||
PyObject *unicode;
|
||||
size_t len;
|
||||
|
||||
if (s[size] != '\0' || size != strlen(s)) {
|
||||
PyErr_SetString(PyExc_TypeError, "embedded NUL character");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wchar = _Py_char2wchar(s);
|
||||
wchar = _Py_char2wchar(s, &len);
|
||||
if (wchar == NULL)
|
||||
return NULL;
|
||||
|
||||
unicode = PyUnicode_FromWideChar(wchar, -1);
|
||||
unicode = PyUnicode_FromWideChar(wchar, len);
|
||||
PyMem_Free(wchar);
|
||||
return unicode;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue