diff options
author | Jani Nikula <jani.nikula@intel.com> | 2017-08-31 15:21:29 -0400 |
---|---|---|
committer | Jonathan Corbet <corbet@lwn.net> | 2017-08-31 15:36:28 -0400 |
commit | 86c0f046a8b0c23fca65f77333c233a06c25ef9a (patch) | |
tree | c855556f07686d52f232f89a778d7f41f0150103 /Documentation/sphinx/kerneldoc.py | |
parent | a27bfcab5c1c3a0df61b68e85fc5e4cade83559f (diff) |
Documentation/sphinx: fix kernel-doc decode for non-utf-8 locale
On python3, Popen() universal_newlines=True converts the subprocess
stdout to unicode text using a codec based on user preferences. Given
LANG indicating ascii and utf-8 stdout from the subprocess, you'd get:
WARNING: kernel-doc '../scripts/kernel-doc -rst -enable-lineno
../drivers/media/dvb-core/demux.h' processing failed with: 'ascii' codec can't
decode byte 0xe2 in position 6368: ordinal not in range(128)
Fix this by dropping universal_newlines=True and replacing the implicit
LANG specific decode with an explicit utf-8 decode. This also gets rid
of the annoying conditional code for python 2 vs. 3.
Fixes: ba3501859354 ("Documentation/sphinx: fix kernel-doc extension on python3")
Reference: http://mid.mail-archive.com/54c23e8e-89c0-5cea-0dcc-e938952c5642@infradead.org
Reported-and-tested-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Diffstat (limited to 'Documentation/sphinx/kerneldoc.py')
-rw-r--r-- | Documentation/sphinx/kerneldoc.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/Documentation/sphinx/kerneldoc.py b/Documentation/sphinx/kerneldoc.py index d15e07f36881..39aa9e8697cc 100644 --- a/Documentation/sphinx/kerneldoc.py +++ b/Documentation/sphinx/kerneldoc.py | |||
@@ -27,6 +27,7 @@ | |||
27 | # Please make sure this works on both python2 and python3. | 27 | # Please make sure this works on both python2 and python3. |
28 | # | 28 | # |
29 | 29 | ||
30 | import codecs | ||
30 | import os | 31 | import os |
31 | import subprocess | 32 | import subprocess |
32 | import sys | 33 | import sys |
@@ -88,13 +89,10 @@ class KernelDocDirective(Directive): | |||
88 | try: | 89 | try: |
89 | env.app.verbose('calling kernel-doc \'%s\'' % (" ".join(cmd))) | 90 | env.app.verbose('calling kernel-doc \'%s\'' % (" ".join(cmd))) |
90 | 91 | ||
91 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) | 92 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
92 | out, err = p.communicate() | 93 | out, err = p.communicate() |
93 | 94 | ||
94 | # python2 needs conversion to unicode. | 95 | out, err = codecs.decode(out, 'utf-8'), codecs.decode(err, 'utf-8') |
95 | # python3 with universal_newlines=True returns strings. | ||
96 | if sys.version_info.major < 3: | ||
97 | out, err = unicode(out, 'utf-8'), unicode(err, 'utf-8') | ||
98 | 96 | ||
99 | if p.returncode != 0: | 97 | if p.returncode != 0: |
100 | sys.stderr.write(err) | 98 | sys.stderr.write(err) |