python: Better sort dictionary keys/values

In Python 2, dict.keys() and dict.values() both return a list, which can
be sorted in two ways:

* l.sort() modifies the list in-place;
* sorted(l) returns a new, sorted list;

In Python 3, dict.keys() and dict.values() do not return lists any more,
but iterators. Iterators do not have a .sort() method.

This commit moves the build scripts to using sorted() on dict keys and
values, which makes them compatible with both Python 2 and Python 3.

Signed-off-by: Mathieu Bridon <bochecha@daitauha.fr>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
Mathieu Bridon
2018-07-06 12:17:50 +02:00
committed by Dylan Baker
parent 5530cb1296
commit 01da2feb0e
4 changed files with 8 additions and 16 deletions

View File

@@ -391,8 +391,7 @@ static const struct proc_pair
const char *name; const char *name;
_glapi_proc proc; _glapi_proc proc;
} proc_pairs[%d] = {""" % len(procs)) } proc_pairs[%d] = {""" % len(procs))
names = procs.keys() names = sorted(procs.keys())
names.sort()
for i in xrange(len(names)): for i in xrange(len(names)):
comma = ',' if i < len(names) - 1 else '' comma = ',' if i < len(names) - 1 else ''
print(' { "%s", (_glapi_proc) gl%s }%s' % (names[i], procs[names[i]], comma)) print(' { "%s", (_glapi_proc) gl%s }%s' % (names[i], procs[names[i]], comma))

View File

@@ -208,8 +208,7 @@ class glx_enum_function(object):
for enum_obj in self.enums[e]: for enum_obj in self.enums[e]:
list[ enum_obj.priority() ] = enum_obj.name list[ enum_obj.priority() ] = enum_obj.name
keys = list.keys() keys = sorted(list.keys())
keys.sort()
for k in keys: for k in keys:
j = list[k] j = list[k]
if first: if first:
@@ -275,8 +274,7 @@ class glx_server_enum_function(glx_enum_function):
o = f.offset_of( param_name ) o = f.offset_of( param_name )
foo[o] = param_name foo[o] = param_name
keys = foo.keys() keys = sorted(foo.keys())
keys.sort()
for o in keys: for o in keys:
p = f.parameters_by_name[ foo[o] ] p = f.parameters_by_name[ foo[o] ]

View File

@@ -988,12 +988,10 @@ class gl_api(object):
functions = [] functions = []
for func_cat_type in range(0,4): for func_cat_type in range(0,4):
keys = lists[func_cat_type].keys() keys = sorted(lists[func_cat_type].keys())
keys.sort()
for key in keys: for key in keys:
names = lists[func_cat_type][key].keys() names = sorted(lists[func_cat_type][key].keys())
names.sort()
for name in names: for name in names:
functions.append(lists[func_cat_type][key][name]) functions.append(lists[func_cat_type][key][name])
@@ -1027,8 +1025,7 @@ class gl_api(object):
def enumIterateByName(self): def enumIterateByName(self):
keys = self.enums_by_name.keys() keys = sorted(self.enums_by_name.keys())
keys.sort()
list = [] list = []
for enum in keys: for enum in keys:
@@ -1047,8 +1044,7 @@ class gl_api(object):
list = [] list = []
for cat_type in range(0,4): for cat_type in range(0,4):
keys = self.categories[cat_type].keys() keys = sorted(self.categories[cat_type].keys())
keys.sort()
for key in keys: for key in keys:
list.append(self.categories[cat_type][key]) list.append(self.categories[cat_type][key])

View File

@@ -144,8 +144,7 @@ typedef struct {
print('') print('')
print('/* OpenGL ES specific prototypes */') print('/* OpenGL ES specific prototypes */')
print('') print('')
keys = categories.keys() keys = sorted(categories.keys())
keys.sort()
for key in keys: for key in keys:
print('/* category %s */' % key) print('/* category %s */' % key)
print("\n".join(categories[key])) print("\n".join(categories[key]))