Bury ordering structures and their alloc+free inside order.c
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 21 Dec 2009 07:20:09 +0000 (09:20 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 21 Dec 2009 07:20:09 +0000 (09:20 +0200)
- nothing outside order.c needs this stuff, TSI alloc+free routines
  have no business being exported
- for now we need to store a pointer to tsortInfo in the elements,
  its just an opaque pointer for ping-ponging the data through ts elements
- all allocation + freeing is local to ordering code

lib/order.c
lib/rpmte.c
lib/rpmte.h
lib/rpmte_internal.h

index 1b1c73e..8f24fb1 100644 (file)
@@ -30,6 +30,30 @@ struct scc_s {
 
 typedef struct scc_s * scc;
 
+struct relation_s {
+    rpmte   rel_suc;  // pkg requiring this package
+    rpmsenseFlags rel_flags; // accumulated flags of the requirements
+    struct relation_s * rel_next;
+};
+
+typedef struct relation_s * relation;
+
+struct tsortInfo_s {
+    int degree;                        /*!< No. of immediate children. */
+    int npreds;                        /*!< No. of predecessors. */
+    int tree;                  /*!< Tree index. */
+    int depth;                 /*!< Depth in dependency tree. */
+    int             tsi_count;     // #pkgs this pkg requires
+    int             tsi_qcnt;      // #pkgs requiring this package
+    int             tsi_reqx;       // requires Idx/mark as (queued/loop)
+    struct relation_s * tsi_relations;
+    struct relation_s * tsi_forward_relations;
+    rpmte    tsi_suc;        // used for queuing (addQ)
+    int      tsi_SccIdx;     // # of the SCC the node belongs to
+                             // (1 for trivial SCCs)
+    int      tsi_SccLowlink; // used for SCC detection
+};
+
 struct badDeps_s {
     char * pname;
     const char * qname;
@@ -107,6 +131,23 @@ static int ignoreDep(const rpmts ts, const rpmte p, const rpmte q)
     return 0;
 }
 
+static void rpmTSIFree(tsortInfo tsi)
+{
+    relation rel;
+
+    while (tsi->tsi_relations != NULL) {
+       rel = tsi->tsi_relations;
+       tsi->tsi_relations = tsi->tsi_relations->rel_next;
+       rel = _free(rel);
+    }
+    while (tsi->tsi_forward_relations != NULL) {
+       rel = tsi->tsi_forward_relations;
+       tsi->tsi_forward_relations = \
+           tsi->tsi_forward_relations->rel_next;
+       rel = _free(rel);
+    }
+}
+
 /**
  * Record next "q <- p" relation (i.e. "p" requires "q").
  * @param ts           transaction set
@@ -564,6 +605,8 @@ int rpmtsOrder(rpmts ts)
     int rc;
     rpmal erasedPackages = rpmalCreate(5, rpmtsColor(ts), prefcolor);
     scc SCCs;
+    int nelem = rpmtsNElements(ts);
+    tsortInfo sortInfo = xcalloc(nelem, sizeof(struct tsortInfo_s));
 
     (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_ORDER), 0);
 
@@ -581,10 +624,9 @@ int rpmtsOrder(rpmts ts)
     pi = rpmtsiFree(pi);
     rpmalMakeIndex(erasedPackages);
 
-    pi = rpmtsiInit(ts);
-    while ((p = rpmtsiNext(pi, 0)) != NULL)
-       rpmteNewTSI(p);
-    pi = rpmtsiFree(pi);
+    for (int i = 0; i < nelem; i++) {
+       rpmteSetTSI(ts->order[i], &sortInfo[i]);
+    }
 
     /* Record relations. */
     rpmlog(RPMLOG_DEBUG, "========== recording tsort relations\n");
@@ -661,10 +703,11 @@ int rpmtsOrder(rpmts ts)
     }
 
     /* Clean up tsort data */
-    pi = rpmtsiInit(ts);
-    while ((p = rpmtsiNext(pi, 0)) != NULL)
-       rpmteFreeTSI(p);
-    pi = rpmtsiFree(pi);
+    for (int i = 0; i < nelem; i++) {
+       rpmteSetTSI(ts->order[i], NULL);
+       rpmTSIFree(&sortInfo[i]);
+    }
+    free(sortInfo);
 
     assert(newOrderCount == ts->orderCount);
 
index 9f44d6e..b09556c 100644 (file)
@@ -421,32 +421,9 @@ tsortInfo rpmteTSI(rpmte te)
     return te->tsi;
 }
 
