From 9129dd9501b05c48fffd931996c31be06e23dbad Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 20 Dec 2010 15:05:27 -0500 Subject: Maintain a stack of includes so we can special-case S_SPLINT_S. --- deheader | 15 ++++++++++----- deheader.xml | 5 ++++- test/README | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/deheader b/deheader index eb03d4f..16cc9f1 100755 --- a/deheader +++ b/deheader @@ -147,6 +147,7 @@ requirements = ( (r"fputwc()", [""]), (r"fputws()", [""]), (r"fread()", [""]), + (r"free()", [""]), # Header dependencies implies by SuS (r"", [""]), (r"", ["", ""]), @@ -223,12 +224,16 @@ class InclusionMap: for sourcefile in self.files: includes = [] requires = [] - ifdepth = 0 + conditions = [] for line in open(sourcefile): - if line.startswith("#if") or line.startswith("#ifndef"): - ifdepth += 1 + if line.startswith("#ifndef"): + conditions.append(line[7:].strip()) + elif line.startswith("#ifdef"): + conditions.append(line[6:].strip()) + elif line.startswith("#if"): + conditions.append(line[3:].strip()) elif line.startswith("#endif"): - ifdepth -= 1 + conditions.pop() elif line.startswith("#include"): if verbosity >= PROGRESS_DEBUG: name = trim(line) @@ -237,7 +242,7 @@ class InclusionMap: if verbosity >= PROGRESS_DEBUG: print "deheader: ignoring %s (exclusion match with %s)." % (name, ignore.pattern) continue - if ifdepth == 0: + if not conditions or conditions == ["S_SPLINT_S"]: includes.append(line) elif verbose > 1: print "deheader: ignoring %s (conditional inclusion)" % name diff --git a/deheader.xml b/deheader.xml index d765e4e..ea6044b 100644 --- a/deheader.xml +++ b/deheader.xml @@ -47,7 +47,10 @@ name of the current directory had been passed to it. Inclusions within the scope of #if/#ifdef/#else/#endif directives are left alone, because trying to reason about potential combinations of -D and U options would be too complicated and prone to -weird errors. +weird errors. One exception: headers protected only by S_SPLINT_S, the +conditional for blocking scanning by the static analysis tool +splint1, +are scanned normally. The tool will also emit warnings about duplicate inclusions, and inclusions required for portability but not present. diff --git a/test/README b/test/README index ffe1b30..0c2b63f 100644 --- a/test/README +++ b/test/README @@ -37,7 +37,7 @@ stdio.h - fgetpos(), fgets(), fileno(), f*lockfile(), fopen(), not tested. wchar.h - fgetwc(), fgetws() not tested. fmtmsg.h - fmtmsg() not tested. fnmatch.h - fnmatch() not tested. -unistd.h - fork(), fpathconf() not tested. +unistd.h - fork(), fpathconf(), free() not tested. stdio.h - *printf*, fputc(), fputwc(), fputws(), fread() not tested. For other dependencies not tested, see the commented-out lines in deheader's -- cgit v1.2.3-70-g09d2