forked from OSchip/llvm-project
Added Repr() and Str() member functions to our PythonObject class to allow easy conversion to-string of every PythonObject
llvm-svn: 186205
This commit is contained in:
parent
456ed25149
commit
b8b0bf9b81
|
@ -99,6 +99,12 @@ namespace lldb_private {
|
|||
return m_py_obj;
|
||||
}
|
||||
|
||||
PythonString
|
||||
Repr ();
|
||||
|
||||
PythonString
|
||||
Str ();
|
||||
|
||||
operator bool () const
|
||||
{
|
||||
return m_py_obj != NULL;
|
||||
|
|
|
@ -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
|
||||
//----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue