aboutsummaryrefslogtreecommitdiff
path: root/Lib/python/pywstrings.swg
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/python/pywstrings.swg')
-rw-r--r--Lib/python/pywstrings.swg24
1 files changed, 20 insertions, 4 deletions
diff --git a/Lib/python/pywstrings.swg b/Lib/python/pywstrings.swg
index e64618762..0e5a78df5 100644
--- a/Lib/python/pywstrings.swg
+++ b/Lib/python/pywstrings.swg
@@ -18,16 +18,32 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
int isunicode = PyUnicode_Check(obj);
%#if PY_VERSION_HEX < 0x03000000 && !defined(SWIG_PYTHON_STRICT_UNICODE_WCHAR)
if (!isunicode && PyString_Check(obj)) {
- obj = tmp = PyUnicode_FromObject(obj);
- isunicode = 1;
+ tmp = PyUnicode_FromObject(obj);
+ if (tmp) {
+ isunicode = 1;
+ obj = tmp;
+ } else {
+ PyErr_Clear();
+ return SWIG_TypeError;
+ }
}
%#endif
if (isunicode) {
+%#if PY_VERSION_HEX >= 0x03030000
+ Py_ssize_t len = PyUnicode_GetLength(obj);
+%#else
Py_ssize_t len = PyUnicode_GetSize(obj);
+%#endif
if (cptr) {
+ Py_ssize_t length;
*cptr = %new_array(len + 1, wchar_t);
- PyUnicode_AsWideChar(SWIGPY_UNICODE_ARG(obj), *cptr, len);
- (*cptr)[len] = 0;
+ length = PyUnicode_AsWideChar(SWIGPY_UNICODE_ARG(obj), *cptr, len);
+ if (length == -1) {
+ PyErr_Clear();
+ Py_XDECREF(tmp);
+ return SWIG_TypeError;
+ }
+ (*cptr)[length] = 0;
}
if (psize) *psize = (size_t) len + 1;
if (alloc) *alloc = cptr ? SWIG_NEWOBJ : 0;