Skip to content

Commit c5ba8af

Browse files
gregersryggmbolivar-nordic
authored andcommitted
scripts: unity: Fix function definition regex bug
The whitespace fix to this regex last week triggered another bug in libmodem. They have a typedef that the regex parsed as a function definition because it accepted too many character in the argument list of a function. This fix updates the regex to only allow characters you would expect in an argument list of a function def. Characters expected in the argument list of a function def: \w A-Z a-z 0-9 and _ \s All whitespace , Argument separator * Pointers \. Variadic argument \[ Array start \] Array end Signed-off-by: Gregers Gram Rygg <[email protected]>
1 parent 2486637 commit c5ba8af

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

scripts/unity/func_name_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def func_names_from_header(in_file, out_file):
1414

1515
with open(out_file, 'w') as f_out:
1616
# Regex match all function names in the header file
17-
x = re.findall(r"^\s*(?:\w+[*\s]+)+(\w+?)\s*\([^\\]*?\)\s*;",
17+
x = re.findall(r"^\s*(?:\w+[*\s]+)+(\w+?)\s*\([\w\s,*\.\[\]]*?\)\s*;",
1818
content, re.M | re.S)
1919
for item in x:
2020
f_out.write(item + "\n")

scripts/unity/header_prepare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def header_prepare(in_file, out_file, out_wrap_file):
6363
# Prepare file with functions prefixed with __wrap_ that will be used for
6464
# mock generation.
6565
func_pattern = re.compile(
66-
r"^\s*((?:\w+[*\s]+)+)(\w+?\s*\([^\\{}#]*?\)\s*;)", re.M)
66+
r"^\s*((?:\w+[*\s]+)+)(\w+?\s*\([\w\s,*\.\[\]]*?\)\s*;)", re.M)
6767
content2 = func_pattern.sub(r"\n\1__wrap_\2", content)
6868

6969
with open(out_wrap_file, 'w') as f_wrap:

0 commit comments

Comments
 (0)