Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH] Warn if LC_CTYPE does not toupper()/tolower() ASCII chars correctly
Date: Wed, 11 Nov 2015 21:33:42
Message-Id: 1447277615-26774-1-git-send-email-mgorny@gentoo.org
1 Output a warning if LC_CTYPE is set to a value that causes libc
2 toupper() and/or tolower() conversions not apply correctly to printable
3 ASCII characters.
4 ---
5 pym/_emerge/actions.py | 40 ++++++++++++++++++++++++++++++++++++++++
6 1 file changed, 40 insertions(+)
7
8 diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
9 index 7f1cb59..31825ae 100644
10 --- a/pym/_emerge/actions.py
11 +++ b/pym/_emerge/actions.py
12 @@ -26,6 +26,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
13 'portage.dbapi._similar_name_search:similar_name_search',
14 'portage.debug',
15 'portage.news:count_unread_news,display_news_notifications',
16 + 'portage.util._ctypes:find_library,LoadLibrary',
17 'portage.util._get_vm_info:get_vm_info',
18 'portage.emaint.modules.sync.sync:SyncRepos',
19 '_emerge.chk_updated_cfg_files:chk_updated_cfg_files',
20 @@ -2451,6 +2452,43 @@ def getgccversion(chost):
21 # lead them to report invalid bugs.
22 _emerge_features_warn = frozenset(['keeptemp', 'keepwork'])
23
24 +def check_case_conversion_sanity():
25 + # test for insane LC_CTYPE
26 + libc_fn = find_library("c")
27 + if libc_fn is not None:
28 + libc = LoadLibrary(libc_fn)
29 + if libc is not None:
30 + lc = list(range(ord('a'), ord('z')+1))
31 + uc = list(range(ord('A'), ord('Z')+1))
32 + rlc = [libc.tolower(c) for c in uc]
33 + ruc = [libc.toupper(c) for c in lc]
34 +
35 + if lc != rlc or uc != ruc:
36 + msg = ("WARNING: The LC_CTYPE variable is set to " +
37 + "a locale that does not convert between lowercase " +
38 + "and uppercase ASCII characters correctly. This " +
39 + "can break ebuilds and cause issues in programs " +
40 + "that rely on latin character conversion. " +
41 + "Please consider enabling another locale (such as " +
42 + "en_US.UTF-8) in /etc/locale.gen and setting it " +
43 + "as LC_TYPE in make.conf.")
44 + msg = [l for l in textwrap.wrap(msg, 70)]
45 + msg.append("")
46 + if uc != ruc:
47 + msg.extend([
48 + " %s -> %s" % (''.join([chr(x) for x in lc]),
49 + ''.join([chr(x) for x in ruc])),
50 + " %28s: %s" % ('expected',
51 + ''.join([chr(x) for x in uc]))])
52 + if lc != rlc:
53 + msg.extend([
54 + " %s -> %s" % (''.join([chr(x) for x in uc]),
55 + ''.join([chr(x) for x in rlc])),
56 + " %28s: %s" % ('expected',
57 + ''.join([chr(x) for x in lc]))])
58 + writemsg_level("".join(["!!! %s\n" % l for l in msg]),
59 + level=logging.ERROR, noiselevel=-1)
60 +
61 def validate_ebuild_environment(trees):
62 features_warn = set()
63 for myroot in trees:
64 @@ -2467,6 +2505,8 @@ def validate_ebuild_environment(trees):
65 for line in textwrap.wrap(msg, 65):
66 out.ewarn(line)
67
68 + check_case_conversion_sanity()
69 +
70 def check_procfs():
71 procfs_path = '/proc'
72 if platform.system() not in ("Linux",) or \
73 --
74 2.6.3

Replies