diff options
author | Rafael Antognolli <[email protected]> | 2017-03-31 09:57:22 -0700 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2017-04-24 15:14:08 -0700 |
commit | 4ace73b1f6e8c8d96663a0d8f0f1d61f934e9cb2 (patch) | |
tree | 7d8d962d5e8fa40d136a86233acbc083ecac0aba /src/intel | |
parent | 19720405d5c455e2920e549606f8a45437a3a816 (diff) |
genxml: Fix python crash when no dwords are found.
If the 'dwords' dict is empty, max(dwords.keys()) throws an exception.
This case could happen when we have an instruction that is only an array
of other structs, with variable length.
v2:
- Add another clause for empty dwords and make it work with python 3
(Dylan)
- Set the length to 0 if dwords is empty, and do not declare dw
Signed-off-by: Rafael Antognolli <[email protected]>
Reviewed-by: Dylan Baker <[email protected]>
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/intel')
-rw-r--r-- | src/intel/genxml/gen_pack_header.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/intel/genxml/gen_pack_header.py b/src/intel/genxml/gen_pack_header.py index 81c64cbbc75..1b1949ff8a5 100644 --- a/src/intel/genxml/gen_pack_header.py +++ b/src/intel/genxml/gen_pack_header.py @@ -347,7 +347,7 @@ class Group(object): dwords[index + 1] = dwords[index] index = index + 1 - def emit_pack_function(self): + def collect_dwords_and_length(self): dwords = {} self.collect_dwords(dwords, 0, "") @@ -357,9 +357,14 @@ class Group(object): # index we've seen plus one. if self.size > 0: length = self.size // 32 - else: + elif dwords: length = max(dwords.keys()) + 1 + else: + length = 0 + + return (dwords, length) + def emit_pack_function(self, dwords, length): for index in range(length): # Handle MBZ dwords if not index in dwords: @@ -576,10 +581,12 @@ class Parser(object): print("static inline void\n%s_pack(__gen_user_data *data, void * restrict dst,\n%sconst struct %s * restrict values)\n{" % (name, ' ' * (len(name) + 6), name)) - # Cast dst to make header C++ friendly - print(" uint32_t * restrict dw = (uint32_t * restrict) dst;") + (dwords, length) = group.collect_dwords_and_length() + if length: + # Cast dst to make header C++ friendly + print(" uint32_t * restrict dw = (uint32_t * restrict) dst;") - group.emit_pack_function() + group.emit_pack_function(dwords, length) print("}\n") |