[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
Tue Jan 7 17:16:50 PST 2020


JDevlieghere created this revision.
JDevlieghere added a reviewer: labath.
Herald added a project: LLDB.
JDevlieghere marked 2 inline comments as done.
JDevlieghere added inline comments.


================
Comment at: lldb/scripts/extensions.swig:4
+  const char *lldb::SBTarget::__str__ (){
+    lldb::SBStream stream;
+    $self->GetDescription (stream, lldb::eDescriptionLevelBrief);
----------------
of course this should be factored out and reused across different SB classes. 


================
Comment at: lldb/scripts/lldb.swig:100
 %{
+#include "../include/lldb/Utility/ConstString.h"
 #include "../source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h"
----------------
This is unfortunate but not worse that what's already done for `PythonDataObjects.h`. 


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 Lua. I propose to rewrite this extension by using `ConstString` instead.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D72377

Files:
  lldb/scripts/Python/python-extensions.swig
  lldb/scripts/extensions.swig
  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
@@ -11,8 +11,10 @@
 %include "./headers.swig"
 
 %{
+#include "../include/lldb/Utility/ConstString.h"
 using namespace lldb_private;
 using namespace lldb;
 %}
 
+%include "./extensions.swig"
 %include "./interfaces.swig"
Index: lldb/scripts/lldb.swig
===================================================================
--- lldb/scripts/lldb.swig
+++ lldb/scripts/lldb.swig
@@ -97,6 +97,7 @@
 %include "./headers.swig"
 
 %{
+#include "../include/lldb/Utility/ConstString.h"
 #include "../source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h"
 #include "../scripts/Python/python-swigsafecast.swig"
 using namespace lldb_private;
@@ -105,6 +106,7 @@
 %}
 
 %include "./interfaces.swig"
+%include "./extensions.swig"
 %include "./Python/python-extensions.swig"
 %include "./Python/python-wrapper.swig"
 
Index: lldb/scripts/extensions.swig
===================================================================
--- /dev/null
+++ lldb/scripts/extensions.swig
@@ -0,0 +1,17 @@
+%extend lldb::SBTarget {
+  %nothreadallow;
+  const char *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;
+
+    lldb_private::ConstString str(desc, desc_len);
+    return str.GetCString();
+  }
+  %clearnothreadallow;
+}
+
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.236722.patch
Type: text/x-patch
Size: 2560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200108/51a010d9/attachment-0001.bin>


More information about the lldb-commits mailing list