[Lldb-commits] [PATCH] D72377: [ldlb/SWIG] Refactor extensions to be non Python-specific.

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 8 10:40:16 PST 2020


JDevlieghere updated this revision to Diff 236861.
JDevlieghere added a comment.

- Use `std::string`
- Move extension into the corresponding interface file


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72377/new/

https://reviews.llvm.org/D72377

Files:
  lldb/scripts/Python/python-extensions.swig
  lldb/scripts/interface/SBTarget.i
  lldb/scripts/lldb.swig
  lldb/scripts/lldb_lua.swig


Index: lldb/scripts/lldb_lua.swig
===================================================================
--- lldb/scripts/lldb_lua.swig
+++ lldb/scripts/lldb_lua.swig
@@ -8,6 +8,7 @@
 
 %module lldb
 
+%include <std_string.i>
 %include "./headers.swig"
 
 %{
Index: lldb/scripts/lldb.swig
===================================================================
--- lldb/scripts/lldb.swig
+++ lldb/scripts/lldb.swig
@@ -93,6 +93,7 @@
         yield elem(i)
 %}
 
+%include <std_string.i>
 %include "./Python/python-typemaps.swig"
 %include "./headers.swig"
 
Index: lldb/scripts/interface/SBTarget.i
===================================================================
--- lldb/scripts/interface/SBTarget.i
+++ 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 @@
     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):
@@ -1067,3 +1082,5 @@
 #endif
 };
 } // namespace lldb
+
+
Index: lldb/scripts/Python/python-extensions.swig
===================================================================
--- lldb/scripts/Python/python-extensions.swig
+++ lldb/scripts/Python/python-extensions.swig
@@ -502,18 +502,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)):


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72377.236861.patch
Type: text/x-patch
Size: 2514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200108/c78b6eb3/attachment.bin>


More information about the lldb-commits mailing list