summaryrefslogtreecommitdiffstats
path: root/lldb/scripts/Python
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2014-10-21 17:49:24 +0000
committerEnrico Granata <egranata@apple.com>2014-10-21 17:49:24 +0000
commitdd86f33902071c39b3ec2ab8c572df32beb8b29b (patch)
tree4db162c87e328d3c5dacef62d3f851b21f082c94 /lldb/scripts/Python
parent256451561c9d9f71328c213295cae8ce9fded3f9 (diff)
downloadbcm5719-llvm-dd86f33902071c39b3ec2ab8c572df32beb8b29b.tar.gz
bcm5719-llvm-dd86f33902071c39b3ec2ab8c572df32beb8b29b.zip
Add typemaps to handle the transformation of Python list of strings into a 'char const **'. This fixes zephyr's issue with SBTarget::Launch without splitting the API into multiple names
llvm-svn: 220306
Diffstat (limited to 'lldb/scripts/Python')
-rw-r--r--lldb/scripts/Python/python-typemaps.swig74
1 files changed, 74 insertions, 0 deletions
diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig
index 7a6e0d3261c..df809f408a8 100644
--- a/lldb/scripts/Python/python-typemaps.swig
+++ b/lldb/scripts/Python/python-typemaps.swig
@@ -25,6 +25,23 @@
}
}
+%typemap(typecheck) char ** {
+ /* Check if is a list */
+ $1 = 1;
+ if (PyList_Check($input)) {
+ int size = PyList_Size($input);
+ int i = 0;
+ for (i = 0; i < size; i++) {
+ PyObject *o = PyList_GetItem($input,i);
+ if (!PyString_Check(o)) { $1 = 0; }
+ }
+ }
+ else
+ {
+ $1 = ( ($input == Py_None) ? 1 : 0);
+ }
+}
+
%typemap(freearg) char** {
free((char *) $1);
}
@@ -40,6 +57,63 @@
}
}
+%typemap(in) char const ** {
+ /* Check if is a list */
+ if (PyList_Check($input)) {
+ int size = PyList_Size($input);
+ int i = 0;
+ $1 = (char **) malloc((size+1) * sizeof(char*));
+ for (i = 0; i < size; i++) {
+ PyObject *o = PyList_GetItem($input,i);
+ if (PyString_Check(o))
+ $1[i] = PyString_AsString(o);
+ else {
+ PyErr_SetString(PyExc_TypeError,"list must contain strings");
+ free($1);
+ return NULL;
+ }
+ }
+ $1[i] = 0;
+ } else if ($input == Py_None) {
+ $1 = NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError,"not a list");
+ return NULL;
+ }
+}
+
+%typemap(typecheck) char const ** {
+ /* Check if is a list */
+ $1 = 1;
+ if (PyList_Check($input)) {
+ int size = PyList_Size($input);
+ int i = 0;
+ for (i = 0; i < size; i++) {
+ PyObject *o = PyList_GetItem($input,i);
+ if (!PyString_Check(o)) { $1 = 0; }
+ }
+ }
+ else
+ {
+ $1 = ( ($input == Py_None) ? 1 : 0);
+ }
+}
+
+%typemap(freearg) char const ** {
+ free((char *) $1);
+}
+
+%typemap(out) char const ** {
+ int len;
+ int i;
+ len = 0;
+ while ($1[len]) len++;
+ $result = PyList_New(len);
+ for (i = 0; i < len; i++) {
+ PyList_SetItem($result, i, PyString_FromString($1[i]));
+ }
+}
+
/* Typemap definitions to allow SWIG to properly handle char buffer. */
// typemap for a char buffer
OpenPOWER on IntegriCloud