Handle transaction global pool allocation centrally in rpmtsPool()
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 19 Dec 2012 10:32:52 +0000 (12:32 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 19 Dec 2012 10:47:07 +0000 (12:47 +0200)
- Previously the pool would only get allocated on successfull addition
  of install or erasure elements, causing assert() failures on
  operations on empty transaction set, which should be just a no-op,
  not an error.
- Make rpmtsPool() create the pool if it doesn't exist, update relevant
  users to call rpmtsPool() instead of directly accessing tsmem->pool,
  this avoids having to worry about pool existence in all the various cases.
- Also fix up the pool-related comment on rpmtsEmpty(): pools does not
  and can not support emptying as it could break references to its
  contents. Per-string refcount would be needed for emptying support.
(cherry picked from commit d73535e1a9dc5095e78475adc5b636d99f01efa9)

lib/depends.c
lib/rpmts.c
lib/rpmts_internal.h
lib/transaction.c

index 4cda587..6539396 100644 (file)
@@ -99,10 +99,6 @@ static int removePackage(rpmts ts, Header h, rpmte depends)
         return 0;
     }
 
-    /* Ensure our pool exists before adding elements */
-    if (tsmem->pool == NULL)
-       tsmem->pool = rpmstrPoolCreate();
-
     p = rpmteNew(ts, h, TR_REMOVED, NULL, NULL);
     if (p == NULL)
        return 1;
@@ -408,10 +404,6 @@ int rpmtsAddInstallElement(rpmts ts, Header h,
            goto exit;
     }
 
-    /* Ensure our pool exists before adding elements */
-    if (tsmem->pool == NULL)
-       tsmem->pool = rpmstrPoolCreate();
-
     p = rpmteNew(ts, h, TR_ADDED, key, relocs);
     if (p == NULL) {
        ec = 1;
@@ -445,7 +437,7 @@ int rpmtsAddInstallElement(rpmts ts, Header h,
     }
     
     if (tsmem->addedPackages == NULL) {
-       tsmem->addedPackages = rpmalCreate(tsmem->pool, 5, rpmtsFlags(ts),
+       tsmem->addedPackages = rpmalCreate(rpmtsPool(ts), 5, rpmtsFlags(ts),
                                           tscolor, rpmtsPrefColor(ts));
     }
     rpmalAdd(tsmem->addedPackages, p);
@@ -561,7 +553,7 @@ retry:
      */
     if (dsflags & RPMSENSE_RPMLIB) {
        if (tsmem->rpmlib == NULL)
-           rpmdsRpmlibPool(tsmem->pool, &(tsmem->rpmlib), NULL);
+           rpmdsRpmlibPool(rpmtsPool(ts), &(tsmem->rpmlib), NULL);
        
        if (tsmem->rpmlib != NULL && rpmdsSearch(tsmem->rpmlib, dep) >= 0) {
            rpmdsNotify(dep, "(rpmlib provides)", rc);
index 3463ce3..9642734 100644 (file)
@@ -586,7 +586,7 @@ void rpmtsEmpty(rpmts ts)
     }
 
     tsmem->orderCount = 0;
-    /* XXX emptying would be sufficient... */
+    /* The pool cannot be emptied, there might be references to its contents */
     tsmem->pool = rpmstrPoolFree(tsmem->pool);
     removedHashEmpty(tsmem->removedPackages);
     return;
@@ -934,7 +934,14 @@ tsMembers rpmtsMembers(rpmts ts)
 rpmstrPool rpmtsPool(rpmts ts)
 {
     tsMembers tsmem = rpmtsMembers(ts);
-    return (tsmem != NULL) ? tsmem->pool : NULL;
+    rpmstrPool tspool = NULL;
+
+    if (tsmem) {
+       if (tsmem->pool == NULL)
+           tsmem->pool = rpmstrPoolCreate();
+       tspool = tsmem->pool;
+    }
+    return tspool;
 }
 
 rpmts rpmtsCreate(void)
index a22c892..d4f25e1 100644 (file)
@@ -76,7 +76,7 @@ extern "C" {
 #endif
 
 /** \ingroup rpmts
- * Return transaction global string pool handle
+ * Return transaction global string pool handle, creating the pool if needed.
  * @param ts           transaction set
  * @return             string pool handle (weak ref)
  */
index 31c847e..4cd6720 100644 (file)
@@ -910,6 +910,7 @@ static
 rpmdbMatchIterator rpmFindBaseNamesInDB(rpmts ts, uint64_t fileCount)
 {
     tsMembers tsmem = rpmtsMembers(ts);
+    rpmstrPool tspool = rpmtsPool(ts);
     rpmtsi pi;  rpmte p;
     rpmfi fi;
     rpmdbMatchIterator mi;
@@ -938,8 +939,8 @@ rpmdbMatchIterator rpmFindBaseNamesInDB(rpmts ts, uint64_t fileCount)
            if (rpmStringSetHasEntry(baseNames, baseNameId))
                continue;
 
-           keylen = rpmstrPoolStrlen(tsmem->pool, baseNameId);
-           baseName = rpmstrPoolStr(tsmem->pool, baseNameId);
+           keylen = rpmstrPoolStrlen(tspool, baseNameId);
+           baseName = rpmstrPoolStr(tspool, baseNameId);
            if (keylen == 0)
                keylen++;       /* XXX "/" fixup. */
            rpmdbExtendIterator(mi, baseName, keylen);
@@ -1311,7 +1312,7 @@ static int rpmtsPrepare(rpmts ts)
     const char *dbhome = NULL;
     struct stat dbstat;
 
-    fingerPrintCache fpc = fpCacheCreate(fileCount/2 + 10001, tsmem->pool);
+    fingerPrintCache fpc = fpCacheCreate(fileCount/2 + 10001, rpmtsPool(ts));
 
     rpmlog(RPMLOG_DEBUG, "computing %" PRIu64 " file fingerprints\n", fileCount);