aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/stringlist.c')
-rw-r--r--src/stringlist.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/stringlist.c b/src/stringlist.c
index 915cca4..ad1acf3 100644
--- a/src/stringlist.c
+++ b/src/stringlist.c
@@ -72,8 +72,20 @@ StringList* listToCList(PyObject* list)
//Item are copied so that the PyObject can be deleted after the call without
//destroying the data in the returned list.
PyObject *elem = PyList_GetItem(list, i);
- ret->list[i] = malloc(sizeof(char) * (PyBytes_Size(elem) + 1));
- strcpy(ret->list[i], PyBytes_AsString(elem));
+ char *val = NULL;
+
+ if (PyUnicode_Check(elem))
+ {
+ PyObject *tmp = PyUnicode_AsUTF8String(elem);
+ val = strdup(PyString_AsString(tmp));
+ Py_DECREF(tmp);
+ }
+ else if (PyString_Check(elem))
+ {
+ val = PyString_AsString(elem);
+ }
+
+ ret->list[i] = strdup(val);
}
return ret;