Skip to content

Commit 00c781e

Browse files
committed
Support XKB_CONTEXT_NO_SECURE_GETENV flag
Introduced in libxkbcommon-1.5.0
1 parent 870f6f3 commit 00c781e

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

tests/test_xkb.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ def tearDownClass(cls):
5959
def test_create(self):
6060
xkb.Context()
6161

62+
def test_no_secure_getenv(self):
63+
# We are unlikely to be testing in an environment where
64+
# secure_getenv() will return NULL instead of a value string,
65+
# so just check that we are able to create a context with this
66+
# flag set
67+
xkb.Context(no_secure_getenv=True)
68+
6269
def test_default_includes(self):
6370
ctx = xkb.Context(no_default_includes=True)
6471
self.assertEqual(len(list(ctx.include_path())), 0)

xkbcommon/ffi_build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@
9696
enum xkb_context_flags {
9797
XKB_CONTEXT_NO_FLAGS = ...,
9898
XKB_CONTEXT_NO_DEFAULT_INCLUDES = ...,
99-
XKB_CONTEXT_NO_ENVIRONMENT_NAMES = ...
99+
XKB_CONTEXT_NO_ENVIRONMENT_NAMES = ...,
100+
XKB_CONTEXT_NO_SECURE_GETENV = ...
100101
};
101102
102103
struct xkb_context *

xkbcommon/xkb.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ class Context:
229229
XKB_DEFAULT_OPTIONS - see xkb_rule_names.
230230
"""
231231

232-
def __init__(self, no_default_includes=False, no_environment_names=False):
232+
def __init__(self, no_default_includes=False, no_environment_names=False,
233+
no_secure_getenv=False):
233234
"""Create a new context.
234235
235236
Keyword arguments:
@@ -239,12 +240,17 @@ def __init__(self, no_default_includes=False, no_environment_names=False):
239240
240241
no_environment_names: if set, don't take RMLVO names from the
241242
environment.
243+
244+
no_secure_getenv: if set, use getenv() instead of
245+
secure_getenv() to obtain environment variables.
242246
"""
243247
flags = lib.XKB_CONTEXT_NO_FLAGS
244248
if no_default_includes:
245249
flags = flags | lib.XKB_CONTEXT_NO_DEFAULT_INCLUDES
246250
if no_environment_names:
247251
flags = flags | lib.XKB_CONTEXT_NO_ENVIRONMENT_NAMES
252+
if no_secure_getenv:
253+
flags = flags | lib.XKB_CONTEXT_NO_SECURE_GETENV
248254
context = lib.xkb_context_new(flags)
249255
if not context:
250256
raise XKBError("Couldn't create XKB context")

0 commit comments

Comments
 (0)