[Lldb-commits] [lldb] r186205 - Added Repr() and Str() member functions to our PythonObject class to allow easy conversion to-string of every PythonObject

Enrico Granata egranata at apple.com
Fri Jul 12 14:11:03 PDT 2013


Author: enrico
Date: Fri Jul 12 16:11:02 2013
New Revision: 186205

URL: http://llvm.org/viewvc/llvm-project?rev=186205&view=rev
Log:
Added Repr() and Str() member functions to our PythonObject class to allow easy conversion to-string of every PythonObject

Modified:
    lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h
    lldb/trunk/source/Interpreter/PythonDataObjects.cpp

Modified: lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h?rev=186205&r1=186204&r2=186205&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h (original)
+++ lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h Fri Jul 12 16:11:02 2013
@@ -99,6 +99,12 @@ namespace lldb_private {
             return m_py_obj;
         }
         
+        PythonString
+        Repr ();
+        
+        PythonString
+        Str ();
+        
         operator bool () const
         {
             return m_py_obj != NULL;

Modified: lldb/trunk/source/Interpreter/PythonDataObjects.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/PythonDataObjects.cpp?rev=186205&r1=186204&r2=186205&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/PythonDataObjects.cpp (original)
+++ lldb/trunk/source/Interpreter/PythonDataObjects.cpp Fri Jul 12 16:11:02 2013
@@ -66,6 +66,28 @@ PythonObject::Dump (Stream &strm) const
         strm.PutCString ("NULL");
 }
 
+PythonString
+PythonObject::Repr ()
+{
+    if (!m_py_obj)
+        return PythonString ();
+    PyObject *repr = PyObject_Repr(m_py_obj);
+    if (!repr)
+        return PythonString ();
+    return PythonString(repr);
+}
+
+PythonString
+PythonObject::Str ()
+{
+    if (!m_py_obj)
+        return PythonString ();
+    PyObject *str = PyObject_Str(m_py_obj);
+    if (!str)
+        return PythonString ();
+    return PythonString(str);
+}
+
 //----------------------------------------------------------------------
 // PythonString
 //----------------------------------------------------------------------





More information about the lldb-commits mailing list