From b8b0bf9b81de68d4e6776265cb3db75ae6315336 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Fri, 12 Jul 2013 21:11:02 +0000 Subject: [PATCH] Added Repr() and Str() member functions to our PythonObject class to allow easy conversion to-string of every PythonObject llvm-svn: 186205 --- lldb/include/lldb/Interpreter/PythonDataObjects.h | 6 ++++++ lldb/source/Interpreter/PythonDataObjects.cpp | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lldb/include/lldb/Interpreter/PythonDataObjects.h b/lldb/include/lldb/Interpreter/PythonDataObjects.h index 3893e3b..b2c9240 100644 --- a/lldb/include/lldb/Interpreter/PythonDataObjects.h +++ b/lldb/include/lldb/Interpreter/PythonDataObjects.h @@ -99,6 +99,12 @@ namespace lldb_private { return m_py_obj; } + PythonString + Repr (); + + PythonString + Str (); + operator bool () const { return m_py_obj != NULL; diff --git a/lldb/source/Interpreter/PythonDataObjects.cpp b/lldb/source/Interpreter/PythonDataObjects.cpp index e59e75a..2a1f348 100644 --- a/lldb/source/Interpreter/PythonDataObjects.cpp +++ b/lldb/source/Interpreter/PythonDataObjects.cpp @@ -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 //---------------------------------------------------------------------- -- 2.7.4