[PATCH] D133236: [Clang][Tools] Use utf-8 for JSON object load
Amy Wang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 2 14:47:15 PDT 2022
kaitingwang created this revision.
kaitingwang added reviewers: djasper, sammccall, ldrumm, vsk.
kaitingwang added a project: clang-format.
Herald added subscribers: Naghasan, Anastasia.
Herald added a project: All.
kaitingwang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
>From Python 3.6 and above, it should be able to automatically select a decoding for the json.loads. However, with a vim encoding that defaults to utf-8, the clang-format.py runs into the following error. The patch explicit specifies to use use utf-8 decoding for head.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/k00375917/sycl_workspace/llvm/clang/tools/clang-format/clang-format.py", line 156, in <module>
main()
File "/home/k00375917/sycl_workspace/llvm/clang/tools/clang-format/clang-format.py", line 137, in main
header = json.loads(header)
File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133236
Files:
clang/tools/clang-format/clang-format.py
Index: clang/tools/clang-format/clang-format.py
===================================================================
--- clang/tools/clang-format/clang-format.py
+++ clang/tools/clang-format/clang-format.py
@@ -10,9 +10,9 @@
# imap <C-I> <c-o>:py3f <path-to-this-file>/clang-format.py<cr>
# endif
#
-# The if-elseif-endif conditional should pick either the python3 or python2
+# The if-elseif-endif conditional should pick either the python3 or python2
# integration depending on your vim setup.
-#
+#
# The first mapping enables clang-format for NORMAL and VISUAL mode, the second
# mapping adds support for INSERT mode. Change "C-I" to another binding if you
# need clang-format on a different key (C-I stands for Ctrl+i).
@@ -134,7 +134,7 @@
)
else:
header, content = stdout.split(b'\n', 1)
- header = json.loads(header)
+ header = json.loads(header.decode('utf-8'))
# Strip off the trailing newline (added above).
# This maintains trailing empty lines present in the buffer if
# the -lines specification requests them to remain unchanged.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133236.457709.patch
Type: text/x-patch
Size: 1091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220902/c5d59fc2/attachment.bin>
More information about the cfe-commits
mailing list