Skip to content

Commit

Permalink
Support XKB_CONTEXT_NO_SECURE_GETENV flag
Browse files Browse the repository at this point in the history
Introduced in libxkbcommon-1.5.0
  • Loading branch information
sde1000 committed Jul 5, 2024
1 parent 870f6f3 commit 12d10d1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:

strategy:
matrix:
os: ['ubuntu-22.04']
os: ['ubuntu-24.04']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

runs-on: ${{ matrix.os }}
Expand Down
7 changes: 7 additions & 0 deletions tests/test_xkb.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def tearDownClass(cls):
def test_create(self):
xkb.Context()

def test_no_secure_getenv(self):
# We are unlikely to be testing in an environment where
# secure_getenv() will return NULL instead of a value string,
# so just check that we are able to create a context with this
# flag set
xkb.Context(no_secure_getenv=True)

def test_default_includes(self):
ctx = xkb.Context(no_default_includes=True)
self.assertEqual(len(list(ctx.include_path())), 0)
Expand Down
3 changes: 2 additions & 1 deletion xkbcommon/ffi_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
enum xkb_context_flags {
XKB_CONTEXT_NO_FLAGS = ...,
XKB_CONTEXT_NO_DEFAULT_INCLUDES = ...,
XKB_CONTEXT_NO_ENVIRONMENT_NAMES = ...
XKB_CONTEXT_NO_ENVIRONMENT_NAMES = ...,
XKB_CONTEXT_NO_SECURE_GETENV = ...
};
struct xkb_context *
Expand Down
8 changes: 7 additions & 1 deletion xkbcommon/xkb.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ class Context:
XKB_DEFAULT_OPTIONS - see xkb_rule_names.
"""

def __init__(self, no_default_includes=False, no_environment_names=False):
def __init__(self, no_default_includes=False, no_environment_names=False,
no_secure_getenv=False):
"""Create a new context.
Keyword arguments:
Expand All @@ -239,12 +240,17 @@ def __init__(self, no_default_includes=False, no_environment_names=False):
no_environment_names: if set, don't take RMLVO names from the
environment.
no_secure_getenv: if set, use getenv() instead of
secure_getenv() to obtain environment variables.
"""
flags = lib.XKB_CONTEXT_NO_FLAGS
if no_default_includes:
flags = flags | lib.XKB_CONTEXT_NO_DEFAULT_INCLUDES
if no_environment_names:
flags = flags | lib.XKB_CONTEXT_NO_ENVIRONMENT_NAMES
if no_secure_getenv:
flags = flags | lib.XKB_CONTEXT_NO_SECURE_GETENV
context = lib.xkb_context_new(flags)
if not context:
raise XKBError("Couldn't create XKB context")
Expand Down

0 comments on commit 12d10d1

Please sign in to comment.