[PATCH] minikconf: explicitly set encoding to UTF-8

Stefan Hajnoczi posted 1 patch 6 months, 1 week ago
Test docker-mingw@fedora passed
Test checkpatch passed
Test asan passed
Test docker-quick@centos7 passed
Test FreeBSD passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20200521153616.307100-1-stefanha@redhat.com
scripts/minikconf.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

[PATCH] minikconf: explicitly set encoding to UTF-8

Posted by Stefan Hajnoczi 6 months, 1 week ago
QEMU currently only has ASCII Kconfig files but Linux actually uses
UTF-8. Explicitly specify the encoding and that we're doing text file
I/O.

It's unclear whether or not QEMU will ever need Unicode in its Kconfig
files. If we start using the help text then it will become an issue
sooner or later. Make this change now for consistency with Linux
Kconfig.

Reported-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 scripts/minikconf.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/minikconf.py b/scripts/minikconf.py
index 90b99517c1..bcd91015d3 100755
--- a/scripts/minikconf.py
+++ b/scripts/minikconf.py
@@ -402,7 +402,7 @@ class KconfigParser:
         if incl_abs_fname in self.data.previously_included:
             return
         try:
-            fp = open(incl_abs_fname, 'r')
+            fp = open(incl_abs_fname, 'rt', encoding='utf-8')
         except IOError as e:
             raise KconfigParserError(self,
                                 '%s: %s' % (e.strerror, include))
@@ -696,7 +696,7 @@ if __name__ == '__main__':
             parser.do_assignment(name, value == 'y')
             external_vars.add(name[7:])
         else:
-            fp = open(arg, 'r')
+            fp = open(arg, 'rt', encoding='utf-8')
             parser.parse_file(fp)
             fp.close()
 
@@ -705,7 +705,7 @@ if __name__ == '__main__':
         if key not in external_vars and config[key]:
             print ('CONFIG_%s=y' % key)
 
-    deps = open(argv[2], 'w')
+    deps = open(argv[2], 'wt', encoding='utf-8')
     for fname in data.previously_included:
         print ('%s: %s' % (argv[1], fname), file=deps)
     deps.close()
-- 
2.25.3

Re: [PATCH] minikconf: explicitly set encoding to UTF-8

Posted by Stefan Hajnoczi 5 months, 2 weeks ago
On Thu, May 21, 2020 at 04:36:16PM +0100, Stefan Hajnoczi wrote:
> QEMU currently only has ASCII Kconfig files but Linux actually uses
> UTF-8. Explicitly specify the encoding and that we're doing text file
> I/O.
> 
> It's unclear whether or not QEMU will ever need Unicode in its Kconfig
> files. If we start using the help text then it will become an issue
> sooner or later. Make this change now for consistency with Linux
> Kconfig.
> 
> Reported-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  scripts/minikconf.py | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

Re: [PATCH] minikconf: explicitly set encoding to UTF-8

Posted by Richard Henderson 6 months, 1 week ago
On 5/21/20 8:36 AM, Stefan Hajnoczi wrote:
> QEMU currently only has ASCII Kconfig files but Linux actually uses
> UTF-8. Explicitly specify the encoding and that we're doing text file
> I/O.
> 
> It's unclear whether or not QEMU will ever need Unicode in its Kconfig
> files. If we start using the help text then it will become an issue
> sooner or later. Make this change now for consistency with Linux
> Kconfig.
> 
> Reported-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  scripts/minikconf.py | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~