Skip to content

Commit e04ccd2

Browse files
committed
fix: detect direct sync calls using physical source lines
Recognize bare sync calls alongside global calls while excluding members. Keep reachability and reported call positions on the same newline basis.
1 parent 259c334 commit e04ccd2

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎scripts/test_native_source_guard.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,22 @@ def parse(level: int = 0) -> set[bool]:
360360

361361

362362
def _apple_fdatasync(text: str) -> tuple[int, list[int]]:
363-
"""Count lexical calls and locate those not provably excluded on Apple."""
363+
"""Count direct lexical calls not provably excluded on Apple.
364+
365+
Check bare fdatasync(...) and ::fdatasync(...), excluding member calls.
366+
Indirect calls through function pointers and token-pasted calls are
367+
outside this lexical check.
368+
"""
364369
# Splice before masking, as C++ does, including continued // comments.
365370
# Keep enough offset information to report physical source line numbers.
366371
splices = [match.start() - 2 * index for index, match in
367372
enumerate(re.finditer(r"\\\n", text))]
368373
masked = _mask_cpp(text.replace("\\\n", ""))
369374
calls: dict[int, list[int]] = {}
370375
count = 0
371-
for match in re.finditer(r"::\s*fdatasync\s*\(", masked):
376+
for match in re.finditer(r"(?:::\s*|(?<!\w))fdatasync\s*\(", masked):
377+
if masked[:match.start()].rstrip().endswith((".", "->")):
378+
continue
372379
logical_line = masked.count("\n", 0, match.start()) + 1
373380
physical_offset = match.start() + 2 * bisect_right(splices, match.start())
374381
calls.setdefault(logical_line, []).append(
@@ -382,7 +389,7 @@ def _apple_fdatasync(text: str) -> tuple[int, list[int]]:
382389
stack: list[tuple[bool, bool, bool]] = []
383390
reachable = True
384391
exposed: list[int] = []
385-
for line_number, line in enumerate(masked.splitlines(), 1):
392+
for line_number, line in enumerate(masked.split("\n"), 1):
386393
directive = re.match(r"^\s*#\s*(if|ifdef|ifndef|elif|else|endif)\b(.*)", line)
387394
if directive:
388395
kind, expression = directive.groups()

0 commit comments

Comments
 (0)