Skip to contentSkip to conversation

x86/gen-cpuid: Fix Py2/3 compatibility

PATCH In review Andrew Cooper 2 participants 2 messages Feb 25, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/gen-cpuid: Fix Py2/3 compatibility

There is a fencepost error on the sys.version_info check which will break on Python 3.0. Reverse the logic to make py2 compatible with py3 (rather than py3 compatible with py2) which will be more natural to follow as py2 usage reduces.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/tools/gen-cpuid.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
xen/tools/gen-cpuid.py +4 -5
index 362cdb5306..71ea78f4eb 100755
@@ -3,9 +3,8 @@
 
 import sys, os, re
 
-if (sys.version_info > (3, 0)):
-    def xrange(x):
-        return range(x)
+if sys.version_info < (3, 0):
+    range = xrange
 
 class Fail(Exception):
     pass
@@ -330,10 +329,10 @@ def crunch_numbers(state):
         state.deep_deps[k] = featureset_to_uint32s(v, nr_entries)
 
     # Calculate the bitfield name declarations
-    for word in xrange(nr_entries):
+    for word in range(nr_entries):
 
         names = []
-        for bit in xrange(32):
+        for bit in range(32):
 
             name = state.names.get(word * 32 + bit, "")
 
Signature · 7 lines
2.11.0


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

There is a fencepost error on the sys.version_info check which will break on Python 3.0. Reverse the logic to make py2 compatible with py3 (rather than py3 compatible with py2) which will be more natural to follow as py2 usage reduces.

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