From 535ddedd6087a30efb3348d579c208cbf097ab43 Mon Sep 17 00:00:00 2001 From: geisserml Date: Fri, 19 Jan 2024 23:45:21 +0100 Subject: [PATCH] Add option to get rid of all CPP defaults at once --- ctypesgen/__main__.py | 7 ++++++- ctypesgen/parser/preprocessor.py | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ctypesgen/__main__.py b/ctypesgen/__main__.py index 5340f779..a689e501 100644 --- a/ctypesgen/__main__.py +++ b/ctypesgen/__main__.py @@ -192,13 +192,18 @@ def __call__(self, parser, namespace, values, option_string=None): help="Instruct the preprocessor to undefine the specified macro via commandline", ) parser.add_argument( - "-X", "--no-default-cppflags", + "-X", "--pop-default-flags", nargs="+", action="extend", default=[], metavar="ENTRY", help="Remove ENTRY from preprocessor defaults, e.g. -X __GNUC__ can be used to not implicitly undefine __GNUC__.", ) + parser.add_argument( + "--no-default-flags", + action="store_true", + help="Do not add any default defines/undefines at all. Beware: this will most probably lead to more parser errors." + ) parser.add_argument( "--preproc-savepath", metavar="FILENAME", diff --git a/ctypesgen/parser/preprocessor.py b/ctypesgen/parser/preprocessor.py index 380b6b68..8f301c1f 100755 --- a/ctypesgen/parser/preprocessor.py +++ b/ctypesgen/parser/preprocessor.py @@ -61,7 +61,6 @@ def __init__(self, options, cparser): self.cparser = cparser # An instance of CParser self.default_flags = {"-D": {}, "-U": []} - self.default_flags["-D"].update({ "__extension__": "", "__asm__(x)": "", @@ -97,8 +96,11 @@ def __init__(self, options, cparser): def _get_default_flags(self): + if self.options.no_default_flags: + return {} + flags_dict = copy.deepcopy(self.default_flags) - crossout = self.options.no_default_cppflags + crossout = self.options.pop_default_flags for params in flags_dict.values(): deletor = params.pop if isinstance(params, dict) else params.remove unfound = []