summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-16 23:16:16 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-16 23:16:16 (GMT)
commit168e117e0a8825bc3ae0c08f0b08a33ac351a14f (patch)
tree8f9e0067a2d14a362844f891815791d9d41cfb79 /Objects/unicodeobject.c
parent0a1b8cba90d467e85be87cd8b10b4d31caa8765a (diff)
downloadcpython-168e117e0a8825bc3ae0c08f0b08a33ac351a14f.zip
cpython-168e117e0a8825bc3ae0c08f0b08a33ac351a14f.tar.gz
cpython-168e117e0a8825bc3ae0c08f0b08a33ac351a14f.tar.bz2
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.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 98427e3..9fe9c42 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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;
}