[clang] 1bd4dc4 - [hmaptool] Port to python3
Nathan Lanza via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 19 16:52:12 PST 2021
Author: Nathan Lanza
Date: 2021-11-19T19:25:31-05:00
New Revision: 1bd4dc4f2854edf3035732416ec7e4adbddaf982
URL: https://github.com/llvm/llvm-project/commit/1bd4dc4f2854edf3035732416ec7e4adbddaf982
DIFF: https://github.com/llvm/llvm-project/commit/1bd4dc4f2854edf3035732416ec7e4adbddaf982.diff
LOG: [hmaptool] Port to python3
This is just a few trivial changes -- change the interpreter and fix a
few byte-vs-string issues.
Differential Revision: https://reviews.llvm.org/D107944
Added:
Modified:
clang/utils/hmaptool/hmaptool
Removed:
################################################################################
diff --git a/clang/utils/hmaptool/hmaptool b/clang/utils/hmaptool/hmaptool
index e647cde6bc46a..7949002020489 100755
--- a/clang/utils/hmaptool/hmaptool
+++ b/clang/utils/hmaptool/hmaptool
@@ -1,6 +1,7 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
from __future__ import absolute_import, division, print_function
+from ctypes import ArgumentError
import json
import optparse
import os
@@ -9,8 +10,8 @@ import sys
###
-k_header_magic_LE = 'pamh'
-k_header_magic_BE = 'hmap'
+k_header_magic_LE = b'pamh'
+k_header_magic_BE = b'hmap'
def hmap_hash(str):
"""hash(str) -> int
@@ -43,7 +44,7 @@ class HeaderMap(object):
path,))
(version, reserved, strtable_offset, num_entries,
- num_buckets, max_value_len) = struct.unpack(header_fmt, data)
+ num_buckets) = struct.unpack(header_fmt, data)
if version != 1:
raise SystemExit("error: %s: unknown headermap version: %r" % (
@@ -83,7 +84,7 @@ class HeaderMap(object):
if len(strtable) != strtable_size:
raise SystemExit("error: %s: unable to read complete string table"%(
path,))
- if strtable[-1] != '\0':
+ if strtable[-1] != 0:
raise SystemExit("error: %s: invalid string table in headermap" % (
path,))
@@ -97,8 +98,8 @@ class HeaderMap(object):
def get_string(self, idx):
if idx >= len(self.strtable):
raise SystemExit("error: %s: invalid string index" % (
- path,))
- end_idx = self.strtable.index('\0', idx)
+ idx,))
+ end_idx = self.strtable.index(0, idx)
return self.strtable[idx:end_idx]
@property
@@ -220,7 +221,7 @@ def action_write(name, args):
# Write out the headermap.
with open(output_path, 'wb') as f:
- f.write(magic.encode())
+ f.write(magic)
f.write(struct.pack(header_fmt, *header))
for bucket in table:
f.write(struct.pack(bucket_fmt, *bucket))
More information about the cfe-commits
mailing list