[Mesa-dev] [PATCH] r600/egd_tables.py: make the script python 2+3 compatible

Gustaw Smolarczyk wielkiegie at gmail.com
Fri Mar 2 12:39:40 UTC 2018


2018-03-02 12:59 GMT+01:00 Stefan Dirsch <sndirsch at suse.de>:

> On Fri, Mar 02, 2018 at 11:47:57AM +0000, Eric Engestrom wrote:
> > On Friday, 2018-03-02 12:25:11 +0100, Stefan Dirsch wrote:
> > > On Fri, Mar 02, 2018 at 11:03:53AM +0000, Eric Engestrom wrote:
> > > > On Friday, 2018-03-02 11:41:00 +0100, Stefan Dirsch wrote:
> > > > > Patch by "Tomas Chvatal" <tchvatal at suse.com> with modifications
> > > > > by "Michal Srb" <msrb at suse.com> to not break python 2.
> > > > >
> > > > > https://bugzilla.suse.com/show_bug.cgi?id=1082303
> > > > >
> > > > > v2:
> > > > > - no longer try to encode a unicode
> > > > > - make use of 'from __future__ import print_function', so semantics
> > > > >   of print statements in python2 are closer to print functions in
> python3
> > > > >
> > > > > https://lists.freedesktop.org/archives/mesa-dev/2018-
> February/187056.html
> > > > >
> > > > > Signed-off-by: Stefan Dirsch <sndirsch at suse.de>
> > > > > Reviewed-by: Tomas Chvatal <tchvatal at suse.com>
> > > > > ---
> > > > >  src/gallium/drivers/r600/egd_tables.py | 53
> +++++++++++++++++-----------------
> > > > >  1 file changed, 27 insertions(+), 26 deletions(-)
> > > > >
> > > > > diff --git a/src/gallium/drivers/r600/egd_tables.py
> b/src/gallium/drivers/r600/egd_tables.py
> > > > > index d7b78c7fb1..4796456330 100644
> > > > > --- a/src/gallium/drivers/r600/egd_tables.py
> > > > > +++ b/src/gallium/drivers/r600/egd_tables.py
> > > > > @@ -1,3 +1,4 @@
> > > > > +from __future__ import print_function
> > > > >
> > > > >  CopyRight = '''
> > > > >  /*
> > > > > @@ -60,7 +61,7 @@ class StringTable:
> > > > >          """
> > > > >          fragments = [
> > > > >              '"%s\\0" /* %s */' % (
> > > > > -                te[0].encode('string_escape'),
> > > > > +                te[0],
>

Hi,

I am not an expert in Python 3, but I have found the following answer
experimentally.

I think the original version is semi-correct, but the encode() method
returns a bytes object which we need to convert to unicode. I think the
following would be fine:

te[0].encode('unicode_escape').decode('utf-8')

Regards,
Gustaw Smolarczyk


> > > >
> > > > I think you still need to escape the string here.
> > >
> > > I don't know how to address this. :-( At least the output of
> > >
> > >   python2 egd_tables.py evergreend.h
> > >   python3 egd_tables.py evergreend.h
> > >
> > > is now identical. Surely this may change with changes in content of
> > > evergreend.h. :-( Ok. I've tried my best.
> >
> > I think you should already land the print() changes, leaving this line
> > as is for now. Won't be valid python3 yet, but this will be the last
> > thing to fix, which someone else might pick up :)
>
> Leaving the line as is won't run with python3.
>
> > With the string escape hunk left out, this patch is
> > Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com>
>
> Thanks, but I'm not really interested in submitting a patch, which doesn't
> fix
> the build for python3.
>
> Stefan
>
> Public Key available
> ------------------------------------------------------
> Stefan Dirsch (Res. & Dev.)   SUSE LINUX GmbH
> Tel: 0911-740 53 0            Maxfeldstraße 5
> FAX: 0911-740 53 479          D-90409 Nürnberg
> http://www.suse.de            Germany
> ---------------------------------------------------------------
> SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham
> Norton, HRB 21284 (AG Nürnberg)
> ---------------------------------------------------------------
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180302/b9bcbb44/attachment.html>


More information about the mesa-dev mailing list