Fix output handling to avoid potential UnicodeEncodeError.
authorZac Medico <zmedico@gentoo.org>
Tue, 12 Jan 2010 02:47:50 +0000 (02:47 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 12 Jan 2010 02:47:50 +0000 (02:47 -0000)
svn path=/main/trunk/; revision=15196

bin/check-implicit-pointer-usage.py

index ebd4c362964c4ce1438595597119113f05d72d0f..1f6417b58732deb0a3f8aee1613e7c9ed0cea8f0 100755 (executable)
@@ -37,15 +37,20 @@ if sys.hexversion < 0x3000000:
     pointer_pattern = unicode(pointer_pattern, encoding='utf_8')
     unicode_quote_open = unicode('\xE2\x80\x98', encoding='utf_8')
     unicode_quote_close = unicode('\xE2\x80\x99', encoding='utf_8')
+    out = sys.stdout
 else:
     unicode_quote_open = '\u2018'
     unicode_quote_close = '\u2019'
+    out = sys.stdout.buffer
 pointer_pattern = re.compile(pointer_pattern)
 
 last_implicit_filename = ""
 last_implicit_linenum = -1
 last_implicit_func = ""
 
+def write(msg):
+    out.write(msg.encode('utf_8', 'backslashreplace'))
+
 while True:
     if sys.hexversion >= 0x3000000:
         line = sys.stdin.buffer.readline().decode('utf_8', 'replace')
@@ -69,6 +74,7 @@ while True:
             pointer_linenum = int(m.group(2))
             if (last_implicit_filename == pointer_filename
                 and last_implicit_linenum == pointer_linenum):
-                print(("Function `%s' implicitly converted to pointer at " \
-                      "%s:%d" % (last_implicit_func, last_implicit_filename,
-                                 last_implicit_linenum)))
+                write("Function `%s' implicitly converted to pointer at " \
+                      "%s:%d\n" % (last_implicit_func,
+                                   last_implicit_filename,
+                                   last_implicit_linenum))