Author: Jonas Devlieghere Date: 2020-01-08T13:37:07-08:00 New Revision: 0341c11e08504acef8c16ab07210bc253dadf2d9
URL: https://github.com/llvm/llvm-project/commit/0341c11e08504acef8c16ab07210bc253dadf2d9 DIFF: https://github.com/llvm/llvm-project/commit/0341c11e08504acef8c16ab07210bc253dadf2d9.diff LOG: [lldb/SWIG] Refactor extensions to be non Python-specific The current SWIG extensions for the string conversion operator is Python specific because it uses the PythonObjects. This means that the code cannot be reused for other SWIG supported languages such as Lua. This reimplements the extensions in a more generic way that can be reused. Differential revision: https://reviews.llvm.org/D72377 Added: Modified: lldb/scripts/Python/python-extensions.swig lldb/scripts/interface/SBTarget.i lldb/scripts/lldb.swig lldb/scripts/lldb_lua.swig Removed: ################################################################################ diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig index c10c32b44877..dbd4b1d79d00 100644 --- a/lldb/scripts/Python/python-extensions.swig +++ b/lldb/scripts/Python/python-extensions.swig @@ -1,4 +1,3 @@ - %extend lldb::SBAddress { %nothreadallow; PyObject *lldb::SBAddress::__str__ (){ @@ -502,18 +501,6 @@ } %extend lldb::SBTarget { - %nothreadallow; - PyObject *lldb::SBTarget::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - const char *desc = description.GetData(); - size_t desc_len = description.GetSize(); - if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) - --desc_len; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - %pythoncode %{ def __eq__(self, rhs): if not isinstance(rhs, type(self)): diff --git a/lldb/scripts/interface/SBTarget.i b/lldb/scripts/interface/SBTarget.i index b31622889e52..02c70b6e1cd6 100644 --- a/lldb/scripts/interface/SBTarget.i +++ b/lldb/scripts/interface/SBTarget.i @@ -8,7 +8,6 @@ namespace lldb { - %feature("docstring", "Represents the target program running under the debugger. @@ -968,6 +967,22 @@ public: lldb::SBValue EvaluateExpression (const char *expr, const lldb::SBExpressionOptions &options); + %extend { + %nothreadallow; + std::string lldb::SBTarget::__str__(){ + lldb::SBStream stream; + $self->GetDescription (stream, lldb::eDescriptionLevelBrief); + + const char *desc = stream.GetData(); + size_t desc_len = stream.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + + return std::string(desc, desc_len); + } + %clearnothreadallow; + } + #ifdef SWIGPYTHON %pythoncode %{ class modules_access(object): diff --git a/lldb/scripts/lldb.swig b/lldb/scripts/lldb.swig index f030116b6cb8..c3b908332741 100644 --- a/lldb/scripts/lldb.swig +++ b/lldb/scripts/lldb.swig @@ -93,6 +93,7 @@ def lldb_iter(obj, getsize, getelem): yield elem(i) %} +%include <std_string.i> %include "./Python/python-typemaps.swig" %include "./headers.swig" diff --git a/lldb/scripts/lldb_lua.swig b/lldb/scripts/lldb_lua.swig index 85edefff76f2..bf8809015d9a 100644 --- a/lldb/scripts/lldb_lua.swig +++ b/lldb/scripts/lldb_lua.swig @@ -8,6 +8,7 @@ %module lldb +%include <std_string.i> %include "./headers.swig" %{ _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits