aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/python_varargs_typemap.i
diff options
context:
space:
mode:
Diffstat (limited to 'Examples/test-suite/python_varargs_typemap.i')
-rw-r--r--Examples/test-suite/python_varargs_typemap.i14
1 files changed, 9 insertions, 5 deletions
diff --git a/Examples/test-suite/python_varargs_typemap.i b/Examples/test-suite/python_varargs_typemap.i
index d809bf1fa..65ce72f43 100644
--- a/Examples/test-suite/python_varargs_typemap.i
+++ b/Examples/test-suite/python_varargs_typemap.i
@@ -17,21 +17,25 @@
PyObject *pyobj = PyTuple_GetItem(varargs, i);
char *str = 0;
%#if PY_VERSION_HEX>=0x03000000
+ const char *strtmp = 0;
PyObject *pystr;
if (!PyUnicode_Check(pyobj)) {
- PyErr_SetString(PyExc_ValueError, "Expected a string");
- SWIG_fail;
+ PyErr_SetString(PyExc_ValueError, "Expected a string");
+ SWIG_fail;
}
pystr = PyUnicode_AsUTF8String(pyobj);
if (!pystr) {
SWIG_fail;
}
- str = strdup(PyBytes_AsString(pystr));
+ strtmp = PyBytes_AsString(pystr);
+ str = (char *)malloc(strlen(strtmp) + 1);
+ if (str)
+ strcpy(str, strtmp);
Py_DECREF(pystr);
%#else
if (!PyString_Check(pyobj)) {
- PyErr_SetString(PyExc_ValueError, "Expected a string");
- SWIG_fail;
+ PyErr_SetString(PyExc_ValueError, "Expected a string");
+ SWIG_fail;
}
str = PyString_AsString(pyobj);
%#endif