This is somewhat insufficient, it might run okay with python3, but the behavior
will be different between the two. Please add `from __future__ import
print_function`, so that the behavior will be the same, not just the syntax.

Also, the StringTable, InteTable, Field, and Reg classes is also an old-style
class in python2, but a new-style in python3, they should inherit from object to
be new-style in python2. There are some real problems with old-style classes,
which is why python3 dropped them.

Everything up to this point is changes I'm requesting, below I'm going to make a
case for not hybridzing code, because hybridizing is hard to do right:

Python2 is opening the files being parsed in bytes mode, while python3 is
opening them in text (unicode) mode, things might be okay, or they might break
in subtle ways. Unfortunately at the moment that's a hard thing to fix since
mesa supports python 2.6 right now and writing 2.6/3.x compatible code correctly
is insanely hard without a helper library like six. If we're going to add python
3 support, we need to bump our python 2 version to 2.7.

This may not be a popular opinion, but since we have meson (which requires
python 3) as a build system and presumably we're moving toward a future where we
drop scons and autotools, and python 2 is approaching End of Life, I'd be 
happier
to see generators that are not run by scons (which is python2 only) be converted
to pure python 3, and only those that need to be run by scons be hybridized. I
have written a lot of code that is hybrid python 2/3 and it's not a
straightforward thing to do, there are a lot of subtle differences that can bite
you in odd ways, it's much easier to write code that is correct python 3.

Dylan

Quoting Michal Srb (2018-01-11 07:14:07)
> diff --git a/src/gallium/drivers/r600/egd_tables.py 
> b/src/gallium/drivers/r600/egd_tables.py
> index d7b78c7fb1..7bda44ce83 100644
> --- a/src/gallium/drivers/r600/egd_tables.py
> +++ b/src/gallium/drivers/r600/egd_tables.py
> @@ -1,4 +1,4 @@
> -
> +#!/usr/bin/python3
>  CopyRight = '''
>  /*
>   * Copyright 2015 Advanced Micro Devices, Inc.
> @@ -60,7 +60,7 @@ class StringTable:
>          """
>          fragments = [
>              '"%s\\0" /* %s */' % (
> -                te[0].encode('string_escape'),
> +                te[0].encode('unicode_escape'),
>                  ', '.join(str(idx) for idx in te[2])
>              )
>              for te in self.table
> @@ -217,10 +217,10 @@ def write_tables(regs, packets):
>      strings = StringTable()
>      strings_offsets = IntTable("int")
>  
> -    print '/* This file is autogenerated by egd_tables.py from evergreend.h. 
> Do not edit directly. */'
> -    print
> -    print CopyRight.strip()
> -    print '''
> +    print('/* This file is autogenerated by egd_tables.py from evergreend.h. 
> Do not edit directly. */')
> +    print('')
> +    print(CopyRight.strip())
> +    print('''
>  #ifndef EG_TABLES_H
>  #define EG_TABLES_H
>  
> @@ -242,20 +242,20 @@ struct eg_packet3 {
>          unsigned name_offset;
>          unsigned op;
>  };
> -'''
> +''')
>  
> -    print 'static const struct eg_packet3 packet3_table[] = {'
> +    print('static const struct eg_packet3 packet3_table[] = {')
>      for pkt in packets:
> -        print '\t{%s, %s},' % (strings.add(pkt[5:]), pkt)
> -    print '};'
> -    print
> +        print('\t{%s, %s},' % (strings.add(pkt[5:]), pkt))
> +    print('};')
> +    print('')
>  
> -    print 'static const struct eg_field egd_fields_table[] = {'
> +    print('static const struct eg_field egd_fields_table[] = {')
>  
>      fields_idx = 0
>      for reg in regs:
>          if len(reg.fields) and reg.own_fields:
> -            print '\t/* %s */' % (fields_idx)
> +            print('\t/* %s */' % (fields_idx))
>  
>              reg.fields_idx = fields_idx
>  
> @@ -266,34 +266,34 @@ struct eg_packet3 {
>                          while value[1] >= len(values_offsets):
>                              values_offsets.append(-1)
>                          values_offsets[value[1]] = 
> strings.add(strip_prefix(value[0]))
> -                    print '\t{%s, %s(~0u), %s, %s},' % (
> +                    print('\t{%s, %s(~0u), %s, %s},' % (
>                          strings.add(field.name), field.s_name,
> -                        len(values_offsets), 
> strings_offsets.add(values_offsets))
> +                        len(values_offsets), 
> strings_offsets.add(values_offsets)))
>                  else:
> -                    print '\t{%s, %s(~0u)},' % (strings.add(field.name), 
> field.s_name)
> +                    print('\t{%s, %s(~0u)},' % (strings.add(field.name), 
> field.s_name))
>                  fields_idx += 1
>  
> -    print '};'
> -    print
> +    print('};')
> +    print('')
>  
> -    print 'static const struct eg_reg egd_reg_table[] = {'
> +    print('static const struct eg_reg egd_reg_table[] = {')
>      for reg in regs:
>          if len(reg.fields):
> -            print '\t{%s, %s, %s, %s},' % (strings.add(reg.name), reg.r_name,
> -                len(reg.fields), reg.fields_idx if reg.own_fields else 
> reg.fields_owner.fields_idx)
> +            print('\t{%s, %s, %s, %s},' % (strings.add(reg.name), reg.r_name,
> +                len(reg.fields), reg.fields_idx if reg.own_fields else 
> reg.fields_owner.fields_idx))
>          else:
> -            print '\t{%s, %s},' % (strings.add(reg.name), reg.r_name)
> -    print '};'
> -    print
> +            print('\t{%s, %s},' % (strings.add(reg.name), reg.r_name))
> +    print('};')
> +    print('')
>  
>      strings.emit(sys.stdout, "egd_strings")
>  
> -    print
> +    print('')
>  
>      strings_offsets.emit(sys.stdout, "egd_strings_offsets")
>  
> -    print
> -    print '#endif'
> +    print('')
> +    print('#endif')
>  
>  
>  def main():
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Attachment: signature.asc
Description: signature

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to