From 00c781efd8c2cb01fb51e7d2d0ee9bba0dda3b06 Mon Sep 17 00:00:00 2001 From: Stephen Early Date: Fri, 5 Jul 2024 23:15:21 +0100 Subject: [PATCH] Support XKB_CONTEXT_NO_SECURE_GETENV flag Introduced in libxkbcommon-1.5.0 --- tests/test_xkb.py | 7 +++++++ xkbcommon/ffi_build.py | 3 ++- xkbcommon/xkb.py | 8 +++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/test_xkb.py b/tests/test_xkb.py index 4c46e2b..3a8294d 100644 --- a/tests/test_xkb.py +++ b/tests/test_xkb.py @@ -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) diff --git a/xkbcommon/ffi_build.py b/xkbcommon/ffi_build.py index c222655..99fce31 100644 --- a/xkbcommon/ffi_build.py +++ b/xkbcommon/ffi_build.py @@ -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 * diff --git a/xkbcommon/xkb.py b/xkbcommon/xkb.py index 8de19af..afa7362 100644 --- a/xkbcommon/xkb.py +++ b/xkbcommon/xkb.py @@ -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: @@ -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")