Add SWIG renames for fields to preserve backcompat

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
This commit is contained in:
Ryan Lee 2024-09-30 12:56:06 -07:00
parent 3f5180527d
commit e2c407c614
2 changed files with 24 additions and 2 deletions

View file

@ -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 */

View file

@ -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 <aalogparse.h>
/**