[PATCH] D131553: [analyzer] exploded-graph-rewriter: Fix python3 string encoding issues

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 11 07:09:13 PDT 2022


This revision was automatically updated to reflect the committed changes.
steakhal marked an inline comment as done.
Closed by commit rG5e876c54f2d7: [analyzer] exploded-graph-rewriter: Fix python3 string encoding issues (authored by steakhal).

Changed prior to commit:
  https://reviews.llvm.org/D131553?vs=451401&id=451846#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131553/new/

https://reviews.llvm.org/D131553

Files:
  clang/utils/analyzer/exploded-graph-rewriter.py


Index: clang/utils/analyzer/exploded-graph-rewriter.py
===================================================================
--- clang/utils/analyzer/exploded-graph-rewriter.py
+++ clang/utils/analyzer/exploded-graph-rewriter.py
@@ -18,7 +18,6 @@
 import logging
 import os
 import re
-import sys
 
 
 #===-----------------------------------------------------------------------===#
@@ -423,10 +422,7 @@
 
     def output(self):
         assert not self._dump_dot_only
-        if sys.version_info[0] > 2 and sys.version_info[1] >= 5:
-            return ''.join(self._output).encode()
-        else:
-            return ''.join(self._output)
+        return ''.join(self._output)
 
     def _dump(self, s):
         s = s.replace('&', '&') \
@@ -854,8 +850,8 @@
             import sys
             import tempfile
 
-            def write_temp_file(suffix, data):
-                fd, filename = tempfile.mkstemp(suffix=suffix)
+            def write_temp_file(suffix, prefix, data):
+                fd, filename = tempfile.mkstemp(suffix, prefix, '.', True)
                 print('Writing "%s"...' % filename)
                 with os.fdopen(fd, 'w') as fp:
                     fp.write(data)
@@ -873,13 +869,13 @@
                 print('You may also convert DOT to SVG manually via')
                 print('  $ dot -Tsvg input.dot -o output.svg')
                 print()
-                write_temp_file('.dot', self.output())
+                write_temp_file('.dot', 'egraph-', self.output())
                 return
 
-            svg = graphviz.pipe('dot', 'svg', self.output())
+            svg = graphviz.pipe('dot', 'svg', self.output().encode()).decode()
 
             filename = write_temp_file(
-                '.html', '<html><body bgcolor="%s">%s</body></html>' % (
+                '.html', 'egraph-', '<html><body bgcolor="%s">%s</body></html>' % (
                              '#1a1a1a' if self._dark_mode else 'white', svg))
             if sys.platform == 'win32':
                 os.startfile(filename)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131553.451846.patch
Type: text/x-patch
Size: 2035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220811/7d65b20e/attachment.bin>


More information about the cfe-commits mailing list