[PATCH] [LIT] Decode string result in lit.util.capture

Eric Fiselier eric at efcs.ca
Tue Dec 23 00:50:38 PST 2014


Hi ddunbar,

I think this is probably a bug, but I'm putting this up for review just to be sure. I think that `lit.util.capture` should decode the resulting string in the same way `lit.util.executeCommand` does.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D6769

Files:
  utils/lit/lit/util.py

Index: utils/lit/lit/util.py
===================================================================
--- utils/lit/lit/util.py
+++ utils/lit/lit/util.py
@@ -16,6 +16,12 @@
         return bytes
     return to_bytes(bytes)
 
+def convert_string(bytes):
+    try:
+        return to_string(bytes.decode('utf-8'))
+    except UnicodeError:
+        return str(bytes)
+
 def detectCPUs():
     """
     Detects the number of CPUs on a system. Cribbed from pp.
@@ -60,7 +66,7 @@
     p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                          env=env)
     out,_ = p.communicate()
-    return out
+    return convert_string(out)
 
 def which(command, paths = None):
     """which(command, [paths]) - Look up the given command in the paths string
@@ -166,14 +172,8 @@
         raise KeyboardInterrupt
 
     # Ensure the resulting output is always of string type.
-    try:
-        out = to_string(out.decode('utf-8'))
-    except:
-        out = str(out)
-    try:
-        err = to_string(err.decode('utf-8'))
-    except:
-        err = str(err)
+    out = convert_string(out)
+    err = convert_string(err)
 
     return out, err, exitCode

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6769.17585.patch
Type: text/x-patch
Size: 1179 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141223/8563bcef/attachment.bin>


More information about the llvm-commits mailing list