Author: lawrence_danna
Date: Tue Oct 15 09:59:20 2019
New Revision: 374912

URL: http://llvm.org/viewvc/llvm-project?rev=374912&view=rev
Log:
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

Modified:
    
lldb/trunk/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
    lldb/trunk/scripts/interface/SBDebugger.i

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=374912&r1=374911&r2=374912&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 09:59:20 2019
@@ -129,8 +129,6 @@ class FileHandleTestCase(lldbtest.TestBa
 
 
     @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 @@ class FileHandleTestCase(lldbtest.TestBa
             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 @@ class FileHandleTestCase(lldbtest.TestBa
     @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'])
@@ -859,3 +855,40 @@ class FileHandleTestCase(lldbtest.TestBa
         with open(self.out_filename, 'r') as f:
             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)

Modified: lldb/trunk/scripts/interface/SBDebugger.i
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBDebugger.i?rev=374912&r1=374911&r2=374912&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBDebugger.i (original)
+++ lldb/trunk/scripts/interface/SBDebugger.i Tue Oct 15 09:59:20 2019
@@ -165,29 +165,44 @@ public:
     void
     SkipLLDBInitFiles (bool b);
 
-    %feature("autodoc", "DEPRECATED, use SetInputFile");
-    void
-    SetInputFileHandle (FILE *f, bool transfer_ownership);
-
-    %feature("autodoc", "DEPRECATED, use SetOutputFile");
-    void
-    SetOutputFileHandle (FILE *f, bool transfer_ownership);
-
-    %feature("autodoc", "DEPRECATED, use SetErrorFile");
-    void
-    SetErrorFileHandle (FILE *f, bool transfer_ownership);
-
-    %feature("autodoc", "DEPRECATED, use GetInputFile");
-    FILE *
-    GetInputFileHandle ();
-
-    %feature("autodoc", "DEPRECATED, use GetOutputFile");
-    FILE *
-    GetOutputFileHandle ();
-
-    %feature("autodoc", "DEPRECATED, use GetErrorFile");
-    FILE *
-    GetErrorFileHandle ();
+    %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))
+    %}
+
+
+    %extend {
+
+        lldb::FileSP GetInputFileHandle() {
+            return self->GetInputFile().GetFile();
+        }
+
+        lldb::FileSP GetOutputFileHandle() {
+            return self->GetOutputFile().GetFile();
+        }
+
+        lldb::FileSP GetErrorFileHandle() {
+            return self->GetErrorFile().GetFile();
+        }
+    }
 
     SBError
     SetInputFile (SBFile file);


_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to