Skip to content

Commit 21be609

Browse files
committed
In lint-format-strings, open files sequentially
In lint-format-strings, we use python argparse to read our file arguments. In this mode, argparse opens all the files simultaneously. On OS X, where the default filehandle limit is 128, this causes the lint to fail. Instead, ask argparse for our filename arguments as strings, and open them one at a time using 'with open'.
1 parent 14023c9 commit 21be609

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

test/lint/lint-format-strings.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -262,27 +262,27 @@ def main():
262262
parser.add_argument("--skip-arguments", type=int, help="number of arguments before the format string "
263263
"argument (e.g. 1 in the case of fprintf)", default=0)
264264
parser.add_argument("function_name", help="function name (e.g. fprintf)", default=None)
265-
parser.add_argument("file", type=argparse.FileType("r", encoding="utf-8"), nargs="*", help="C++ source code file (e.g. foo.cpp)")
265+
parser.add_argument("file", nargs="*", help="C++ source code file (e.g. foo.cpp)")
266266
args = parser.parse_args()
267-
268267
exit_code = 0
269-
for f in args.file:
270-
for function_call_str in parse_function_calls(args.function_name, f.read()):
271-
parts = parse_function_call_and_arguments(args.function_name, function_call_str)
272-
relevant_function_call_str = unescape("".join(parts))[:512]
273-
if (f.name, relevant_function_call_str) in FALSE_POSITIVES:
274-
continue
275-
if len(parts) < 3 + args.skip_arguments:
276-
exit_code = 1
277-
print("{}: Could not parse function call string \"{}(...)\": {}".format(f.name, args.function_name, relevant_function_call_str))
278-
continue
279-
argument_count = len(parts) - 3 - args.skip_arguments
280-
format_str = parse_string_content(parts[1 + args.skip_arguments])
281-
format_specifier_count = count_format_specifiers(format_str)
282-
if format_specifier_count != argument_count:
283-
exit_code = 1
284-
print("{}: Expected {} argument(s) after format string but found {} argument(s): {}".format(f.name, format_specifier_count, argument_count, relevant_function_call_str))
285-
continue
268+
for filename in args.file:
269+
with open(filename, "r", encoding="utf-8") as f:
270+
for function_call_str in parse_function_calls(args.function_name, f.read()):
271+
parts = parse_function_call_and_arguments(args.function_name, function_call_str)
272+
relevant_function_call_str = unescape("".join(parts))[:512]
273+
if (f.name, relevant_function_call_str) in FALSE_POSITIVES:
274+
continue
275+
if len(parts) < 3 + args.skip_arguments:
276+
exit_code = 1
277+
print("{}: Could not parse function call string \"{}(...)\": {}".format(f.name, args.function_name, relevant_function_call_str))
278+
continue
279+
argument_count = len(parts) - 3 - args.skip_arguments
280+
format_str = parse_string_content(parts[1 + args.skip_arguments])
281+
format_specifier_count = count_format_specifiers(format_str)
282+
if format_specifier_count != argument_count:
283+
exit_code = 1
284+
print("{}: Expected {} argument(s) after format string but found {} argument(s): {}".format(f.name, format_specifier_count, argument_count, relevant_function_call_str))
285+
continue
286286
sys.exit(exit_code)
287287

288288

0 commit comments

Comments
 (0)