Skip to content

Commit

Permalink
Add option to get rid of all CPP defaults at once
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Jan 19, 2024
1 parent 93f7fe1 commit 535dded
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ctypesgen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions ctypesgen/parser/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)": "",
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 535dded

Please sign in to comment.