[llvm] [llvm-lit] Resolve TypeError in built-in cat -v implementation (PR #98363)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 10 11:14:35 PDT 2024


https://github.com/connieyzhu created https://github.com/llvm/llvm-project/pull/98363

When using -v in lit's internal implementation of cat, there is a TypeError when the file data is passed into convertToCaretAndMNotation() as a str, because bytearray() requires an encoded string. This patch encodes the str before passing it through bytearray().

>From fca041412d938f4c5c71d3660ae364b70739c3e9 Mon Sep 17 00:00:00 2001
From: Connie Zhu <connieyzhu at google.com>
Date: Wed, 10 Jul 2024 17:52:33 +0000
Subject: [PATCH] [llvm-lit] Resolve TypeError in built-in cat -v
 implementation

When using -v in lit's internal implementation of cat, there
is a TypeError when the file data is passed into convertToCaretAndMNotation()
as a str, because bytearray() requires an encoded string. This patch
encodes the str before passing it through bytearray().
---
 llvm/utils/lit/lit/builtin_commands/cat.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/lit/lit/builtin_commands/cat.py b/llvm/utils/lit/lit/builtin_commands/cat.py
index 6fb2152ef9332..d6dbe889cc2b1 100644
--- a/llvm/utils/lit/lit/builtin_commands/cat.py
+++ b/llvm/utils/lit/lit/builtin_commands/cat.py
@@ -10,7 +10,7 @@
 def convertToCaretAndMNotation(data):
     newdata = StringIO()
     if isinstance(data, str):
-        data = bytearray(data)
+        data = bytearray(data.encode())
 
     for intval in data:
         if intval == 9 or intval == 10:



More information about the llvm-commits mailing list