Author: Amy Wang Date: 2022-09-05T15:40:47+01:00 New Revision: 8f4e6cfe73d803697470e817845d9b94c4530ca3
URL: https://github.com/llvm/llvm-project/commit/8f4e6cfe73d803697470e817845d9b94c4530ca3 DIFF: https://github.com/llvm/llvm-project/commit/8f4e6cfe73d803697470e817845d9b94c4530ca3.diff LOG: [clang-format] Use utf-8 for JSON object load >From Python 3.6 and above, it should be able to automatically select a decoding for json.loads. However, with a vim encoding that defaults to utf-8, clang-format.py runs into the following error TypeError: the JSON object must be str, not 'bytes' This patch explicitly specifies utf-8 decoding for the header. Reviewed by: ldrumm, sammcall Differential Revision: https://reviews.llvm.org/D133236 Added: Modified: clang/tools/clang-format/clang-format.py Removed: ################################################################################ diff --git a/clang/tools/clang-format/clang-format.py b/clang/tools/clang-format/clang-format.py index 76fedb6481474..5bc108bfc713b 100644 --- a/clang/tools/clang-format/clang-format.py +++ b/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 diff erent key (C-I stands for Ctrl+i). @@ -134,7 +134,7 @@ def main(): ) 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. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits