From e93a77c9b792b68c63ce7d3d360ab7f43d37feb6 Mon Sep 17 00:00:00 2001 From: jbj Date: Mon, 18 Oct 2004 01:08:56 +0000 Subject: [PATCH] Add generalized iterator to rpmlib. CVS patchset: 7482 CVS date: 2004/10/18 01:08:56 --- lib/Makefile.am | 6 +++--- lib/depends.c | 2 ++ lib/manifest.c | 17 ++++++++------- lib/manifest.h | 9 ++++---- lib/package.c | 2 ++ lib/rpmcli.h | 2 ++ lib/rpmgi.c | 55 +++++++++++++++++++++++++++++++++++++------------ lib/rpmgi.h | 32 ++++++++++++++-------------- lib/rpmlib.h | 5 +++++ lib/rpmts.h | 2 +- rpmdb/rpmdb.c | 2 +- 11 files changed, 88 insertions(+), 46 deletions(-) diff --git a/lib/Makefile.am b/lib/Makefile.am index 381eaea58..aeaa80374 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -20,7 +20,7 @@ EXTRA_PROGRAMS = tgi pkgincdir = $(pkgincludedir) pkginc_HEADERS = \ misc.h rpmcli.h rpmlib.h \ - rpmal.h rpmds.h rpmfi.h rpmps.h rpmsx.h rpmte.h rpmts.h \ + rpmal.h rpmds.h rpmfi.h rpmgi.h rpmps.h rpmsx.h rpmte.h rpmts.h \ stringbuf.h noinst_HEADERS = \ cpio.h fsm.h manifest.h psm.h rpmlead.h signature.h rpmlock.h @@ -36,7 +36,7 @@ librpm_la_SOURCES = \ cpio.c depends.c formats.c fs.c fsm.c getdate.c \ manifest.c misc.c package.c \ poptALL.c poptI.c poptQV.c psm.c query.c \ - rpmal.c rpmchecksig.c rpmds.c rpmfi.c rpminstall.c \ + rpmal.c rpmchecksig.c rpmds.c rpmfi.c rpmgi.c rpminstall.c \ rpmlead.c rpmlibprov.c rpmps.c rpmrc.c rpmsx.c rpmte.c rpmts.c \ rpmvercmp.c signature.c stringbuf.c transaction.c \ verify.c rpmlock.c @@ -123,5 +123,5 @@ tplatform: tplatform.o librpm.la trhn: trhn.o librpm.la $(LINK) @LDFLAGS_STATIC@ $(CFLAGS) $(DEFS) $(INCLUDES) -o $@ $< $(mylibs) -tgi_SOURCES = tgi.c rpmgi.c +tgi_SOURCES = tgi.c tgi_LDADD = librpm.la diff --git a/lib/depends.c b/lib/depends.c index b747ba650..e9e80fcc0 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -316,8 +316,10 @@ int rpmtsAddInstallElement(rpmts ts, Header h, if (rpmVersionCompare(h, oh)) #endif xx = removePackage(ts, oh, rpmdbGetIteratorOffset(mi), pkgKey); +/*@-nullptrarith@*/ rpmMessage(RPMMESS_DEBUG, _(" Obsoletes: %s\t\terases %s\n"), rpmdsDNEVR(obsoletes)+2, ohNEVRA); +/*@=nullptrarith@*/ ohNEVRA = _free(ohNEVRA); } } diff --git a/lib/manifest.c b/lib/manifest.c index 16795d7bd..0374516c5 100644 --- a/lib/manifest.c +++ b/lib/manifest.c @@ -6,6 +6,7 @@ #include #include +#include #include "stringbuf.h" #include "manifest.h" @@ -65,7 +66,7 @@ char * rpmPermsString(int mode) /**@todo Infinite loops through manifest files exist, operator error for now. */ /*@-boundsread@*/ -int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr) +rpmRC rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr) { StringBuf sb = newStringBuf(); char * s = NULL; @@ -77,7 +78,7 @@ int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr) /*@+voidabstract@*/ FILE * f = (FILE *) fdGetFp(fd); /*@=voidabstract@*/ - int rc = 0; + rpmRC rpmrc = RPMRC_OK; int i; /*@-boundswrite@*/ @@ -105,7 +106,7 @@ int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr) /* Insure that file contains only ASCII */ if (*s < 32) { - rc = 1; + rpmrc = RPMRC_NOTFOUND; goto exit; } @@ -121,13 +122,13 @@ int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr) /*@=branchstate@*/ if (!(s && *s)) { - rc = 1; + rpmrc = RPMRC_NOTFOUND; goto exit; } /* Glob manifest items. */ - rc = rpmGlob(s, &ac, &av); - if (rc) goto exit; + rpmrc = rpmGlob(s, &ac, &av); + if (rpmrc != RPMRC_OK) goto exit; /* Find 1st existing unprocessed arg. */ for (i = 0; i < argc; i++) @@ -162,7 +163,7 @@ int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr) exit: /*@-branchstate@*/ - if (argvPtr == NULL || (rc != 0 && av)) { + if (argvPtr == NULL || (rpmrc != RPMRC_OK && av)) { if (av) /*@-boundswrite@*/ for (i = 0; i < ac; i++) @@ -173,7 +174,7 @@ exit: /*@=branchstate@*/ sb = freeStringBuf(sb); /*@-nullstate@*/ /* FIX: *argvPtr may be NULL. */ - return rc; + return rpmrc; /*@=nullstate@*/ } /*@=boundsread@*/ diff --git a/lib/manifest.h b/lib/manifest.h index 8081479d8..6a331ee67 100644 --- a/lib/manifest.h +++ b/lib/manifest.h @@ -24,11 +24,12 @@ char * rpmPermsString(int mode) /** * Read manifest, glob items, and append to existing args. - * @param fd manifest file handle - * @retval argcPtr no. of args - * @retval argvPtr args themselves + * @param fd manifest file handle + * @retval argcPtr no. of args + * @retval argvPtr args themselves + * @return RPMRC_OK on success */ -int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr) +rpmRC rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr) /*@globals fileSystem, internalState @*/ /*@modifies fd, *argcPtr, *argvPtr, fileSystem, internalState @*/; diff --git a/lib/package.c b/lib/package.c index 9e0f70719..e2b9720d1 100644 --- a/lib/package.c +++ b/lib/package.c @@ -868,9 +868,11 @@ rpmRC rpmReadPackageFile(rpmts ts, FD_t fd, const char * fn, Header * hdrp) /* XXX repackaged packages have appended tags, legacy dig/sig check fails */ if (opx > 0) (void) rpmswEnter(rpmtsOp(ts, opx), 0); +/*@-type@*/ /* XXX arrow access of non-pointer (FDSTAT_t) */ nb = -fd->stats->ops[FDSTAT_READ].bytes; rc = rpmReadHeader(ts, fd, &h, &msg); nb += fd->stats->ops[FDSTAT_READ].bytes; +/*@=type@*/ if (opx > 0) (void) rpmswExit(rpmtsOp(ts, opx), nb); diff --git a/lib/rpmcli.h b/lib/rpmcli.h index 1b32710fa..d5907137f 100644 --- a/lib/rpmcli.h +++ b/lib/rpmcli.h @@ -258,6 +258,8 @@ struct rpmQVKArguments_s { rpmfileAttrs qva_fflags; /*!< Bit(s) to filter on attribute. */ /*@only@*/ /*@null@*/ rpmdbMatchIterator qva_mi; /*!< Match iterator on selected headers. */ +/*@refccounted@*/ /*@null@*/ + rpmdbMatchIterator qva_gi; /*!< Generalized iterator on selected headers. */ /*@null@*/ QVF_t qva_showPackage; /*!< Function to display iterator matches. */ /*@null@*/ diff --git a/lib/rpmgi.c b/lib/rpmgi.c index 1384f175f..1c151d115 100644 --- a/lib/rpmgi.c +++ b/lib/rpmgi.c @@ -12,9 +12,12 @@ #include "debug.h" +/*@access rpmdbMatchIterator @*/ + /*@unchecked@*/ int _rpmgi_debug = 0; +/*@unchecked@*/ /*@observer@*/ static const char * hdlistpath = "/usr/share/comps/i386/hdlist"; rpmgi XrpmgiUnlink(rpmgi gi, const char * msg, const char * fn, unsigned ln) @@ -52,6 +55,7 @@ fprintf(stderr, "*** gi %p\t%p[%d]\n", gi, gi->argv, gi->argc); (void) rpmgiUnlink(gi, NULL); +/*@-usereleased@*/ switch (gi->tag) { default: case RPMGI_RPMDB: @@ -80,7 +84,10 @@ fprintf(stderr, "*** gi %p\t%p[%d]\n", gi, gi->argv, gi->argc); gi->ts = rpmtsFree(gi->ts); memset(gi, 0, sizeof(*gi)); /* XXX trash and burn */ +/*@-refcounttrans@*/ gi = _free(gi); +/*@=refcounttrans@*/ +/*@=usereleased@*/ return NULL; } @@ -94,6 +101,9 @@ rpmgi rpmgiNew(rpmts ts, int tag, void *const keyp, size_t keylen) gi->ts = rpmtsLink(ts, NULL); gi->tag = tag; gi->i = -1; + gi->fd = NULL; + gi->argv = NULL; + gi->argc = 0; switch (gi->tag) { default: @@ -109,7 +119,7 @@ fprintf(stderr, "*** gi %p\t%p\n", gi, gi->mi); break; case RPMGI_ARGLIST: case RPMGI_FTSWALK: - { ARGV_t pav = keyp; + { ARGV_t pav = keyp; const char * arg; unsigned flags = keylen; int xx; @@ -139,8 +149,10 @@ fprintf(stderr, "*** gi %p\t%p[%d]\n", gi, gi->argv, gi->argc); return gi; } +/*@unchecked@*/ static int indent = 2; +/*@unchecked@*/ /*@observer@*/ static const char * ftsInfoStrings[] = { "UNKNOWN", "D", @@ -159,16 +171,22 @@ static const char * ftsInfoStrings[] = { "W", }; -static const char * ftsInfoStr(int fts_info) { +/*@observer@*/ +static const char * ftsInfoStr(int fts_info) + /*@*/ +{ + if (!(fts_info >= 1 && fts_info <= 14)) fts_info = 0; +/*@-compmempass@*/ return ftsInfoStrings[ fts_info ]; +/*@=compmempass@*/ } /*@only@*/ -static const char * rpmgiPathOrQF(rpmgi gi, const char * fn, +static const char * rpmgiPathOrQF(const rpmgi gi, const char * fn, /*@null@*/ Header * hdrp) - /*@modifies gi, *hdrp @*/ + /*@modifies *hdrp @*/ { const char * fmt = ((gi->queryFormat != NULL) ? gi->queryFormat : "%{name}-%{version}-%{release}"); @@ -189,8 +207,9 @@ static const char * rpmgiPathOrQF(rpmgi gi, const char * fn, } /*@null@*/ -static rpmRC rpmgiReadManifest(rpmgi gi, const char * fileURL) - /*@*/ +static rpmRC rpmgiLoadManifest(rpmgi gi, const char * fileURL) + /*@globals h_errno, internalState @*/ + /*@modifies gi, h_errno, internalState @*/ { rpmRC rpmrc; FD_t fd; @@ -212,7 +231,8 @@ static rpmRC rpmgiReadManifest(rpmgi gi, const char * fileURL) /*@null@*/ static Header rpmgiReadHeader(rpmgi gi, const char * fileURL) - /*@*/ + /*@globals rpmGlobalMacroContext, h_errno, internalState @*/ + /*@modifies gi, rpmGlobalMacroContext, h_errno, internalState @*/ { Header h = NULL; rpmRC rpmrc; @@ -247,7 +267,6 @@ static Header rpmgiReadHeader(rpmgi gi, const char * fileURL) } const char * rpmgiNext(/*@null@*/ rpmgi gi) - /*@modifies gi @*/ { const char * val = NULL; const char * fn = NULL; @@ -259,15 +278,18 @@ const char * rpmgiNext(/*@null@*/ rpmgi gi) default: case RPMGI_RPMDB: h = rpmdbNextIterator(gi->mi); +/*@-branchstate@*/ if (h != NULL) { val = rpmgiPathOrQF(gi, "rpmdb", &h); } else { gi->mi = rpmdbFreeIterator(gi->mi); gi->i = -1; } +/*@=branchstate@*/ break; case RPMGI_HDLIST: h = headerRead(gi->fd, HEADER_MAGIC_YES); +/*@-branchstate@*/ if (h != NULL) { val = rpmgiPathOrQF(gi, "hdlist", &h); } else { @@ -275,8 +297,10 @@ const char * rpmgiNext(/*@null@*/ rpmgi gi) gi->fd = NULL; gi->i = -1; } +/*@=branchstate@*/ break; case RPMGI_ARGLIST: +/*@-branchstate@*/ if (gi->argv != NULL && gi->argv[gi->i] != NULL) { if (_rpmgi_debug < 0) fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->argv, gi->i, gi->argv[gi->i]); @@ -285,21 +309,24 @@ fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->argv, gi->i, gi->argv[gi->i]) fn = gi->argv[gi->i]; h = rpmgiReadHeader(gi, fn); if (h != NULL) - break; + /*@loopbreak@*/ break; /* Not a header, so try for a manifest. */ gi->argv[gi->i] = NULL; - rpmrc = rpmgiReadManifest(gi, fn); + rpmrc = rpmgiLoadManifest(gi, fn); if (rpmrc != RPMRC_OK) { gi->argv[gi->i] = fn; - break; + /*@loopbreak@*/ break; } fn = _free(fn); } while (1); /* XXX check rpmrc */ +/*@-compdef@*/ /* XXX WTF? gi->argv undefined */ val = rpmgiPathOrQF(gi, fn, &h); +/*@=compdef@*/ h = headerFree(h); } else gi->i = -1; +/*@=branchstate@*/ break; case RPMGI_FTSWALK: if (gi->argv == NULL) @@ -318,6 +345,7 @@ fprintf(stderr, "FTS_%s\t%*s %s\n", ftsInfoStr(fts->fts_info), indent * (fts->fts_level < 0 ? 0 : fts->fts_level), "", fts->fts_name); +/*@-branchstate@*/ switch (fts->fts_info) { case FTS_F: case FTS_SL: @@ -327,10 +355,11 @@ fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->ftsp, gi->i, fts->fts_path); h = rpmgiReadHeader(gi, fn); val = rpmgiPathOrQF(gi, fn, &h); h = headerFree(h); - break; + /*@switchbreak@*/ break; default: - break; + /*@switchbreak@*/ break; } +/*@=branchstate@*/ } if (gi->fts == NULL && gi->ftsp != NULL) { int xx; diff --git a/lib/rpmgi.h b/lib/rpmgi.h index 61b3b819c..1d4f864c1 100644 --- a/lib/rpmgi.h +++ b/lib/rpmgi.h @@ -17,10 +17,6 @@ extern int _rpmgi_debug; /*@=exportlocal@*/ -/** - */ -typedef /*@abstract@*/ struct rpmgi_s * rpmgi; - /** */ typedef enum rpmgiTag_e { @@ -38,23 +34,19 @@ struct rpmgi_s { rpmts ts; int tag; int i; + const char * queryFormat; -/*@dependent@*/ +/*@relnull@*/ rpmdbMatchIterator mi; /*@refcounted@*/ FD_t fd; -/*@only@*/ - const char * queryFormat; - -/*@dependent@*/ ARGV_t argv; int argc; + int ftsOpts; -/*@dependent@*/ FTS * ftsp; -/*@dependent@*/ FTSENT * fts; /*@refs@*/ @@ -107,21 +99,29 @@ rpmgi XrpmgiLink (/*@null@*/ rpmgi gi, /*@null@*/ const char * msg, * @param gi generalized iterator * @return NULL always */ -/*@only@*/ +/*@null@*/ rpmgi rpmgiFree(/*@killref@*/ /*@only@*/ /*@null@*/ rpmgi gi) - /*@modifies gi @*/; + /*@globals rpmGlobalMacroContext, h_errno, internalState @*/ + /*@modifies gi, rpmGlobalMacroContext, h_errno, internalState @*/; /** Create a generalized iterator. * @param argv iterator argv array * @param flags iterator flags * @return new general iterator */ -/*@only@*/ +/*@null@*/ rpmgi rpmgiNew(rpmts ts, int tag, void *const keyp, size_t keylen) - /*@*/; + /*@globals rpmGlobalMacroContext, h_errno, internalState @*/ + /*@modifies ts, rpmGlobalMacroContext, h_errno, internalState @*/; +/** Return next iteration element. + * @param gi generalized iterator + * @returns next element + */ +/*@observer@*/ const char * rpmgiNext(/*@null@*/ rpmgi gi) - /*@modifies gi @*/; + /*@globals rpmGlobalMacroContext, h_errno, internalState @*/ + /*@modifies gi, rpmGlobalMacroContext, h_errno, internalState @*/; int rpmgiSetQueryFormat(rpmgi gi, const char * queryFormat) /*@modifies gi @*/; diff --git a/lib/rpmlib.h b/lib/rpmlib.h index d543429b9..c9bf0beb9 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -112,6 +112,11 @@ typedef /*@abstract@*/ /*@refcounted@*/ struct rpmdb_s * rpmdb; */ typedef /*@abstract@*/ struct _rpmdbMatchIterator * rpmdbMatchIterator; +/** \ingroup rpmcli + * Generalized iterator. + */ +typedef /*@abstract@*/ /*@refcounted@*/ struct rpmgi_s * rpmgi; + /** \ingroup header * Return name, version, release strings from header. * @param h header diff --git a/lib/rpmts.h b/lib/rpmts.h index cc11e73c1..f1cf55c9e 100644 --- a/lib/rpmts.h +++ b/lib/rpmts.h @@ -993,7 +993,7 @@ uint_32 rpmtsSetColor(rpmts ts, uint_32 color) * @param opx operation timestamp index * @return pointer to operation timestamp. */ -/*@null@*/ +/*@relnull@*/ rpmop rpmtsOp(rpmts ts, rpmtsOpX opx) /*@*/; diff --git a/rpmdb/rpmdb.c b/rpmdb/rpmdb.c index 0591d24f6..672c43c66 100644 --- a/rpmdb/rpmdb.c +++ b/rpmdb/rpmdb.c @@ -699,7 +699,7 @@ int rpmdbCheckSignals(void) rpmdb db; rpmdbMatchIterator mi; - rpmMessage(RPMMESS_NORMAL, "Exiting on signal(0x%lx) ...\n", *((unsigned long *)&rpmsqCaught)); + rpmMessage(RPMMESS_DEBUG, "Exiting on signal(0x%lx) ...\n", *((unsigned long *)&rpmsqCaught)); /*@-branchstate@*/ while ((mi = rpmmiRock) != NULL) {