python: Specify the template output encoding
authorMathieu Bridon <bochecha@daitauha.fr>
Thu, 5 Jul 2018 13:17:46 +0000 (15:17 +0200)
committerDylan Baker <dylan@pnwbakers.com>
Tue, 7 Aug 2018 20:28:35 +0000 (13:28 -0700)
We're trying to write a unicode string (i.e decoded) to a file opened
in binary (i.e encoded) mode.

In Python 2 this works, because of the automatic conversion between
byte and unicode strings.

In Python 3 this fails though, as no automatic conversion is attempted.

This change makes the scripts compatible with both versions of Python.

Signed-off-by: Mathieu Bridon <bochecha@daitauha.fr>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
src/compiler/nir/nir_intrinsics_c.py
src/compiler/nir/nir_intrinsics_h.py

index 98af67c38aefe66b8bd6cfe4c342e091275b3475..ac45b94d4968db2bdd1538fedb8676a93c75bb19 100644 (file)
@@ -64,7 +64,7 @@ def main():
 
     path = os.path.join(args.outdir, 'nir_intrinsics.c')
     with open(path, 'wb') as f:
 
     path = os.path.join(args.outdir, 'nir_intrinsics.c')
     with open(path, 'wb') as f:
-        f.write(Template(template).render(INTR_OPCODES=INTR_OPCODES))
+        f.write(Template(template, output_encoding='utf-8').render(INTR_OPCODES=INTR_OPCODES))
 
 if __name__ == '__main__':
     main()
 
 if __name__ == '__main__':
     main()
index 8a4f0d501e6e7c9c9a5d2589418ddc64b2619460..8abc6a8626d30377f8d20a8fc2815ed5569c117a 100644 (file)
@@ -53,7 +53,7 @@ def main():
 
     path = os.path.join(args.outdir, 'nir_intrinsics.h')
     with open(path, 'wb') as f:
 
     path = os.path.join(args.outdir, 'nir_intrinsics.h')
     with open(path, 'wb') as f:
-        f.write(Template(template).render(INTR_OPCODES=INTR_OPCODES))
+        f.write(Template(template, output_encoding='utf-8').render(INTR_OPCODES=INTR_OPCODES))
 
 if __name__ == '__main__':
     main()
 
 if __name__ == '__main__':
     main()