From f05112b5e9b79bb265c2e820af6fb49f712ca97f Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 23 Sep 2024 13:04:23 -0700 Subject: [PATCH] aa_is_enabled now returns a boolean in Python Because boooleans are a subclass of ints in Python, this isn't a breaking change Signed-off-by: Ryan Lee --- libraries/libapparmor/swig/SWIG/libapparmor.i | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libraries/libapparmor/swig/SWIG/libapparmor.i b/libraries/libapparmor/swig/SWIG/libapparmor.i index b66b7ea5d..0cdce1e92 100644 --- a/libraries/libapparmor/swig/SWIG/libapparmor.i +++ b/libraries/libapparmor/swig/SWIG/libapparmor.i @@ -122,6 +122,19 @@ extern char *aa_splitcon(char *con, char **mode); /* apparmor.h */ +/* + * aa_is_enabled returns a boolean as an int with failure reason in errno + * Therefore, aa_is_enabled either returns True or throws an exception + * + * Keep that behavior for backwards compatibilty but return a boolean on Python + * where it makes more sense, which isn't a breaking change because a boolean is + * a subclass of int + */ +#ifdef SWIGPYTHON +%typemap(out) int { + $result = PyBool_FromLong($1); +} +#endif extern int aa_is_enabled(void); /* These should not receive the VOID_Object typemap */