Skip to content

Commit

Permalink
Invalid python function name fix (#69)
Browse files Browse the repository at this point in the history
* fix macOS barvinok build

* fix invalid python function name

* special casing for invalid py identifier
  • Loading branch information
thisiscam authored Oct 20, 2021
1 parent 33cdc99 commit a5c7df5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gen_wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ def on_directive_handle(self, directive, toks, ifpassthru, precedingtoks):
# {{{ FunctionData (includes parser)

class FunctionData:

INVALID_PY_IDENTIFIER_RENAMING_MAP = {
"2exp": "two_exp"
}

def __init__(self, include_dirs):
self.classes_to_methods = {}
self.include_dirs = include_dirs
Expand Down Expand Up @@ -656,6 +661,13 @@ def parse_decl(self, decl):
if name in PYTHON_RESERVED_WORDS:
name = name + "_"

name = self.INVALID_PY_IDENTIFIER_RENAMING_MAP.get(name, name)

if name[0].isdigit():
print(f"SKIP: {class_name} {name} "
"(unhandled invalid python identifier)")
return

if class_name == "options":
assert name.startswith("set_") or name.startswith("get_"), (name, c_name)
name = f"{name[:4]}option_{name[4:]}"
Expand Down

0 comments on commit a5c7df5

Please sign in to comment.