This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Use utf-8 for JSON object load
ClosedPublic

Authored by kaitingwang on Sep 2 2022, 2:47 PM.

Details

Summary

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 header.

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'

Diff Detail

Event Timeline

kaitingwang created this revision.Sep 2 2022, 2:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 2 2022, 2:47 PM
kaitingwang requested review of this revision.Sep 2 2022, 2:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 2 2022, 2:47 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sammccall accepted this revision.Sep 5 2022, 2:01 AM

Thanks!

This revision is now accepted and ready to land.Sep 5 2022, 2:01 AM
curdeius retitled this revision from [Clang][Tools] Use utf-8 for JSON object load to [clang-format] Use utf-8 for JSON object load.Sep 5 2022, 3:02 AM
ldrumm accepted this revision.Sep 5 2022, 3:11 AM

LGTM

ldrumm added a comment.Sep 5 2022, 3:20 AM

Do you have commit access?

Do you have commit access?

@ldrumm I don't have commit access. Would you commit for me? Really appreciate it!

kaitingwang edited the summary of this revision. (Show Details)Sep 5 2022, 6:27 AM
This revision was landed with ongoing or failed builds.Sep 5 2022, 7:41 AM
This revision was automatically updated to reflect the committed changes.