Skip to content

Commit 0341c11

Browse files
committed
[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
1 parent 0b8ce37 commit 0341c11

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

lldb/scripts/Python/python-extensions.swig

-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
%extend lldb::SBAddress {
32
%nothreadallow;
43
PyObject *lldb::SBAddress::__str__ (){
@@ -502,18 +501,6 @@
502501
}
503502

504503
%extend lldb::SBTarget {
505-
%nothreadallow;
506-
PyObject *lldb::SBTarget::__str__ (){
507-
lldb::SBStream description;
508-
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
509-
const char *desc = description.GetData();
510-
size_t desc_len = description.GetSize();
511-
if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r'))
512-
--desc_len;
513-
return PythonString(llvm::StringRef(desc, desc_len)).release();
514-
}
515-
%clearnothreadallow;
516-
517504
%pythoncode %{
518505
def __eq__(self, rhs):
519506
if not isinstance(rhs, type(self)):

lldb/scripts/interface/SBTarget.i

+16-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace lldb {
1010

11-
1211
%feature("docstring",
1312
"Represents the target program running under the debugger.
1413
@@ -968,6 +967,22 @@ public:
968967
lldb::SBValue
969968
EvaluateExpression (const char *expr, const lldb::SBExpressionOptions &options);
970969

970+
%extend {
971+
%nothreadallow;
972+
std::string lldb::SBTarget::__str__(){
973+
lldb::SBStream stream;
974+
$self->GetDescription (stream, lldb::eDescriptionLevelBrief);
975+
976+
const char *desc = stream.GetData();
977+
size_t desc_len = stream.GetSize();
978+
if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r'))
979+
--desc_len;
980+
981+
return std::string(desc, desc_len);
982+
}
983+
%clearnothreadallow;
984+
}
985+
971986
#ifdef SWIGPYTHON
972987
%pythoncode %{
973988
class modules_access(object):

lldb/scripts/lldb.swig

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def lldb_iter(obj, getsize, getelem):
9393
yield elem(i)
9494
%}
9595

96+
%include <std_string.i>
9697
%include "./Python/python-typemaps.swig"
9798
%include "./headers.swig"
9899

lldb/scripts/lldb_lua.swig

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
%module lldb
1010

11+
%include <std_string.i>
1112
%include "./headers.swig"
1213

1314
%{

0 commit comments

Comments
 (0)