-void rpmteFreeTSI(rpmte te)
+void rpmteSetTSI(rpmte te, tsortInfo tsi)
 {
-    relation rel;
-    if (te == NULL || rpmteTSI(te) == NULL) return;
-
-    while (te->tsi->tsi_relations != NULL) {
-       rel = te->tsi->tsi_relations;
-       te->tsi->tsi_relations = te->tsi->tsi_relations->rel_next;
-       rel = _free(rel);
-    }
-    while (te->tsi->tsi_forward_relations != NULL) {
-       rel = te->tsi->tsi_forward_relations;
-       te->tsi->tsi_forward_relations = \
-           te->tsi->tsi_forward_relations->rel_next;
-       rel = _free(rel);
-    }
-    te->tsi = _free(te->tsi);
-}
-
-void rpmteNewTSI(rpmte te)
-{
-    if (te != NULL) {
-       rpmteFreeTSI(te);
-       te->tsi = xcalloc(1, sizeof(*te->tsi));
-       memset(te->tsi, 0, sizeof(*te->tsi));
-    }
+    te->tsi = tsi;
 }
 
 void rpmteSetDependsOn(rpmte te, rpmte depends) {
index f1edfe4..905b311 100644 (file)
@@ -176,25 +176,6 @@ rpmte rpmteParent(rpmte te);
 rpmte rpmteSetParent(rpmte te, rpmte pte);
 
 /** \ingroup rpmte
- * Retrieve tsort info for transaction element.
- * @param te           transaction element
- * @return             tsort info
- */
-tsortInfo rpmteTSI(rpmte te);
-
-/** \ingroup rpmte
- * Destroy tsort info of transaction element.
- * @param te           transaction element
- */
-void rpmteFreeTSI(rpmte te);
-
-/** \ingroup rpmte
- * Initialize tsort info of transaction element.
- * @param te           transaction element
- */
-void rpmteNewTSI(rpmte te);
-
-/** \ingroup rpmte
  * Destroy dependency set info of transaction element.
  * @param te           transaction element
  */
index 0d0774d..357eead 100644 (file)
@@ -8,30 +8,6 @@
  * Dependncy ordering information.
  */
 
-struct relation_s {
-    rpmte   rel_suc;  // pkg requiring this package
-    rpmsenseFlags rel_flags; // accumulated flags of the requirements
-    struct relation_s * rel_next;
-};
-
-typedef struct relation_s * relation;
-
-struct tsortInfo_s {
-    int degree;                        /*!< No. of immediate children. */
-    int npreds;                        /*!< No. of predecessors. */
-    int tree;                  /*!< Tree index. */
-    int depth;                 /*!< Depth in dependency tree. */
-    int             tsi_count;     // #pkgs this pkg requires
-    int             tsi_qcnt;      // #pkgs requiring this package
-    int             tsi_reqx;       // requires Idx/mark as (queued/loop)
-    struct relation_s * tsi_relations;
-    struct relation_s * tsi_forward_relations;
-    rpmte    tsi_suc;        // used for queuing (addQ)
-    int      tsi_SccIdx;     // # of the SCC the node belongs to
-                             // (1 for trivial SCCs)
-    int      tsi_SccLowlink; // used for SCC detection
-};
-
 /**
  */
 typedef struct sharedFileInfo_s *              sharedFileInfo;
@@ -86,6 +62,12 @@ int rpmteHaveTransScript(rpmte te, rpmTag tag);
 RPM_GNUC_INTERNAL
 rpmps rpmteProblems(rpmte te);
 
+RPM_GNUC_INTERNAL
+tsortInfo rpmteTSI(rpmte te);
+
+RPM_GNUC_INTERNAL
+void rpmteSetTSI(rpmte te, tsortInfo tsi);
+
 //RPM_GNUC_INTERNAL
 rpmfs rpmteGetFileStates(rpmte te);