Skip to content

Commit

Permalink
gumjs: Generate simpler enum value lookup code
Browse files Browse the repository at this point in the history
Some C compilers limit how many `else if` branches they support. One
such compiler is MSVC for arm64.

We should implement a better lookup scheme at some point though.
  • Loading branch information
oleavr committed Jul 18, 2024
1 parent 3d0d281 commit 6e33b00
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bindings/gumjs/generate-bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2349,8 +2349,11 @@ def generate_enum_parser(name, type, prefix, values):
statements = []
for i, value in enumerate(values):
statements.extend([
"{0}if (strcmp (name, \"{1}\") == 0)".format(" else " if i > 0 else "", value),
" *value = {0}{1};".format(prefix, value.upper().replace("-", "_")),
f" if (strcmp (name, \"{value}\") == 0)",
" {",
" *value = {}{};".format(prefix, value.upper().replace("-", "_")),
" return TRUE;",
" }",
])

code = """\
Expand All @@ -2359,10 +2362,9 @@ def generate_enum_parser(name, type, prefix, values):
const gchar * name,
{type} * value)
{{
{statements}
else
return FALSE;
return TRUE;
{statements}
return FALSE;
}}
""".format(
name=name,
Expand Down

0 comments on commit 6e33b00

Please sign in to comment.