Index: include/lldb/API/SBCommandReturnObject.h =================================================================== --- include/lldb/API/SBCommandReturnObject.h +++ include/lldb/API/SBCommandReturnObject.h @@ -83,7 +83,9 @@ bool GetDescription (lldb::SBStream &description); - + + // deprecated, these two functions do not take + // ownership of file handle void SetImmediateOutputFile (FILE *fh); @@ -91,6 +93,12 @@ SetImmediateErrorFile (FILE *fh); void + SetImmediateOutputFile (FILE *fh, bool transfer_ownership); + + void + SetImmediateErrorFile (FILE *fh, bool transfer_ownership); + + void PutCString(const char* string, int len = -1); size_t Index: scripts/interface/SBCommandReturnObject.i =================================================================== --- scripts/interface/SBCommandReturnObject.i +++ scripts/interface/SBCommandReturnObject.i @@ -16,6 +16,7 @@ See SBCommandInterpreter for example usage of SBCommandReturnObject." ) SBCommandReturnObject; + class SBCommandReturnObject { public: @@ -84,11 +85,17 @@ bool GetDescription (lldb::SBStream &description); - void - SetImmediateOutputFile (FILE *fh); - - void - SetImmediateErrorFile (FILE *fh); + + // wrapping here so that lldb takes ownership of the + // new FILE* created inside of the swig interface + %extend { + void SetImmediateOutputFile(FILE *fh) { + self->SetImmediateOutputFile(fh, true); + } + void SetImmediateErrorFile(FILE *fh) { + self->SetImmediateErrorFile(fh, true); + } + } void PutCString(const char* string, int len); Index: source/API/SBCommandReturnObject.cpp =================================================================== --- source/API/SBCommandReturnObject.cpp +++ source/API/SBCommandReturnObject.cpp @@ -258,15 +258,27 @@ void SBCommandReturnObject::SetImmediateOutputFile(FILE *fh) { - if (m_opaque_ap) - m_opaque_ap->SetImmediateOutputFile(fh); + SetImmediateOutputFile(fh, false); } void SBCommandReturnObject::SetImmediateErrorFile(FILE *fh) { + SetImmediateErrorFile(fh, false); +} + +void +SBCommandReturnObject::SetImmediateOutputFile(FILE *fh, bool transfer_ownership) +{ + if (m_opaque_ap) + m_opaque_ap->SetImmediateOutputFile(fh, transfer_ownership); +} + +void +SBCommandReturnObject::SetImmediateErrorFile(FILE *fh, bool transfer_ownership) +{ if (m_opaque_ap) - m_opaque_ap->SetImmediateErrorFile(fh); + m_opaque_ap->SetImmediateErrorFile(fh, transfer_ownership); } void