diff options
author | Zachary Turner <zturner@google.com> | 2016-01-13 21:21:49 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-01-13 21:21:49 +0000 |
commit | 19e2ea8fb621111684db21bb5e8f92474ca7d7f4 (patch) | |
tree | afda45d3d2addf6264df46387b0fe56de1f2fc55 /lldb/scripts/Python | |
parent | a4976b33d262cbbf2e813c22820fcaa4f90bd154 (diff) | |
download | bcm5719-llvm-19e2ea8fb621111684db21bb5e8f92474ca7d7f4.tar.gz bcm5719-llvm-19e2ea8fb621111684db21bb5e8f92474ca7d7f4.zip |
Fix TestProcessLaunch for Python 3.
There were a number of problems preventing this from working:
1. The SWIG typemaps for converting Python lists to and from C++
arrays were not updated for Python 3. So they were doing things
like PyString_Check instead of using the PythonString from
PythonDataObjects.
2. ProcessLauncherWindows was ignoring the environment completely.
So any test that involved launching an inferior with any kind
of environment variable would have failed.
3. The test itself was using process.GetSTDOUT(), which isn't
implemented on Windows. So this was changed to save the
value of the environment variable in a local variable and
have the debugger look at the value of the variable.
llvm-svn: 257669
Diffstat (limited to 'lldb/scripts/Python')
-rw-r--r-- | lldb/scripts/Python/python-typemaps.swig | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig index 68e442defd3..ca918198863 100644 --- a/lldb/scripts/Python/python-typemaps.swig +++ b/lldb/scripts/Python/python-typemaps.swig @@ -1,20 +1,22 @@ /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */ %typemap(in) char ** { + using namespace lldb_private; /* Check if is a list */ - if (PyList_Check($input)) { - int size = PyList_Size($input); + if (PythonList::Check($input)) { + PythonList list(PyRefType::Borrowed, $input); + int size = list.GetSize(); int i = 0; - $1 = (char **) malloc((size+1) * sizeof(char*)); + $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 { + PythonString py_str = list.GetItemAtIndex(i).AsType<PythonString>(); + if (!py_str.IsAllocated()) { PyErr_SetString(PyExc_TypeError,"list must contain strings"); free($1); - return NULL; + return nullptr; } + + $1[i] = const_cast<char*>(py_str.GetString().data()); } $1[i] = 0; } else if ($input == Py_None) { @@ -42,12 +44,14 @@ %typemap(typecheck) char ** { /* Check if is a list */ $1 = 1; - if (PyList_Check($input)) { - int size = PyList_Size($input); + using namespace lldb_private; + if (PythonList::Check($input)) { + PythonList list(PyRefType::Borrowed, $input); + int size = list.GetSize(); int i = 0; for (i = 0; i < size; i++) { - PyObject *o = PyList_GetItem($input,i); - if (!PyString_Check(o)) { $1 = 0; } + PythonString s = list.GetItemAtIndex(i).AsType<PythonString>(); + if (!s.IsAllocated()) { $1 = 0; } } } else @@ -81,13 +85,12 @@ $1 = (char**)malloc((size+1)*sizeof(char*)); for (int i = 0; i < size; i++) { - PythonObject o = py_list.GetItemAtIndex(i); - if (!PythonString::Check(o.get())) { + auto py_str = py_list.GetItemAtIndex(i).AsType<PythonString>(); + if (!py_str.IsAllocated()) { PyErr_SetString(PyExc_TypeError,"list must contain strings"); free($1); return nullptr; } - auto py_str = o.AsType<PythonString>(); $1[i] = const_cast<char*>(py_str.GetString().data()); } @@ -101,14 +104,16 @@ } %typemap(typecheck) char const ** { + using namespace lldb_private; /* Check if is a list */ $1 = 1; - if (PyList_Check($input)) { - int size = PyList_Size($input); + if (PythonList::Check($input)) { + PythonList list(PyRefType::Borrowed, $input); + int size = list.GetSize(); int i = 0; for (i = 0; i < size; i++) { - PyObject *o = PyList_GetItem($input,i); - if (!PyString_Check(o)) { $1 = 0; } + PythonString s = list.GetItemAtIndex(i).AsType<PythonString>(); + if (!s.IsAllocated()) { $1 = 0; } } } else @@ -126,10 +131,13 @@ int i; len = 0; while ($1[len]) len++; - $result = PyList_New(len); + using namespace lldb_private; + PythonList list(len); for (i = 0; i < len; i++) { - PyList_SetItem($result, i, PyString_FromString($1[i])); + PythonString str($1[i]); + list.SetItemAtIndex(i, str); } + $result = list.release(); } /* Typemap definitions to allow SWIG to properly handle char buffer. */ |