mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
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. Reported-by: George Dunlap <george.dunlap@eu.citrix.com> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com> Acked-by: Wei Liu <wei.liu2@citrix.com>
71 lines
1.7 KiB
Python
71 lines
1.7 KiB
Python
#!/usr/bin/python
|
|
|
|
import sys;
|
|
from structs import structs, compat_arches;
|
|
|
|
# command line arguments
|
|
outfile = sys.argv[1];
|
|
archs = sys.argv[2:];
|
|
|
|
f = open(outfile, "w");
|
|
f.write('''
|
|
/*
|
|
* sanity checks for generated foreign headers:
|
|
* - verify struct sizes
|
|
*
|
|
* generated by %s -- DO NOT EDIT
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stddef.h>
|
|
#include <inttypes.h>
|
|
''');
|
|
|
|
for a in archs:
|
|
f.write('#include "%s.h"\n' % a);
|
|
|
|
f.write('int main(int argc, char *argv[])\n{\n');
|
|
|
|
f.write('\tprintf("\\n");');
|
|
f.write('printf("%-25s |", "structs");\n');
|
|
for a in archs:
|
|
f.write('\tprintf("%%8s", "%s");\n' % a);
|
|
f.write('\tprintf("\\n");');
|
|
|
|
f.write('\tprintf("\\n");');
|
|
for struct in structs:
|
|
f.write('\tprintf("%%-25s |", "%s");\n' % struct);
|
|
for a in archs:
|
|
s = struct + "_" + a;
|
|
if a in compat_arches:
|
|
compat = compat_arches[a]
|
|
c = struct + "_" + compat;
|
|
else:
|
|
compat = None
|
|
f.write('#ifdef %s_has_no_%s\n' % (a, struct));
|
|
f.write('\tprintf("%8s",\n');
|
|
if compat:
|
|
f.write('# ifndef %s_has_no_%s\n' % (compat, struct));
|
|
f.write('\t\t"!"\n');
|
|
f.write('# else\n')
|
|
f.write('\t\t"-"\n');
|
|
f.write('# endif\n')
|
|
else:
|
|
f.write('\t\t"-"\n');
|
|
f.write('\t);\n')
|
|
f.write("#else\n");
|
|
f.write('\tprintf("%%8zd", sizeof(struct %s));\n' % s);
|
|
if compat:
|
|
f.write('\tif (sizeof(struct %s) != sizeof(struct %s))\n' % (s, c))
|
|
f.write('\t\tprintf("!");\n')
|
|
f.write("#endif\n");
|
|
|
|
f.write('\tprintf("\\n");\n\n');
|
|
|
|
f.write('\tprintf("\\n");\n');
|
|
f.write('\texit(0);\n');
|
|
f.write('}\n');
|
|
|
|
f.close();
|
|
|