forked from OSchip/llvm-project
				
			convert SBDebugger::***FileHandle() wrappers to native files.
Summary: This patch converts the swig wrappers for SetInputFileHandle() and friends to emulate the old behavior using SetInputFile(). This will clear the way for deleting the FILE* typemaps altogether. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: mehdi_amini, dexonsmith, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68856 llvm-svn: 374912
This commit is contained in:
		
							parent
							
								
									d9b553ec99
								
							
						
					
					
						commit
						311dbb1bd7
					
				| 
						 | 
					@ -129,8 +129,6 @@ class FileHandleTestCase(lldbtest.TestBase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @add_test_categories(['pyapi'])
 | 
					    @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):
 | 
					    def test_legacy_file_out_script(self):
 | 
				
			||||||
        with open(self.out_filename, 'w') as f:
 | 
					        with open(self.out_filename, 'w') as f:
 | 
				
			||||||
            self.debugger.SetOutputFileHandle(f, False)
 | 
					            self.debugger.SetOutputFileHandle(f, False)
 | 
				
			||||||
| 
						 | 
					@ -155,8 +153,6 @@ class FileHandleTestCase(lldbtest.TestBase):
 | 
				
			||||||
            self.assertIn('deadbeef', f.read())
 | 
					            self.assertIn('deadbeef', f.read())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @add_test_categories(['pyapi'])
 | 
					    @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):
 | 
					    def test_legacy_file_err_with_get(self):
 | 
				
			||||||
        with open(self.out_filename, 'w') as f:
 | 
					        with open(self.out_filename, 'w') as f:
 | 
				
			||||||
            self.debugger.SetErrorFileHandle(f, False)
 | 
					            self.debugger.SetErrorFileHandle(f, False)
 | 
				
			||||||
| 
						 | 
					@ -194,11 +190,11 @@ class FileHandleTestCase(lldbtest.TestBase):
 | 
				
			||||||
    @add_test_categories(['pyapi'])
 | 
					    @add_test_categories(['pyapi'])
 | 
				
			||||||
    def test_sbfile_type_errors(self):
 | 
					    def test_sbfile_type_errors(self):
 | 
				
			||||||
        sbf = lldb.SBFile()
 | 
					        sbf = lldb.SBFile()
 | 
				
			||||||
        self.assertRaises(TypeError, sbf.Write, None)
 | 
					        self.assertRaises(Exception, sbf.Write, None)
 | 
				
			||||||
        self.assertRaises(TypeError, sbf.Read, None)
 | 
					        self.assertRaises(Exception, sbf.Read, None)
 | 
				
			||||||
        self.assertRaises(TypeError, sbf.Read, b'this bytes is not mutable')
 | 
					        self.assertRaises(Exception, sbf.Read, b'this bytes is not mutable')
 | 
				
			||||||
        self.assertRaises(TypeError, sbf.Write, u"ham sandwich")
 | 
					        self.assertRaises(Exception, sbf.Write, u"ham sandwich")
 | 
				
			||||||
        self.assertRaises(TypeError, sbf.Read, u"ham sandwich")
 | 
					        self.assertRaises(Exception, sbf.Read, u"ham sandwich")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @add_test_categories(['pyapi'])
 | 
					    @add_test_categories(['pyapi'])
 | 
				
			||||||
| 
						 | 
					@ -859,3 +855,40 @@ class FileHandleTestCase(lldbtest.TestBase):
 | 
				
			||||||
        with open(self.out_filename, 'r') as f:
 | 
					        with open(self.out_filename, 'r') as f:
 | 
				
			||||||
            self.assertEqual(list(range(10)), list(map(int, f.read().strip().split())))
 | 
					            self.assertEqual(list(range(10)), list(map(int, f.read().strip().split())))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @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)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -165,29 +165,44 @@ public:
 | 
				
			||||||
    void
 | 
					    void
 | 
				
			||||||
    SkipLLDBInitFiles (bool b);
 | 
					    SkipLLDBInitFiles (bool b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    %feature("autodoc", "DEPRECATED, use SetInputFile");
 | 
					    %pythoncode %{
 | 
				
			||||||
    void
 | 
					        def SetOutputFileHandle(self, file, transfer_ownership):
 | 
				
			||||||
    SetInputFileHandle (FILE *f, bool transfer_ownership);
 | 
					            "DEPRECATED, use SetOutputFile"
 | 
				
			||||||
 | 
					            if file is None:
 | 
				
			||||||
 | 
					                import sys
 | 
				
			||||||
 | 
					                file = sys.stdout
 | 
				
			||||||
 | 
					            self.SetOutputFile(SBFile.Create(file, borrow=True))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    %feature("autodoc", "DEPRECATED, use SetOutputFile");
 | 
					        def SetInputFileHandle(self, file, transfer_ownership):
 | 
				
			||||||
    void
 | 
					            "DEPRECATED, use SetInputFile"
 | 
				
			||||||
    SetOutputFileHandle (FILE *f, bool transfer_ownership);
 | 
					            if file is None:
 | 
				
			||||||
 | 
					                import sys
 | 
				
			||||||
 | 
					                file = sys.stdin
 | 
				
			||||||
 | 
					            self.SetInputFile(SBFile.Create(file, borrow=True))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    %feature("autodoc", "DEPRECATED, use SetErrorFile");
 | 
					        def SetErrorFileHandle(self, file, transfer_ownership):
 | 
				
			||||||
    void
 | 
					            "DEPRECATED, use SetErrorFile"
 | 
				
			||||||
    SetErrorFileHandle (FILE *f, bool transfer_ownership);
 | 
					            if file is None:
 | 
				
			||||||
 | 
					                import sys
 | 
				
			||||||
 | 
					                file = sys.stderr
 | 
				
			||||||
 | 
					            self.SetErrorFile(SBFile.Create(file, borrow=True))
 | 
				
			||||||
 | 
					    %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    %feature("autodoc", "DEPRECATED, use GetInputFile");
 | 
					 | 
				
			||||||
    FILE *
 | 
					 | 
				
			||||||
    GetInputFileHandle ();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    %feature("autodoc", "DEPRECATED, use GetOutputFile");
 | 
					    %extend {
 | 
				
			||||||
    FILE *
 | 
					 | 
				
			||||||
    GetOutputFileHandle ();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    %feature("autodoc", "DEPRECATED, use GetErrorFile");
 | 
					        lldb::FileSP GetInputFileHandle() {
 | 
				
			||||||
    FILE *
 | 
					            return self->GetInputFile().GetFile();
 | 
				
			||||||
    GetErrorFileHandle ();
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        lldb::FileSP GetOutputFileHandle() {
 | 
				
			||||||
 | 
					            return self->GetOutputFile().GetFile();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        lldb::FileSP GetErrorFileHandle() {
 | 
				
			||||||
 | 
					            return self->GetErrorFile().GetFile();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    SBError
 | 
					    SBError
 | 
				
			||||||
    SetInputFile (SBFile file);
 | 
					    SetInputFile (SBFile file);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue