From ceba071330ec0004d5d44cdb0ba9728df231c223 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Mon, 25 Mar 2013 17:37:39 +0000 Subject: - Masking out SBCommandReturnObject::Printf() from the Python layer because SWIG and varargs do not get along well. It is replaced by a Print("str") call which is equivalent to Printf("%s","str") - Providing file-like behavior for SBStream with appropriate extension write() and flush() calls, plus documenting that these are only meant and only exist for Python Documenting the file-like behavior on our website llvm-svn: 177877 --- .../scripts/Python/interface/SBCommandReturnObject.i | 10 ++++++++-- lldb/scripts/Python/python-extensions.swig | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'lldb/scripts/Python') diff --git a/lldb/scripts/Python/interface/SBCommandReturnObject.i b/lldb/scripts/Python/interface/SBCommandReturnObject.i index e5f062c..e72c1e2 100644 --- a/lldb/scripts/Python/interface/SBCommandReturnObject.i +++ b/lldb/scripts/Python/interface/SBCommandReturnObject.i @@ -86,8 +86,14 @@ public: void PutCString(const char* string, int len = -1); - size_t - Printf(const char* format, ...); + // wrapping the variadic Printf() with a plain Print() + // because it is hard to support varargs in SWIG bridgings + %extend { + void Print (const char* str) + { + self->Printf("%s", str); + } + } }; diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig index 84c719c..29eae6d 100644 --- a/lldb/scripts/Python/python-extensions.swig +++ b/lldb/scripts/Python/python-extensions.swig @@ -68,6 +68,12 @@ else return PyString_FromString(""); } + + /* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage + they are meant to make an SBCommandReturnObject into a file-like object so that instructions of the sort + print >>sb_command_return_object, "something" + will work correctly */ + void lldb::SBCommandReturnObject::write (const char* str) { if (str) @@ -272,6 +278,20 @@ return PyString_FromString(""); } } +%extend lldb::SBStream { + /* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage + they are meant to make an SBStream into a file-like object so that instructions of the sort + print >>sb_stream, "something" + will work correctly */ + + void lldb::SBStream::write (const char* str) + { + if (str) + $self->Printf("%s",str); + } + void lldb::SBStream::flush () + {} +} %extend lldb::SBSymbol { PyObject *lldb::SBSymbol::__str__ (){ lldb::SBStream description; -- cgit v1.1