Skip to content
  • Philippe Mathieu-Daudé's avatar
    4cacecaa
    decodetree: Open files with encoding='utf-8' · 4cacecaa
    Philippe Mathieu-Daudé authored
    
    
    When decodetree.py was added in commit 568ae7ef, QEMU was
    using Python 2 which happily reads UTF-8 files in text mode.
    Python 3 requires either UTF-8 locale or an explicit encoding
    passed to open(). Now that Python 3 is required, explicit
    UTF-8 encoding for decodetree source files.
    
    To avoid further problems with the user locale, also explicit
    UTF-8 encoding for the generated C files.
    
    Explicit both input/output are plain text by using the 't' mode.
    
    This fixes:
    
      $ /usr/bin/python3 scripts/decodetree.py test.decode
      Traceback (most recent call last):
        File "scripts/decodetree.py", line 1397, in <module>
          main()
        File "scripts/decodetree.py", line 1308, in main
          parse_file(f, toppat)
        File "scripts/decodetree.py", line 994, in parse_file
          for line in f:
        File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
          return codecs.ascii_decode(input, self.errors)[0]
      UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 80:
      ordinal not in range(128)
    
    Reported-by: default avatarPeter Maydell <peter.maydell@linaro.org>
    Suggested-by: default avatarYonggang Luo <luoyonggang@gmail.com>
    Reviewed-by: default avatarEduardo Habkost <ehabkost@redhat.com>
    Signed-off-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
    Message-Id: <20210110000240.761122-1-f4bug@amsat.org>
    Signed-off-by: default avatarRichard Henderson <richard.henderson@linaro.org>
    4cacecaa
    decodetree: Open files with encoding='utf-8'
    Philippe Mathieu-Daudé authored
    
    
    When decodetree.py was added in commit 568ae7ef, QEMU was
    using Python 2 which happily reads UTF-8 files in text mode.
    Python 3 requires either UTF-8 locale or an explicit encoding
    passed to open(). Now that Python 3 is required, explicit
    UTF-8 encoding for decodetree source files.
    
    To avoid further problems with the user locale, also explicit
    UTF-8 encoding for the generated C files.
    
    Explicit both input/output are plain text by using the 't' mode.
    
    This fixes:
    
      $ /usr/bin/python3 scripts/decodetree.py test.decode
      Traceback (most recent call last):
        File "scripts/decodetree.py", line 1397, in <module>
          main()
        File "scripts/decodetree.py", line 1308, in main
          parse_file(f, toppat)
        File "scripts/decodetree.py", line 994, in parse_file
          for line in f:
        File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
          return codecs.ascii_decode(input, self.errors)[0]
      UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 80:
      ordinal not in range(128)
    
    Reported-by: default avatarPeter Maydell <peter.maydell@linaro.org>
    Suggested-by: default avatarYonggang Luo <luoyonggang@gmail.com>
    Reviewed-by: default avatarEduardo Habkost <ehabkost@redhat.com>
    Signed-off-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
    Message-Id: <20210110000240.761122-1-f4bug@amsat.org>
    Signed-off-by: default avatarRichard Henderson <richard.henderson@linaro.org>
Loading