Skip to content

Commit

Permalink
Handle UTF-16LE input.
Browse files Browse the repository at this point in the history
Fixes #88
  • Loading branch information
jrfonseca committed May 21, 2024
1 parent 14e0d54 commit bef72e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion gprof2dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import locale
import json
import fnmatch
import codecs
import io

assert sys.version_info[0] >= 3

Expand Down Expand Up @@ -3566,7 +3568,15 @@ def main(argv=sys.argv[1:]):
if not args:
fp = sys.stdin
else:
fp = open(args[0], 'rt', encoding='UTF-8')
fp = open(args[0], 'rb')
bom = fp.read(2)
if bom == codecs.BOM_UTF16_LE:
# Default on Windows PowerShell (https://github.com/jrfonseca/gprof2dot/issues/88)
encoding = 'utf-16le'
else:
encoding = 'utf-8'
fp.seek(0)
fp = io.TextIOWrapper(fp, encoding=encoding)
parser = Format(fp)
elif Format.multipleInput:
if not args:
Expand Down
Binary file added tests/prof/issue88.prof
Binary file not shown.

0 comments on commit bef72e3

Please sign in to comment.