summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 4e0c663..3767064 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3017,6 +3017,37 @@ PyUnicode_AsWideCharString(PyObject *unicode,
return buffer;
}
+wchar_t*
+_PyUnicode_AsWideCharString(PyObject *unicode)
+{
+ const wchar_t *wstr;
+ wchar_t *buffer;
+ Py_ssize_t buflen;
+
+ if (unicode == NULL) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
+
+ wstr = PyUnicode_AsUnicodeAndSize(unicode, &buflen);
+ if (wstr == NULL) {
+ return NULL;
+ }
+ if (wcslen(wstr) != (size_t)buflen) {
+ PyErr_SetString(PyExc_ValueError,
+ "embedded null character");
+ return NULL;
+ }
+
+ buffer = PyMem_NEW(wchar_t, buflen + 1);
+ if (buffer == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ memcpy(buffer, wstr, (buflen + 1) * sizeof(wchar_t));
+ return buffer;
+}
+
#endif /* HAVE_WCHAR_H */
PyObject *