diff --git a/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py b/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py --- a/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py +++ b/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py @@ -129,8 +129,6 @@ @add_test_categories(['pyapi']) - @skipIfWindows # FIXME pre-existing bug, should be fixed - # when we delete the FILE* typemaps. def test_legacy_file_out_script(self): with open(self.out_filename, 'w') as f: self.debugger.SetOutputFileHandle(f, False) @@ -155,8 +153,6 @@ self.assertIn('deadbeef', f.read()) @add_test_categories(['pyapi']) - @skipIfWindows # FIXME pre-existing bug, should be fixed - # when we delete the FILE* typemaps. def test_legacy_file_err_with_get(self): with open(self.out_filename, 'w') as f: self.debugger.SetErrorFileHandle(f, False) @@ -194,11 +190,11 @@ @add_test_categories(['pyapi']) def test_sbfile_type_errors(self): sbf = lldb.SBFile() - self.assertRaises(TypeError, sbf.Write, None) - self.assertRaises(TypeError, sbf.Read, None) - self.assertRaises(TypeError, sbf.Read, b'this bytes is not mutable') - self.assertRaises(TypeError, sbf.Write, u"ham sandwich") - self.assertRaises(TypeError, sbf.Read, u"ham sandwich") + self.assertRaises(Exception, sbf.Write, None) + self.assertRaises(Exception, sbf.Read, None) + self.assertRaises(Exception, sbf.Read, b'this bytes is not mutable') + self.assertRaises(Exception, sbf.Write, u"ham sandwich") + self.assertRaises(Exception, sbf.Read, u"ham sandwich") @add_test_categories(['pyapi']) @@ -825,3 +821,40 @@ with open(self.out_filename, 'r') as f: self.assertEqual("foobar", f.read().strip()) + + @add_test_categories(['pyapi']) + def test_set_filehandle_none(self): + self.assertRaises(Exception, self.debugger.SetOutputFile, None) + self.assertRaises(Exception, self.debugger.SetOutputFile, "ham sandwich") + self.assertRaises(Exception, self.debugger.SetOutputFileHandle, "ham sandwich") + self.assertRaises(Exception, self.debugger.SetInputFile, None) + self.assertRaises(Exception, self.debugger.SetInputFile, "ham sandwich") + self.assertRaises(Exception, self.debugger.SetInputFileHandle, "ham sandwich") + self.assertRaises(Exception, self.debugger.SetErrorFile, None) + self.assertRaises(Exception, self.debugger.SetErrorFile, "ham sandwich") + self.assertRaises(Exception, self.debugger.SetErrorFileHandle, "ham sandwich") + + with open(self.out_filename, 'w') as f: + status = self.debugger.SetOutputFile(f) + self.assertTrue(status.Success()) + status = self.debugger.SetErrorFile(f) + self.assertTrue(status.Success()) + self.debugger.SetOutputFileHandle(None, False) + self.debugger.SetErrorFileHandle(None, False) + sbf = self.debugger.GetOutputFile() + if sys.version_info.major >= 3: + # python 2 lacks PyFile_FromFd, so GetFile() will + # have to duplicate the file descriptor and make a FILE* + # in order to convert a NativeFile it back to a python + # file. + self.assertEqual(sbf.GetFile().fileno(), 1) + sbf = self.debugger.GetErrorFile() + if sys.version_info.major >= 3: + self.assertEqual(sbf.GetFile().fileno(), 2) + with open(self.out_filename, 'r') as f: + status = self.debugger.SetInputFile(f) + self.assertTrue(status.Success()) + self.debugger.SetInputFileHandle(None, False) + sbf = self.debugger.GetInputFile() + if sys.version_info.major >= 3: + self.assertEqual(sbf.GetFile().fileno(), 0) diff --git a/lldb/scripts/interface/SBDebugger.i b/lldb/scripts/interface/SBDebugger.i --- a/lldb/scripts/interface/SBDebugger.i +++ b/lldb/scripts/interface/SBDebugger.i @@ -165,29 +165,44 @@ void SkipLLDBInitFiles (bool b); - %feature("autodoc", "DEPRECATED, use SetInputFile"); - void - SetInputFileHandle (FILE *f, bool transfer_ownership); + %pythoncode %{ + def SetOutputFileHandle(self, file, transfer_ownership): + "DEPRECATED, use SetOutputFile" + if file is None: + import sys + file = sys.stdout + self.SetOutputFile(SBFile.Create(file, borrow=True)) + + def SetInputFileHandle(self, file, transfer_ownership): + "DEPRECATED, use SetInputFile" + if file is None: + import sys + file = sys.stdin + self.SetInputFile(SBFile.Create(file, borrow=True)) + + def SetErrorFileHandle(self, file, transfer_ownership): + "DEPRECATED, use SetErrorFile" + if file is None: + import sys + file = sys.stderr + self.SetErrorFile(SBFile.Create(file, borrow=True)) + %} - %feature("autodoc", "DEPRECATED, use SetOutputFile"); - void - SetOutputFileHandle (FILE *f, bool transfer_ownership); - %feature("autodoc", "DEPRECATED, use SetErrorFile"); - void - SetErrorFileHandle (FILE *f, bool transfer_ownership); + %extend { - %feature("autodoc", "DEPRECATED, use GetInputFile"); - FILE * - GetInputFileHandle (); + lldb::FileSP GetInputFileHandle() { + return self->GetInputFile().GetFile(); + } - %feature("autodoc", "DEPRECATED, use GetOutputFile"); - FILE * - GetOutputFileHandle (); + lldb::FileSP GetOutputFileHandle() { + return self->GetOutputFile().GetFile(); + } - %feature("autodoc", "DEPRECATED, use GetErrorFile"); - FILE * - GetErrorFileHandle (); + lldb::FileSP GetErrorFileHandle() { + return self->GetErrorFile().GetFile(); + } + } SBError SetInputFile (SBFile file);