Skip to contentSkip to conversation

tools/xen-foreign: Update python scripts to be Py3 compatible

PATCH In review Andrew Cooper 2 participants 2 messages Mar 11, 2019 – Mar 12, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/xen-foreign: Update python scripts to be Py3 compatible

The issues are:
* dict.has_key() was completely removed in Py3
* dict.keys() is an iterable rather than list in Py3, so .sort() doesn't work.
* list.sort(cmp=) was deprecated in Py2.4 and removed in Py3.

The has_key() issue is trivially fixed by switching to using the in keyword. The sorting issue could be trivially fixed, but take the opportunity to improve the code.

The reason for the sorting is to ensure that "unsigned long" gets replaced before "long", and the only reason sorting is necessary is because inttypes[arch] is needlessly a dictionary. Update inttypes[arch] to be a list of tuples rather than a dictionary, and process them in list order.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

v2:
* Fix the logic not to need sorting, rather than leaving that WTF in place.

---
 tools/include/xen-foreign/mkchecker.py |  2 +-
 tools/include/xen-foreign/mkheader.py  | 58 ++++++++++++++++------------------
 2 files changed, 29 insertions(+), 31 deletions(-)
tools/include/xen-foreign/mkchecker.py +1 -1
index fdad869..199b0ee 100644
@@ -37,7 +37,7 @@
     f.write('\tprintf("%%-25s |", "%s");\n' % struct);
     for a in archs:
         s = struct + "_" + a;
-        if compat_arches.has_key(a):
+        if a in compat_arches:
             compat = compat_arches[a]
             c = struct + "_" + compat;
         else:
tools/include/xen-foreign/mkheader.py +28 -30

88 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Andrew Cooper

The issues are:
* dict.has_key() was completely removed in Py3
* dict.keys() is an iterable rather than list in Py3, so .sort() doesn't work.
* list.sort(cmp=) was deprecated in Py2.4 and removed in Py3.

The has_key() issue is trivially fixed by switching to using the in keyword. The sorting issue could be trivially fixed, but take the opportunity to improve the code.

Quoted 7 lines

The reason for the sorting is to ensure that "unsigned long" gets replaced before "long", and the only reason sorting is necessary is because inttypes[arch] is needlessly a dictionary. Update inttypes[arch] to be a list of tuples rather than a dictionary, and process them in list order.

Much better.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel