From 4e20d4c49f1d623458a7fdc28214e6729c4e32d4 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 18 Dec 2009 09:04:57 +0200 Subject: [PATCH] Move transaction element iterator into rpmts.c where it logically belongs - make rpmtsi_s really opaque, move rpmtsi typedef to rpmtypes.h along with all the other commonly used types --- lib/rpmte.c | 49 --------------------------------------------- lib/rpmte.h | 27 ------------------------- lib/rpmte_internal.h | 8 -------- lib/rpmts.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/rpmts.h | 23 +++++++++++++++++++++ lib/rpmtypes.h | 2 ++ 6 files changed, 81 insertions(+), 84 deletions(-) diff --git a/lib/rpmte.c b/lib/rpmte.c index 8f0f8df..9ffe44b 100644 --- a/lib/rpmte.c +++ b/lib/rpmte.c @@ -668,55 +668,6 @@ assert (ix < Count); free(refs); } -rpmtsi rpmtsiFree(rpmtsi tsi) -{ - /* XXX watchout: a funky recursion segfaults here iff nrefs is wrong. */ - if (tsi) - tsi->ts = rpmtsFree(tsi->ts); - return _free(tsi); -} - -rpmtsi rpmtsiInit(rpmts ts) -{ - rpmtsi tsi = NULL; - - tsi = xcalloc(1, sizeof(*tsi)); - tsi->ts = rpmtsLink(ts, RPMDBG_M("rpmtsi")); - tsi->oc = 0; - return tsi; -} - -/** - * Return next transaction element. - * @param tsi transaction element iterator - * @return transaction element, NULL on termination - */ -static -rpmte rpmtsiNextElement(rpmtsi tsi) -{ - rpmte te = NULL; - int oc = -1; - - if (tsi == NULL || tsi->ts == NULL || rpmtsNElements(tsi->ts) <= 0) - return te; - - if (tsi->oc < rpmtsNElements(tsi->ts)) oc = tsi->oc++; - if (oc != -1) - te = rpmtsElement(tsi->ts, oc); - return te; -} - -rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type) -{ - rpmte te; - - while ((te = rpmtsiNextElement(tsi)) != NULL) { - if (type == 0 || (te->type & type) != 0) - break; - } - return te; -} - static Header rpmteDBHeader(rpmts ts, unsigned int rec) { Header h = NULL; diff --git a/lib/rpmte.h b/lib/rpmte.h index 5af099f..62b3f63 100644 --- a/lib/rpmte.h +++ b/lib/rpmte.h @@ -22,11 +22,6 @@ extern int _rpmte_debug; typedef struct tsortInfo_s * tsortInfo; /** \ingroup rpmte - * Transaction element iterator. - */ -typedef struct rpmtsi_s * rpmtsi; - -/** \ingroup rpmte * Transaction element type. */ typedef enum rpmElementType_e { @@ -343,28 +338,6 @@ rpmfi rpmteFI(rpmte te); */ void rpmteColorDS(rpmte te, rpmTag tag); -/** \ingroup rpmte - * Destroy transaction element iterator. - * @param tsi transaction element iterator - * @return NULL always - */ -rpmtsi rpmtsiFree(rpmtsi tsi); - -/** \ingroup rpmte - * Create transaction element iterator. - * @param ts transaction set - * @return transaction element iterator - */ -rpmtsi rpmtsiInit(rpmts ts); - -/** \ingroup rpmte - * Return next transaction element of type. - * @param tsi transaction element iterator - * @param type transaction element type selector (0 for any) - * @return next transaction element of type, NULL on termination - */ -rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type); - #ifdef __cplusplus } #endif diff --git a/lib/rpmte_internal.h b/lib/rpmte_internal.h index a513932..ed36958 100644 --- a/lib/rpmte_internal.h +++ b/lib/rpmte_internal.h @@ -58,14 +58,6 @@ struct rpmfs_s { int allocatedReplaced; }; -/** - * Iterator across transaction elements, forward on install, backward on erase. - */ -struct rpmtsi_s { - rpmts ts; /*!< transaction set. */ - int oc; /*!< iterator index. */ -}; - RPM_GNUC_INTERNAL rpmfi rpmteSetFI(rpmte te, rpmfi fi); diff --git a/lib/rpmts.c b/lib/rpmts.c index 236d34b..3808db8 100644 --- a/lib/rpmts.c +++ b/lib/rpmts.c @@ -28,6 +28,14 @@ #include "debug.h" +/** + * Iterator across transaction elements, forward on install, backward on erase. + */ +struct rpmtsi_s { + rpmts ts; /*!< transaction set. */ + int oc; /*!< iterator index. */ +}; + static void loadKeyring(rpmts ts); int _rpmts_debug = 0; @@ -939,3 +947,51 @@ rpmts rpmtsCreate(void) return rpmtsLink(ts, RPMDBG_M("tsCreate")); } +rpmtsi rpmtsiFree(rpmtsi tsi) +{ + /* XXX watchout: a funky recursion segfaults here iff nrefs is wrong. */ + if (tsi) + tsi->ts = rpmtsFree(tsi->ts); + return _free(tsi); +} + +rpmtsi rpmtsiInit(rpmts ts) +{ + rpmtsi tsi = NULL; + + tsi = xcalloc(1, sizeof(*tsi)); + tsi->ts = rpmtsLink(ts, RPMDBG_M("rpmtsi")); + tsi->oc = 0; + return tsi; +} + +/** + * Return next transaction element. + * @param tsi transaction element iterator + * @return transaction element, NULL on termination + */ +static +rpmte rpmtsiNextElement(rpmtsi tsi) +{ + rpmte te = NULL; + int oc = -1; + + if (tsi == NULL || tsi->ts == NULL || rpmtsNElements(tsi->ts) <= 0) + return te; + + if (tsi->oc < rpmtsNElements(tsi->ts)) oc = tsi->oc++; + if (oc != -1) + te = rpmtsElement(tsi->ts, oc); + return te; +} + +rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type) +{ + rpmte te; + + while ((te = rpmtsiNextElement(tsi)) != NULL) { + if (type == 0 || (rpmteType(te) & type) != 0) + break; + } + return te; +} diff --git a/lib/rpmts.h b/lib/rpmts.h index 655e2f7..e589344 100644 --- a/lib/rpmts.h +++ b/lib/rpmts.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -606,6 +607,28 @@ int rpmtsAddInstallElement(rpmts ts, Header h, */ int rpmtsAddEraseElement(rpmts ts, Header h, int dboffset); +/** \ingroup rpmte + * Destroy transaction element iterator. + * @param tsi transaction element iterator + * @return NULL always + */ +rpmtsi rpmtsiFree(rpmtsi tsi); + +/** \ingroup rpmte + * Create transaction element iterator. + * @param ts transaction set + * @return transaction element iterator + */ +rpmtsi rpmtsiInit(rpmts ts); + +/** \ingroup rpmte + * Return next transaction element of type. + * @param tsi transaction element iterator + * @param type transaction element type selector (0 for any) + * @return next transaction element of type, NULL on termination + */ +rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type); + #ifdef __cplusplus } #endif diff --git a/lib/rpmtypes.h b/lib/rpmtypes.h index 99a28e2..07533f7 100644 --- a/lib/rpmtypes.h +++ b/lib/rpmtypes.h @@ -62,6 +62,8 @@ typedef struct rpmds_s * rpmds; typedef struct rpmfi_s * rpmfi; typedef struct rpmdb_s * rpmdb; typedef struct rpmdbMatchIterator_s * rpmdbMatchIterator; +typedef struct rpmtsi_s * rpmtsi; + typedef const void * fnpyKey; typedef void * rpmCallbackData; /** @} */ -- 2.7.4