diff --git a/libraries/libapparmor/include/aalogparse.h b/libraries/libapparmor/include/aalogparse.h index 7d177009d..8684b9e3a 100644 --- a/libraries/libapparmor/include/aalogparse.h +++ b/libraries/libapparmor/include/aalogparse.h @@ -48,12 +48,23 @@ typedef enum AA_RECORD_STATUS /* Configuration change */ } aa_record_event_type; -#ifndef __cplusplus +/* + * Use this preprocessor dance to maintain backcompat for field names + * This will break C code that used the C++ reserved keywords "namespace" + * and "class" as identifiers, but this is bad practice anyways, and we + * hope that we are the only ones in a given C file that messed up this way + * + * TODO: document this in a man page for aalogparse? + */ +#if defined(SWIG) && defined(__cplusplus) +#error "SWIG and __cplusplus are defined together" +#elif !defined(SWIG) && !defined(__cplusplus) +/* Use SWIG's %rename feature to preserve backcompat */ #define class rule_class #define namespace aa_namespace #endif -typedef struct +typedef struct aa_log_record { aa_record_syntax_version version; aa_record_event_type event; /* Event type */ diff --git a/libraries/libapparmor/swig/SWIG/libapparmor.i b/libraries/libapparmor/swig/SWIG/libapparmor.i index ff0f83040..a863193f5 100644 --- a/libraries/libapparmor/swig/SWIG/libapparmor.i +++ b/libraries/libapparmor/swig/SWIG/libapparmor.i @@ -55,6 +55,17 @@ warnings.warn("free_record is now a no-op as the record's memory is handled auto */ %ignore free_record; + +/* + * Map names to preserve backwards compatibility + */ +#ifdef SWIGPYTHON +%rename("_class") aa_log_record::rule_class; +#else +%rename("class") aa_log_record::rule_class; +#endif +%rename("namespace") aa_log_record::aa_namespace; + %include /**