Author: lawrence_danna Date: Tue Oct 15 10:41:40 2019 New Revision: 374924 URL: http://llvm.org/viewvc/llvm-project?rev=374924&view=rev Log: remove FILE* usage from SBStream.i
Summary: This patch removes FILE* and replaces it with SBFile and FileSP the SWIG interface for `SBStream.i`. And this is the last one. With this change, nothing in the python API will can access a FILE* method on the C++ side. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68960 Modified: lldb/trunk/include/lldb/API/SBStream.h lldb/trunk/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py lldb/trunk/scripts/interface/SBStream.i lldb/trunk/source/API/SBStream.cpp Modified: lldb/trunk/include/lldb/API/SBStream.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBStream.h?rev=374924&r1=374923&r2=374924&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBStream.h (original) +++ lldb/trunk/include/lldb/API/SBStream.h Tue Oct 15 10:41:40 2019 @@ -39,6 +39,10 @@ public: void RedirectToFile(const char *path, bool append); + void RedirectToFile(lldb::SBFile file); + + void RedirectToFile(lldb::FileSP file); + void RedirectToFileHandle(FILE *fh, bool transfer_fh_ownership); void RedirectToFileDescriptor(int fd, bool transfer_fh_ownership); Modified: lldb/trunk/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py?rev=374924&r1=374923&r2=374924&view=diff ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py (original) +++ lldb/trunk/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py Tue Oct 15 10:41:40 2019 @@ -892,3 +892,30 @@ class FileHandleTestCase(lldbtest.TestBa sbf = self.debugger.GetInputFile() if sys.version_info.major >= 3: self.assertEqual(sbf.GetFile().fileno(), 0) + + + @add_test_categories(['pyapi']) + def test_sbstream(self): + + with open(self.out_filename, 'w') as f: + stream = lldb.SBStream() + stream.RedirectToFile(f) + stream.Print("zork") + with open(self.out_filename, 'r') as f: + self.assertEqual(f.read().strip(), "zork") + + with open(self.out_filename, 'w') as f: + stream = lldb.SBStream() + stream.RedirectToFileHandle(f, True) + stream.Print("Yendor") + with open(self.out_filename, 'r') as f: + self.assertEqual(f.read().strip(), "Yendor") + + stream = lldb.SBStream() + f = open(self.out_filename, 'w') + stream.RedirectToFile(lldb.SBFile.Create(f, borrow=False)) + stream.Print("Frobozz") + stream = None + self.assertTrue(f.closed) + with open(self.out_filename, 'r') as f: + self.assertEqual(f.read().strip(), "Frobozz") Modified: lldb/trunk/scripts/interface/SBStream.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBStream.i?rev=374924&r1=374923&r2=374924&view=diff ============================================================================== --- lldb/trunk/scripts/interface/SBStream.i (original) +++ lldb/trunk/scripts/interface/SBStream.i Tue Oct 15 10:41:40 2019 @@ -75,7 +75,18 @@ public: RedirectToFile (const char *path, bool append); void - RedirectToFileHandle (FILE *fh, bool transfer_fh_ownership); + RedirectToFile (lldb::SBFile file); + + void + RedirectToFile (lldb::FileSP file); + + %extend { + %feature("autodoc", "DEPRECATED, use RedirectToFile"); + void + RedirectToFileHandle (lldb::FileSP file, bool transfer_fh_ownership) { + self->RedirectToFile(file); + } + } void RedirectToFileDescriptor (int fd, bool transfer_fh_ownership); Modified: lldb/trunk/source/API/SBStream.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBStream.cpp?rev=374924&r1=374923&r2=374924&view=diff ============================================================================== --- lldb/trunk/source/API/SBStream.cpp (original) +++ lldb/trunk/source/API/SBStream.cpp Tue Oct 15 10:41:40 2019 @@ -9,6 +9,7 @@ #include "lldb/API/SBStream.h" #include "SBReproducerPrivate.h" +#include "lldb/API/SBFile.h" #include "lldb/Core/StreamFile.h" #include "lldb/Host/FileSystem.h" #include "lldb/Utility/Status.h" @@ -108,8 +109,19 @@ void SBStream::RedirectToFile(const char void SBStream::RedirectToFileHandle(FILE *fh, bool transfer_fh_ownership) { LLDB_RECORD_METHOD(void, SBStream, RedirectToFileHandle, (FILE *, bool), fh, transfer_fh_ownership); + FileSP file = std::make_unique<NativeFile>(fh, transfer_fh_ownership); + return RedirectToFile(file); +} + +void SBStream::RedirectToFile(SBFile file) { + LLDB_RECORD_METHOD(void, SBStream, RedirectToFile, (SBFile), file) + RedirectToFile(file.GetFile()); +} + +void SBStream::RedirectToFile(FileSP file_sp) { + LLDB_RECORD_METHOD(void, SBStream, RedirectToFile, (FileSP), file_sp); - if (fh == nullptr) + if (!file_sp || !file_sp->IsValid()) return; std::string local_data; @@ -120,7 +132,7 @@ void SBStream::RedirectToFileHandle(FILE local_data = static_cast<StreamString *>(m_opaque_up.get())->GetString(); } - m_opaque_up = std::make_unique<StreamFile>(fh, transfer_fh_ownership); + m_opaque_up = std::make_unique<StreamFile>(file_sp); m_is_file = true; // If we had any data locally in our StreamString, then pass that along to @@ -184,6 +196,8 @@ void RegisterMethods<SBStream>(Registry LLDB_REGISTER_METHOD(const char *, SBStream, GetData, ()); LLDB_REGISTER_METHOD(size_t, SBStream, GetSize, ()); LLDB_REGISTER_METHOD(void, SBStream, RedirectToFile, (const char *, bool)); + LLDB_REGISTER_METHOD(void, SBStream, RedirectToFile, (FileSP)); + LLDB_REGISTER_METHOD(void, SBStream, RedirectToFile, (SBFile)); LLDB_REGISTER_METHOD(void, SBStream, RedirectToFileHandle, (FILE *, bool)); LLDB_REGISTER_METHOD(void, SBStream, RedirectToFileDescriptor, (int, bool)); LLDB_REGISTER_METHOD(void, SBStream, Clear, ()); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits