- fix: specfile queries with BuildArch: (#27589).
authorjbj <devnull@localhost>
Sun, 6 May 2001 19:17:14 +0000 (19:17 +0000)
committerjbj <devnull@localhost>
Sun, 6 May 2001 19:17:14 +0000 (19:17 +0000)
CVS patchset: 4746
CVS date: 2001/05/06 19:17:14

15 files changed:
CHANGES
build.c
build/build.c
build/files.c
build/pack.c
build/parseDescription.c
build/parsePreamble.c
build/parseSpec.c
build/rpmbuild.h
build/rpmspec.h
build/spec.c
lib/Makefile.am
lib/fsm.c
lib/header.h
lib/query.c

diff --git a/CHANGES b/CHANGES
index f343f2f..b582d29 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -41,6 +41,8 @@
        - more boring lclint annotations and fiddles.
        - yet more boring lclint annotations and fiddles.
        - still more boring lclint annotations and fiddles.
+       - enough lclint annotations and fiddles already.
+       - fix: specfile queries with BuildArch: (#27589).
 
 4.0 -> 4.0.[12]
        - add doxygen and lclint annotations most everywhere.
diff --git a/build.c b/build.c
index 55980e8..2f920d3 100644 (file)
--- a/build.c
+++ b/build.c
@@ -279,8 +279,7 @@ static int buildForTarget(const char * arg, BTA_t ba,
     rc = 0;
 
 exit:
-    if (spec)
-       freeSpec(spec);
+    spec = freeSpec(spec);
     buildRootURL = _free(buildRootURL);
     return rc;
 }
index bb7ecdb..fdbf6ee 100644 (file)
@@ -250,13 +250,13 @@ int buildSpec(Spec spec, int what, int test)
 {
     int rc = 0;
 
-    if (!spec->inBuildArchitectures && spec->buildArchitectureCount) {
+    if (!spec->recursing && spec->BACount) {
        int x;
-       /* When iterating over buildArchitectures, do the source    */
+       /* When iterating over BANames, do the source    */
        /* packaging on the first run, and skip RMSOURCE altogether */
-       if (spec->buildArchitectureSpecs != NULL)
-       for (x = 0; x < spec->buildArchitectureCount; x++) {
-           if ((rc = buildSpec(spec->buildArchitectureSpecs[x],
+       if (spec->BASpecs != NULL)
+       for (x = 0; x < spec->BACount; x++) {
+           if ((rc = buildSpec(spec->BASpecs[x],
                                (what & ~RPMBUILD_RMSOURCE) |
                                (x ? 0 : (what & RPMBUILD_PACKAGESOURCE)),
                                test))) {
index 6f011df..f643a0d 100644 (file)
@@ -169,7 +169,8 @@ static void dupAttrRec(const AttrRec oar, /*@in@*/ /*@out@*/ AttrRec nar)
 #if 0
 /**
  */
-static void dumpAttrRec(const char *msg, AttrRec ar)   /*@*/
+static void dumpAttrRec(const char * msg, AttrRec ar)
+       /*@modifies fileSystem @*/
 {
     if (msg)
        fprintf(stderr, "%s:\t", msg);
@@ -1835,10 +1836,10 @@ void initSourceHeader(Spec spec)
     }
     headerFreeIterator(hi);
 
-    if (spec->buildArchitectures && spec->buildArchitectureCount > 0) {
+    if (spec->BANames && spec->BACount > 0) {
        (void) headerAddEntry(spec->sourceHeader, RPMTAG_BUILDARCHS,
                       RPM_STRING_ARRAY_TYPE,
-                      spec->buildArchitectures, spec->buildArchitectureCount);
+                      spec->BANames, spec->BACount);
     }
 }
 
index f4a2ed0..0ca53f8 100644 (file)
@@ -311,7 +311,7 @@ int readRPM(const char *fileName, Spec *specp, struct rpmlead *lead, Header *sig
     if (specp)
        *specp = spec;
     else
-       freeSpec(spec);
+       spec = freeSpec(spec);
 
     if (csa != NULL)
        csa->cpioFdIn = fdi;
index 3f3ab54..210d3a3 100644 (file)
@@ -30,7 +30,7 @@ int parseDescription(Spec spec)
     int arg;
     const char **argv = NULL;
     poptContext optCon = NULL;
-    struct spectag *t = NULL;
+    spectag t = NULL;
 
     name = NULL;
     lang = RPMBUILD_DEFAULT_LANG;
index 0000fef..47c92af 100644 (file)
@@ -370,14 +370,13 @@ exit:
     return rc;
 }
 
-struct spectag *
-stashSt(Spec spec, Header h, int tag, const char *lang)
+spectag stashSt(Spec spec, Header h, int tag, const char * lang)
 {
     HGE_t hge = (HGE_t)headerGetEntryMinMemory;
-    struct spectag *t = NULL;
+    spectag t = NULL;
 
     if (spec->st) {
-       struct spectags *st = spec->st;
+       spectags st = spec->st;
        if (st->st_ntags == st->st_nalloc) {
            st->st_nalloc += 10;
            st->st_t = xrealloc(st->st_t, st->st_nalloc * sizeof(*(st->st_t)));
@@ -638,15 +637,15 @@ static int handlePreambleTag(Spec spec, Package pkg, int tag, const char *macro,
        break;
       case RPMTAG_BUILDARCHS:
        if ((rc = poptParseArgvString(field,
-                                     &(spec->buildArchitectureCount),
-                                     &(spec->buildArchitectures)))) {
+                                     &(spec->BACount),
+                                     &(spec->BANames)))) {
            rpmError(RPMERR_BADSPEC,
                     _("line %d: Bad BuildArchitecture format: %s\n"),
                     spec->lineNum, spec->line);
            return RPMERR_BADSPEC;
        }
-       if (!spec->buildArchitectureCount)
-           spec->buildArchitectures = _free(spec->buildArchitectures);
+       if (!spec->BACount)
+           spec->BANames = _free(spec->BANames);
        break;
 
       default:
@@ -839,7 +838,7 @@ int parsePreamble(Spec spec, int initialPackage)
                }
                if (handlePreambleTag(spec, pkg, tag, macro, lang))
                    return RPMERR_BADSPEC;
-               if (spec->buildArchitectures && !spec->inBuildArchitectures)
+               if (spec->BANames && !spec->recursing)
                    return PART_BUILDARCHITECTURES;
            }
            if ((rc =
index c3e8883..28bc3d6 100644 (file)
@@ -219,7 +219,7 @@ retry:
        ofi->lineNum++;
        spec->lineNum = ofi->lineNum;
        if (spec->sl) {
-           struct speclines * sl = spec->sl;
+           speclines sl = spec->sl;
            if (sl->sl_nlines == sl->sl_nalloc) {
                sl->sl_nalloc += 100;
                sl->sl_lines = (char **) xrealloc(sl->sl_lines, 
@@ -354,8 +354,9 @@ void closeSpec(Spec spec)
 
 extern int noLang;             /* XXX FIXME: pass as arg */
 
+/*@todo Skip parse recursion if os is not compatible. @*/
 int parseSpec(Spec *specp, const char *specFile, const char *rootURL,
-               const char *buildRootURL, int inBuildArch, const char *passPhrase,
+               const char *buildRootURL, int recursing, const char *passPhrase,
                char *cookie, int anyarch, int force)
 {
     rpmParseState parsePart = PART_PREAMBLE;
@@ -364,7 +365,6 @@ int parseSpec(Spec *specp, const char *specFile, const char *rootURL,
     const char *saveArch;
 #endif
     Package pkg;
-    int x, index;
     Spec spec;
     
     /* Set up a new Spec structure with no packages. */
@@ -396,7 +396,7 @@ if (_debug)
 fprintf(stderr, "*** PS buildRootURL(%s) %p macro set to %s\n", spec->buildRootURL, spec->buildRootURL, buildRoot);
     }
     addMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC);
-    spec->inBuildArchitectures = inBuildArch;
+    spec->recursing = recursing;
     spec->anyarch = anyarch;
     spec->force = force;
 
@@ -456,65 +456,72 @@ fprintf(stderr, "*** PS buildRootURL(%s) %p macro set to %s\n", spec->buildRootU
        }
 
        if (parsePart >= PART_LAST) {
-           freeSpec(spec);
+           spec = freeSpec(spec);
            return parsePart;
        }
 
        if (parsePart == PART_BUILDARCHITECTURES) {
-           spec->buildArchitectureSpecs =
-               xmalloc(sizeof(Spec) * spec->buildArchitectureCount);
+           int index;
+           int x;
+
+           closeSpec(spec);
+
+           spec->BASpecs = xmalloc(spec->BACount * sizeof(Spec));
            index = 0;
-           if (spec->buildArchitectures != NULL)
-           for (x = 0; x < spec->buildArchitectureCount; x++) {
-               if (rpmMachineScore(RPM_MACHTABLE_BUILDARCH,
-                                   spec->buildArchitectures[x])) {
+           if (spec->BANames != NULL)
+           for (x = 0; x < spec->BACount; x++) {
+
+               /* Skip if not arch is not compatible. */
+               if (!rpmMachineScore(RPM_MACHTABLE_BUILDARCH, spec->BANames[x]))
+                   continue;
 #ifdef DYING
-                   rpmGetMachine(&saveArch, NULL);
-                   saveArch = xstrdup(saveArch);
-                   rpmSetMachine(spec->buildArchitectures[x], NULL);
+               rpmGetMachine(&saveArch, NULL);
+               saveArch = xstrdup(saveArch);
+               rpmSetMachine(spec->BANames[x], NULL);
 #else
-                   addMacro(NULL, "_target_cpu", NULL, spec->buildArchitectures[x], RMIL_RPMRC);
+               addMacro(NULL, "_target_cpu", NULL, spec->BANames[x], RMIL_RPMRC);
 #endif
-                   if (parseSpec(&(spec->buildArchitectureSpecs[index]),
+               if (parseSpec(&(spec->BASpecs[index]),
                                  specFile, spec->rootURL, buildRootURL, 1,
-                                 passPhrase, cookie, anyarch, force)) {
-                       spec->buildArchitectureCount = index;
-                       freeSpec(spec);
+                                 passPhrase, cookie, anyarch, force))
+               {
+                       spec->BACount = index;
+                       spec = freeSpec(spec);
                        return RPMERR_BADSPEC;
-                   }
+               }
 #ifdef DYING
-                   rpmSetMachine(saveArch, NULL);
-                   saveArch = _free(saveArch);
+               rpmSetMachine(saveArch, NULL);
+               saveArch = _free(saveArch);
 #else
-                   delMacro(NULL, "_target_cpu");
+               delMacro(NULL, "_target_cpu");
 #endif
-                   index++;
-               }
+               index++;
            }
-           spec->buildArchitectureCount = index;
+
+           spec->BACount = index;
            if (! index) {
-               freeSpec(spec);
-               rpmError(RPMERR_BADSPEC, _("No buildable architectures\n"));
+               spec = freeSpec(spec);
+               rpmError(RPMERR_BADSPEC,
+                       _("No compatible architectures found for build\n"));
                return RPMERR_BADSPEC;
            }
 
-           /* XXX HACK: Swap sl/st with child.
+           /*
+            * Return the 1st child's fully parsed Spec structure.
             * The restart of the parse when encountering BuildArch
-            * causes problems for "rpm -q --specfile --specedit"
-            * which needs to keep track of the entire spec file.
+            * causes problems for "rpm -q --specfile". This is
+            * still a hack because there may be more than 1 arch
+            * specified (unlikely but possible.) There's also the
+            * further problem that the macro context, particularly
+            * %{_target_cpu}, disagrees with the info in the header.
             */
-
-           if (spec->sl && spec->st) {
-               Spec nspec = *spec->buildArchitectureSpecs;
-               struct speclines *sl = spec->sl;
-               struct spectags *st = spec->st;
-               spec->sl = nspec->sl;
-               spec->st = nspec->st;
-               nspec->sl = sl;
-               nspec->st = st;
+           if (spec->BACount >= 1) {
+               Spec nspec = spec->BASpecs[0];
+               spec->BASpecs = _free(spec->BASpecs);
+               spec = freeSpec(spec);
+               spec = nspec;
            }
 
-           closeSpec(spec);
            *specp = spec;
            return 0;
        }
@@ -551,7 +558,7 @@ fprintf(stderr, "*** PS buildRootURL(%s) %p macro set to %s\n", spec->buildRootU
            (void) headerNVR(pkg->header, &name, NULL, NULL);
            rpmError(RPMERR_BADSPEC, _("Package has no %%description: %s\n"),
                        name);
-           freeSpec(spec);
+           spec = freeSpec(spec);
            return RPMERR_BADSPEC;
        }
 
index 7e66e39..4d78c6d 100644 (file)
@@ -325,16 +325,18 @@ int lookupPackage(Spec spec, /*@null@*/ const char * name, int flag,
 
 /** \ingroup rpmbuild
  * Destroy all packages associated with spec file.
- * @param spec         spec file control structure
+ * @param packages     package control structure chain
+ * @return             NULL
  */
-void freePackages(Spec spec)
-       /*@modifies spec->packages @*/;
+/*@null@*/ Package freePackages(/*@only@*/ /*@null@*/ Package packages)
+       /*@modifies packages @*/;
 
 /** \ingroup rpmbuild
  * Destroy package control structure.
  * @param pkg          package control structure
+ * @return             NULL
  */
-void freePackage(/*@only@*/ Package pkg)
+/*@null@*/ Package  freePackage(/*@only@*/ /*@null@*/ Package pkg)
        /*@modifies pkg @*/;
 
 /** \ingroup rpmbuild
@@ -380,7 +382,7 @@ int processBinaryFiles(Spec spec, int installSpecialDoc, int test)
  */
 void initSourceHeader(Spec spec)
        /*@modifies spec->sourceHeader,
-               spec->buildRestrictions, spec->buildArchitectures,
+               spec->buildRestrictions, spec->BANames,
                spec->packages->header @*/;
 
 /** \ingroup rpmbuild
@@ -390,7 +392,7 @@ void initSourceHeader(Spec spec)
  */
 int processSourceFiles(Spec spec)
        /*@modifies spec->sourceHeader, spec->sourceCpioList,
-               spec->buildRestrictions, spec->buildArchitectures,
+               spec->buildRestrictions, spec->BANames,
                spec->packages->header @*/;
 
 /* global entry points */
@@ -401,7 +403,7 @@ int processSourceFiles(Spec spec)
  * @param specFile
  * @param rootdir
  * @param buildRoot
- * @param inBuildArch
+ * @param recursing    parse is recursive?
  * @param passPhrase
  * @param cookie
  * @param anyarch
@@ -411,7 +413,7 @@ int processSourceFiles(Spec spec)
 int parseSpec(/*@out@*/ Spec * specp, const char * specFile,
                /*@null@*/ const char * rootdir,
                /*@null@*/ const char * buildRoot,
-               int inBuildArch,
+               int recursing,
                /*@null@*/ const char * passPhrase,
                /*@null@*/ char * cookie,
                int anyarch, int force)
@@ -422,7 +424,7 @@ int parseSpec(/*@out@*/ Spec * specp, const char * specFile,
  * @param specFile
  * @param rootdir
  * @param buildRoot
- * @param inBuildArch
+ * @param recursing    parse is recursive?
  * @param passPhrase
  * @param cookie
  * @param anyarch
@@ -432,7 +434,7 @@ int parseSpec(/*@out@*/ Spec * specp, const char * specFile,
 extern int (*parseSpecVec) (Spec * specp, const char * specFile,
                const char * rootdir,
                /*@null@*/ const char * buildRoot,
-               int inBuildArch,
+               int recursing,
                /*@null@*/ const char * passPhrase,
                /*@null@*/ char * cookie,
                int anyarch, int force)
@@ -448,8 +450,8 @@ extern int (*parseSpecVec) (Spec * specp, const char * specFile,
 int buildSpec(Spec spec, int what, int test)
        /*@modifies spec->sourceHeader, spec->sourceCpioList, spec->cookie,
                spec->sourceRpmName, spec->macros,
-               spec->buildArchitectureSpecs,
-               spec->buildRestrictions, spec->buildArchitectures,
+               spec->BASpecs,
+               spec->buildRestrictions, spec->BANames,
                spec->packages->cpioList, spec->packages->specialDoc,
                spec->packages->header @*/;
 
index 3b660b0..d7f4843 100644 (file)
@@ -59,29 +59,29 @@ typedef struct OpenFileInfo {
 
 /** \ingroup rpmbuild
  */
-struct spectag {
+typedef struct spectag_s {
     int t_tag;
     int t_startx;
     int t_nlines;
 /*@only@*/ const char * t_lang;
 /*@only@*/ const char * t_msgid;
-};
+} * spectag;
 
 /** \ingroup rpmbuild
  */
-struct spectags {
-/*@owned@*/ struct spectag *st_t;
+typedef struct spectags_s {
+/*@owned@*/ spectag st_t;
     int st_nalloc;
     int st_ntags;
-};
+} * spectags;
 
 /** \ingroup rpmbuild
  */
-struct speclines {
+typedef struct speclines_s {
 /*@only@*/ char **sl_lines;
     int sl_nalloc;
     int sl_nlines;
-};
+} * speclines;
 
 /** \ingroup rpmbuild
  * The structure used to store values parsed from a spec file.
@@ -93,8 +93,8 @@ struct SpecStruct {
 /*@only@*/ const char * buildSubdir;
 /*@only@*/ const char * rootURL;
 
-/*@owned@*/ /*@null@*/ struct speclines * sl;
-/*@owned@*/ /*@null@*/ struct spectags * st;
+/*@owned@*/ /*@null@*/ speclines sl;
+/*@owned@*/ /*@null@*/ spectags st;
 
 /*@owned@*/ struct OpenFileInfo * fileStack;
     char lbuf[4*BUFSIZ];
@@ -106,10 +106,10 @@ struct SpecStruct {
 /*@owned@*/ struct ReadLevelEntry * readStack;
 
 /*@refcounted@*/ Header buildRestrictions;
-/*@owned@*/ /*@null@*/ struct SpecStruct ** buildArchitectureSpecs;
-/*@only@*/ /*@null@*/ const char ** buildArchitectures;
-    int buildArchitectureCount;
-    int inBuildArchitectures;
+/*@owned@*/ /*@null@*/ struct SpecStruct ** BASpecs;
+/*@only@*/ /*@null@*/ const char ** BANames;
+    int BACount;
+    int recursing;                     /*!< parse is recursive? */
 
     int force;
     int anyarch;
@@ -176,20 +176,23 @@ extern "C" {
 
 /** \ingroup rpmbuild
  * Create and initialize Spec structure.
+ * @return spec                spec file control structure
  */
 /*@only@*/ Spec newSpec(void)  /*@*/;
 
 /** \ingroup rpmbuild
  * Destroy Spec structure.
  * @param spec         spec file control structure
+ * @return             NULL always
  */
-void freeSpec(/*@only@*/ Spec spec)
+/*@null@*/ Spec freeSpec(/*@only@*/ /*@null@*/ Spec spec)
        /*@modifies spec @*/;
 
 /** \ingroup rpmbuild
  * @param spec         spec file control structure
+ * @return             NULL always
  */
-extern void (*freeSpecVec) (Spec spec) /* XXX FIXME */
+extern /*@null@*/ Spec (*freeSpecVec) (Spec spec)      /* XXX FIXME */
        /*@modifies spec @*/;
 
 /** \ingroup rpmbuild
@@ -199,7 +202,7 @@ struct OpenFileInfo * newOpenFileInfo(void) /*@*/;
 /** \ingroup rpmbuild
  * @param spec         spec file control structure
  */
-struct spectag * stashSt(Spec spec, Header h, int tag, const char * lang)
+spectag stashSt(Spec spec, Header h, int tag, const char * lang)
        /*@modifies spec->st @*/;
 
 /** \ingroup rpmbuild
index a0f03d1..4159e75 100644 (file)
@@ -18,8 +18,10 @@ extern struct MacroContext_s rpmGlobalMacroContext;
 /*@access Header @*/   /* compared with NULL */
 
 /**
+ * @return             NULL always
  */
-static inline void freeTriggerFiles(/*@only@*/ struct TriggerFileEntry *p)
+static inline
+/*@null@*/ struct TriggerFileEntry * freeTriggerFiles(/*@only@*/ /*@null@*/ struct TriggerFileEntry * p)
 {
     struct TriggerFileEntry *o, *q = p;
     
@@ -31,11 +33,16 @@ static inline void freeTriggerFiles(/*@only@*/ struct TriggerFileEntry *p)
        o->prog = _free(o->prog);
        o = _free(o);
     }
+    return NULL;
 }
 
 /**
+ * Destroy source component chain.
+ * @param              source component chain
+ * @return             NULL always
  */
-static inline void freeSources(/*@only@*/ struct Source *s)
+static inline
+/*@null@*/ struct Source * freeSources(/*@only@*/ /*@null@*/ struct Source * s)
 {
     struct Source *r, *t = s;
 
@@ -45,6 +52,7 @@ static inline void freeSources(/*@only@*/ struct Source *s)
        r->fullSource = _free(r->fullSource);
        r = _free(r);
     }
+    return NULL;
 }
 
 int lookupPackage(Spec spec, const char *name, int flag, /*@out@*/Package *pkg)
@@ -135,10 +143,9 @@ Package newPackage(Spec spec)
     return p;
 }
 
-void freePackage(/*@only@*/ Package p)
+Package freePackage(Package p)
 {
-    if (p == NULL)
-       return;
+    if (p == NULL) return NULL;
     
     p->preInFile = _free(p->preInFile);
     p->postInFile = _free(p->postInFile);
@@ -147,6 +154,7 @@ void freePackage(/*@only@*/ Package p)
     p->verifyFile = _free(p->verifyFile);
 
     headerFree(p->header);
+    p->header = NULL;
     p->fileList = freeStringBuf(p->fileList);
     p->fileFile = _free(p->fileFile);
     if (p->cpioList) {
@@ -157,25 +165,23 @@ void freePackage(/*@only@*/ Package p)
     }
 
     p->specialDoc = freeStringBuf(p->specialDoc);
-
-    freeSources(p->icon);
-
-    freeTriggerFiles(p->triggerFiles);
+    p->icon = freeSources(p->icon);
+    p->triggerFiles = freeTriggerFiles(p->triggerFiles);
 
     p = _free(p);
+    return NULL;
 }
 
-void freePackages(Spec spec)
+Package freePackages(Package packages)
 {
     Package p;
 
-    while ((p = spec->packages) != NULL) {
-       /*@-dependenttrans@*/
-       spec->packages = p->next;
-       /*@=dependenttrans@*/
+    while ((p = packages) != NULL) {
+       packages = p->next;
        p->next = NULL;
-       freePackage(p);
+       p = freePackage(p);
     }
+    return NULL;
 }
 
 /**
@@ -184,16 +190,13 @@ static inline /*@owned@*/ struct Source *findSource(Spec spec, int num, int flag
 {
     struct Source *p;
 
-    for (p = spec->sources; p != NULL; p = p->next) {
-       if ((num == p->num) && (p->flags & flag)) {
-           return p;
-       }
-    }
+    for (p = spec->sources; p != NULL; p = p->next)
+       if ((num == p->num) && (p->flags & flag)) return p;
 
     return NULL;
 }
 
-int parseNoSource(Spec spec, const char *field, int tag)
+int parseNoSource(Spec spec, const char * field, int tag)
 {
     const char *f, *fe;
     const char *name;
@@ -295,8 +298,8 @@ int addSource(Spec spec, Package pkg, const char *field, int tag)
     p = xmalloc(sizeof(struct Source));
     p->num = num;
     p->fullSource = xstrdup(field);
-    p->source = strrchr(p->fullSource, '/');
     p->flags = flag;
+    p->source = strrchr(p->fullSource, '/');
     if (p->source) {
        p->source++;
     } else {
@@ -332,11 +335,11 @@ int addSource(Spec spec, Package pkg, const char *field, int tag)
 
 /**
  */
-static inline /*@only@*/ /*@null@*/ struct speclines * newSl(void)
+static inline /*@only@*/ /*@null@*/ speclines newSl(void)
 {
-    struct speclines * sl = NULL;
+    speclines sl = NULL;
     if (specedit) {
-       sl = xmalloc(sizeof(struct speclines));
+       sl = xmalloc(sizeof(*sl));
        sl->sl_lines = NULL;
        sl->sl_nalloc = 0;
        sl->sl_nlines = 0;
@@ -346,26 +349,25 @@ static inline /*@only@*/ /*@null@*/ struct speclines * newSl(void)
 
 /**
  */
-static inline void freeSl(/*@only@*/ /*@null@*/ struct speclines * sl)
+static inline /*@null@*/ speclines freeSl(/*@only@*/ /*@null@*/ speclines sl)
 {
     int i;
-    if (sl == NULL)
-       return;
+    if (sl == NULL) return NULL;
     for (i = 0; i < sl->sl_nlines; i++)
        /*@-unqualifiedtrans@*/
        sl->sl_lines[i] = _free(sl->sl_lines[i]);
        /*@=unqualifiedtrans@*/
     sl->sl_lines = _free(sl->sl_lines);
-    sl = _free(sl);
+    return _free(sl);
 }
 
 /**
  */
-static inline /*@only@*/ /*@null@*/ struct spectags * newSt(void)
+static inline /*@only@*/ /*@null@*/ spectags newSt(void)
 {
-    struct spectags *st = NULL;
+    spectags st = NULL;
     if (specedit) {
-       st = xmalloc(sizeof(struct spectags));
+       st = xmalloc(sizeof(*st));
        st->st_t = NULL;
        st->st_nalloc = 0;
        st->st_ntags = 0;
@@ -375,18 +377,17 @@ static inline /*@only@*/ /*@null@*/ struct spectags * newSt(void)
 
 /**
  */
-static inline void freeSt(/*@only@*/ /*@null@*/ struct spectags *st)
+static inline /*@null@*/ spectags freeSt(/*@only@*/ /*@null@*/ spectags st)
 {
     int i;
-    if (st == NULL)
-       return;
+    if (st == NULL) return NULL;
     for (i = 0; i < st->st_ntags; i++) {
-       struct spectag *t = st->st_t + i;
+       spectag t = st->st_t + i;
        t->t_lang = _free(t->t_lang);
        t->t_msgid = _free(t->t_msgid);
     }
     st->st_t = _free(st->st_t);
-    st = _free(st);
+    return _free(st);
 }
 
 Spec newSpec(void)
@@ -433,10 +434,10 @@ Spec newSpec(void)
     spec->cookie = NULL;
 
     spec->buildRestrictions = headerNew();
-    spec->buildArchitectures = NULL;
-    spec->buildArchitectureCount = 0;
-    spec->inBuildArchitectures = 0;
-    spec->buildArchitectureSpecs = NULL;
+    spec->BANames = NULL;
+    spec->BACount = 0;
+    spec->recursing = 0;
+    spec->BASpecs = NULL;
 
     spec->force = 0;
     spec->anyarch = 0;
@@ -446,13 +447,14 @@ Spec newSpec(void)
     return spec;
 }
 
-void freeSpec(/*@only@*/ Spec spec)
+Spec freeSpec(Spec spec)
 {
-    struct OpenFileInfo *ofi;
     struct ReadLevelEntry *rl;
 
-    freeSl(spec->sl);  spec->sl = NULL;
-    freeSt(spec->st);  spec->st = NULL;
+    if (spec == NULL) return NULL;
+
+    spec->sl = freeSl(spec->sl);
+    spec->st = freeSt(spec->st);
 
     spec->prep = freeStringBuf(spec->prep);
     spec->build = freeStringBuf(spec->build);
@@ -465,6 +467,8 @@ void freeSpec(/*@only@*/ Spec spec)
     spec->specFile = _free(spec->specFile);
     spec->sourceRpmName = _free(spec->sourceRpmName);
 
+#ifdef DEAD
+  { struct OpenFileInfo *ofi;
     while (spec->fileStack) {
        ofi = spec->fileStack;
        spec->fileStack = ofi->next;
@@ -472,6 +476,10 @@ void freeSpec(/*@only@*/ Spec spec)
        ofi->fileName = _free(ofi->fileName);
        ofi = _free(ofi);
     }
+  }
+#else
+    closeSpec(spec);
+#endif
 
     while (spec->readStack) {
        rl = spec->readStack;
@@ -497,30 +505,29 @@ void freeSpec(/*@only@*/ Spec spec)
     headerFree(spec->buildRestrictions);
     spec->buildRestrictions = NULL;
 
-    if (!spec->inBuildArchitectures) {
-       if (spec->buildArchitectureSpecs != NULL)
-       while (spec->buildArchitectureCount--) {
+    if (!spec->recursing) {
+       if (spec->BASpecs != NULL)
+       while (spec->BACount--) {
            /*@-unqualifiedtrans@*/
-           freeSpec(
-               spec->buildArchitectureSpecs[spec->buildArchitectureCount]);
+           spec->BASpecs[spec->BACount] =
+                       freeSpec(spec->BASpecs[spec->BACount]);
            /*@=unqualifiedtrans@*/
        }
        /*@-compdef@*/
-       spec->buildArchitectureSpecs = _free(spec->buildArchitectureSpecs);
+       spec->BASpecs = _free(spec->BASpecs);
        /*@=compdef@*/
     }
-    spec->buildArchitectures = _free(spec->buildArchitectures);
+    spec->BANames = _free(spec->BANames);
 
     spec->passPhrase = _free(spec->passPhrase);
     spec->cookie = _free(spec->cookie);
 
-    freeSources(spec->sources);        spec->sources = NULL;
-    /*@-nullstate@*/   /* FIX: non-null pointers, shrug. */
-    freePackages(spec);
-    closeSpec(spec);
-    /*@=nullstate@*/
+    spec->sources = freeSources(spec->sources);
+    spec->packages = freePackages(spec->packages);
     
     spec = _free(spec);
+
+    return spec;
 }
 
 /*@only@*/ struct OpenFileInfo * newOpenFileInfo(void)
index 247cb44..65ec46d 100644 (file)
@@ -57,9 +57,16 @@ getdate.c: getdate.y
        @echo expect 10 shift/reduce conflicts
        $(YACC) $(srcdir)/getdate.y
        -@if test -f y.tab.c; then \
-        { echo "/*@-globstate -retvalint -unqualifiedtrans -usedef -varuse -nullderef -exportlocal @*/";\
-          cat y.tab.c ;\
-          echo "/*@=globstate =retvalint =unqualifiedtrans =usedef =varuse =nullderef =exportlocal @*/";\
+        { echo "/*@-globstate -statictrans -unqualifiedtrans @*/";\
+          echo "/*@-retvalint -usedef -varuse -nullderef -nullassign @*/";\
+          sed  -e 's,y.tab.c,getdate.c,' y.tab.c \
+               -e 's,^YYSTYPE ,static &,' \
+               -e 's,^short ,static &,' \
+               -e 's,^const short ,static &,' \
+               -e 's,^int yydebug,/*@unused@*/ static &,' \
+               -e 's,^int ,static &,' ;\
+          echo "/*@=retvalint =usedef =varuse =nullderef =nullassign @*/";\
+          echo "/*@=globstate =statictrans =unqualifiedtrans @*/";\
         } > getdate.c ;\
           rm -f y.tab.c; \
        else \
index cf4bd43..b5ccb6d 100644 (file)
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -1126,7 +1126,7 @@ int fsmStage(FSM_t fsm, fileStage stage)
     struct stat * ost = &fsm->osb;
     int saveerrno = errno;
     int rc = fsm->rc;
-    int left;
+    size_t left;
     int i;
 
 #define        _fafilter(_a)   \
index db7fdea..7271156 100644 (file)
@@ -546,11 +546,13 @@ typedef enum rpmTagType_e {
 void * headerFreeData( /*@only@*/ /*@null@*/ const void * data, rpmTagType type)
 {
     if (data) {
+       /*@-branchstate@*/
        if (type < 0 ||
            type == RPM_STRING_ARRAY_TYPE ||
            type == RPM_I18NSTRING_TYPE ||
            type == RPM_BIN_TYPE)
                free((void *)data);
+       /*@=branchstate@*/
     }
     return NULL;
 }
index 74b82cc..b8f6c78 100644 (file)
@@ -365,8 +365,8 @@ static void
 printNewSpecfile(Spec spec)
 {
     Header h = spec->packages->header;
-    struct speclines *sl = spec->sl;
-    struct spectags *st = spec->st;
+    speclines sl = spec->sl;
+    spectags st = spec->st;
     const char * msgstr = NULL;
     int i, j;
 
@@ -374,7 +374,7 @@ printNewSpecfile(Spec spec)
        return;
 
     for (i = 0; i < st->st_ntags; i++) {
-       struct spectag * t = st->st_t + i;
+       spectag t = st->st_t + i;
        const char * tn = tagName(t->t_tag);
        const char * errstr;
        char fmt[128];
@@ -471,12 +471,12 @@ int showMatches(QVA_t qva, rpmdbMatchIterator mi, QVF_t showPackage)
  * @todo Eliminate linkage loop into librpmbuild.a
  */
 int    (*parseSpecVec) (Spec *specp, const char *specFile, const char *rootdir,
-               const char *buildRoot, int inBuildArch, const char *passPhrase,
+               const char *buildRoot, int recursing, const char *passPhrase,
                char *cookie, int anyarch, int force) = NULL;
 /**
  * @todo Eliminate linkage loop into librpmbuild.a
  */
-void   (*freeSpecVec) (Spec spec) = NULL;
+/*@null@*/ Spec        (*freeSpecVec) (Spec spec) = NULL;
 
 int rpmQueryVerify(QVA_t qva, rpmQVSources source, const char * arg,
        rpmdb rpmdb, QVF_t showPackage)
@@ -584,34 +584,33 @@ restart:
       { Spec spec = NULL;
        Package pkg;
        char * buildRoot = NULL;
-       int inBuildArch = 0;
+       int recursing = 0;
        char * passPhrase = "";
        char *cookie = NULL;
        int anyarch = 1;
        int force = 1;
 
-       rc = parseSpecVec(&spec, arg, "/", buildRoot, inBuildArch, passPhrase,
+       rc = parseSpecVec(&spec, arg, "/", buildRoot, recursing, passPhrase,
                cookie, anyarch, force);
        if (rc || spec == NULL) {
            
            rpmError(RPMERR_QUERY,
                        _("query of specfile %s failed, can't parse\n"), arg);
-           if (spec != NULL) freeSpecVec(spec);
+           spec = freeSpecVec(spec);
            retcode = 1;
            break;
        }
 
        if (specedit) {
            printNewSpecfile(spec);
-           freeSpecVec(spec);
+           spec = freeSpecVec(spec);
            retcode = 0;
            break;
        }
 
-       for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
+       for (pkg = spec->packages; pkg != NULL; pkg = pkg->next)
            (void) showPackage(qva, NULL, pkg->header);
-       }
-       freeSpecVec(spec);
+       spec = freeSpecVec(spec);
       }        break;
 
     case RPMQV_ALL: