[Lldb-commits] [PATCH] D53166: [lldbsuite] Fix the filecheck functionality to work with Python 3

Stella Stamenova via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 11 13:38:29 PDT 2018

stella.stamenova created this revision.
stella.stamenova added reviewers: zturner, asmith.
Herald added a subscriber: lldb-commits.

This is another string/byte conversion issue between Python 2 and 3. In Python 2, the subprocess communication expects a byte string, but in Python 3, it expects bytes.

There are a pair of functions to_bytes/to_string in lit that implement the correct conversion, but they're not available throughout the lldb suite which is why this fix is 'in place' rather than calling one of these functions.




Index: packages/Python/lldbsuite/test/lldbtest.py
--- packages/Python/lldbsuite/test/lldbtest.py
+++ packages/Python/lldbsuite/test/lldbtest.py
@@ -2227,6 +2227,10 @@
         # Get the error text if there was an error, and the regular text if not.
         output = self.res.GetOutput() if self.res.Succeeded() \
                 else self.res.GetError()
+        # In Python 2, communicate sends byte strings. In Python 3, communicate sends bytes.
+        # If we got a string (and not a byte string), encode it before sending.
+        if isinstance(output, str) and not isinstance(output, bytes):
+            output = output.encode()
         # Assemble the absolute path to the check file. As a convenience for
         # LLDB inline tests, assume that the check file is a relative path to

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53166.169294.patch
Type: text/x-patch
Size: 867 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20181011/6133a99b/attachment.bin>

More information about the lldb-commits mailing list