[PATCH] D107944: [hmaptool] Port to python3

2021-11-19 Thread Nathan Lanza via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1bd4dc4f2854: [hmaptool] Port to python3 (authored by lanza).

Changed prior to commit:
  https://reviews.llvm.org/D107944?vs=388568=388668#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107944/new/

https://reviews.llvm.org/D107944

Files:
  clang/utils/hmaptool/hmaptool


Index: clang/utils/hmaptool/hmaptool
===
--- clang/utils/hmaptool/hmaptool
+++ 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 @@
 
 ###
 
-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 @@
 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 @@
 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 @@
 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 @@
 
 # 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))


Index: clang/utils/hmaptool/hmaptool
===
--- clang/utils/hmaptool/hmaptool
+++ 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 @@
 
 ###
 
-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 @@
 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 @@
 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 @@
 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 @@
 
 # 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))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107944: [hmaptool] Port to python3

2021-11-19 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107944/new/

https://reviews.llvm.org/D107944

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107944: [hmaptool] Port to python3

2021-11-19 Thread Nathan Lanza via Phabricator via cfe-commits
lanza updated this revision to Diff 388568.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107944/new/

https://reviews.llvm.org/D107944

Files:
  clang/utils/hmaptool/hmaptool


Index: clang/utils/hmaptool/hmaptool
===
--- clang/utils/hmaptool/hmaptool
+++ 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 @@

 ###

-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 @@
 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 @@
 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 @@
 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 @@

 # 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))


Index: clang/utils/hmaptool/hmaptool
===
--- clang/utils/hmaptool/hmaptool
+++ 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 @@

 ###

-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 @@
 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 @@
 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 @@
 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 @@

 # 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))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107944: [hmaptool] Port to python3

2021-11-19 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added inline comments.



Comment at: clang/utils/hmaptool/hmaptool:223
 with open(output_path, 'wb') as f:
 f.write(magic.encode())
 f.write(struct.pack(header_fmt, *header))

`magic` is a bytes object that does not have `encode()` method 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107944/new/

https://reviews.llvm.org/D107944

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107944: [hmaptool] Port to python3

2021-10-12 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Overall looks great but there are some test failures, looks like you also need 
to update line 223?

  --
  Traceback (most recent call last):
File "/var/lib/buildkite-agent/builds/llvm-project/build/bin/hmaptool", 
line 296, in 
  main()
File "/var/lib/buildkite-agent/builds/llvm-project/build/bin/hmaptool", 
line 293, in main
  commands[cmd](cmd, sys.argv[2:])
File "/var/lib/buildkite-agent/builds/llvm-project/build/bin/hmaptool", 
line 223, in action_write
  f.write(magic.encode())
  AttributeError: 'bytes' object has no attribute 'encode'
  --


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107944/new/

https://reviews.llvm.org/D107944

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107944: [hmaptool] Port to python3

2021-08-11 Thread Nathan Lanza via Phabricator via cfe-commits
lanza created this revision.
lanza requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is just a few trivial changes -- change the interpreter and fix a
few byte-vs-string issues.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107944

Files:
  clang/utils/hmaptool/hmaptool


Index: clang/utils/hmaptool/hmaptool
===
--- clang/utils/hmaptool/hmaptool
+++ clang/utils/hmaptool/hmaptool
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 from __future__ import absolute_import, division, print_function
 
 import json
@@ -9,8 +9,8 @@
 
 ###
 
-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
@@ -83,7 +83,7 @@
 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,))
 
@@ -98,7 +98,7 @@
 if idx >= len(self.strtable):
 raise SystemExit("error: %s: invalid string index" % (
 path,))
-end_idx = self.strtable.index('\0', idx)
+end_idx = self.strtable.index(0, idx)
 return self.strtable[idx:end_idx]
 
 @property


Index: clang/utils/hmaptool/hmaptool
===
--- clang/utils/hmaptool/hmaptool
+++ clang/utils/hmaptool/hmaptool
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 from __future__ import absolute_import, division, print_function
 
 import json
@@ -9,8 +9,8 @@
 
 ###
 
-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
@@ -83,7 +83,7 @@
 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,))
 
@@ -98,7 +98,7 @@
 if idx >= len(self.strtable):
 raise SystemExit("error: %s: invalid string index" % (
 path,))
-end_idx = self.strtable.index('\0', idx)
+end_idx = self.strtable.index(0, idx)
 return self.strtable[idx:end_idx]
 
 @property
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits