[Mesa-dev] [PATCH v02 2/3] genxml: Fix python crash when no dwords are found.

Dylan Baker dylan at pnwbakers.com
Tue Apr 18 23:06:11 UTC 2017


Thanks for making the changes I requested.

Reviewed-by: Dylan Baker <dylan at pnwbakers.com>

Quoting Rafael Antognolli (2017-04-18 14:50:20)
> 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 <rafael.antognolli at intel.com>
> ---
>  src/intel/genxml/gen_pack_header.py | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/src/intel/genxml/gen_pack_header.py b/src/intel/genxml/gen_pack_header.py
> index 29bec40..d0b1336 100644
> --- a/src/intel/genxml/gen_pack_header.py
> +++ b/src/intel/genxml/gen_pack_header.py
> @@ -346,7 +346,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, "")
>  
> @@ -356,9 +356,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:
> @@ -575,10 +580,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")
>  
> -- 
> git-series 0.9.1
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170418/af6e130d/attachment.sig>


More information about the mesa-dev mailing list