Add an alternative rpmfi constructor to allow shared pool usage
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 7 Sep 2012 12:48:45 +0000 (15:48 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 7 Sep 2012 12:48:45 +0000 (15:48 +0300)
- rpmfiNewPool() allows specifying shared/private pool, and
  rpmfiNew() is now just a wrapper to always call it with a private pool.

lib/rpmfi.c
lib/rpmfi.h

index 1a8a79c..6786121 100644 (file)
@@ -1084,7 +1084,7 @@ static rpmsid * tag2pool(rpmstrPool pool, Header h, rpmTag tag)
     if (headerGet((_h), (_tag), (_td), (_flags))) \
        _data = (td.data)
 
-rpmfi rpmfiNew(const rpmts ts, Header h, rpmTagVal tagN, rpmfiFlags flags)
+rpmfi rpmfiNewPool(rpmstrPool pool, Header h, rpmTagVal tagN, rpmfiFlags flags)
 {
     rpmfi fi = xcalloc(1, sizeof(*fi)); 
     unsigned char * t;
@@ -1121,7 +1121,8 @@ rpmfi rpmfiNew(const rpmts ts, Header h, rpmTagVal tagN, rpmfiFlags flags)
     /* XXX: ensure the global misc. pool exists */
     if (miscpool == NULL)
        miscpool = rpmstrPoolCreate();
-    fi->pool = rpmstrPoolCreate();
+    /* private or shared pool? */
+    fi->pool = (pool != NULL) ? rpmstrPoolLink(pool) : rpmstrPoolCreate();
 
     /* XXX TODO: all these should be sanity checked, ugh... */
     if (!(flags & RPMFI_NOFILEMODES))
@@ -1206,7 +1207,9 @@ rpmfi rpmfiNew(const rpmts ts, Header h, rpmTagVal tagN, rpmfiFlags flags)
     /* lazily alloced from rpmfiFN() */
     fi->fn = NULL;
 
-    rpmstrPoolFreeze(fi->pool);
+    /* only freeze private pool */
+    if (fi->pool != pool)
+       rpmstrPoolFreeze(fi->pool);
 
 exit:
 
@@ -1222,6 +1225,11 @@ errxit:
     return NULL;
 }
 
+rpmfi rpmfiNew(const rpmts ts, Header h, rpmTagVal tagN, rpmfiFlags flags)
+{
+    return rpmfiNewPool(NULL, h, tagN, flags);
+}
+
 void rpmfiSetFReplacedSizeIndex(rpmfi fi, int ix, rpm_loff_t newsize)
 {
     if (fi != NULL && ix >= 0 && ix < fi->fc) {
index c526c90..17a14bf 100644 (file)
@@ -421,6 +421,16 @@ typedef rpmFlags rpmfiFlags;
 rpmfi rpmfiNew(const rpmts ts, Header h, rpmTagVal tagN, rpmfiFlags flags);
 
 /** \ingroup rpmfi
+ * Create and load a file info set.
+ * @param pool         shared string pool (or NULL for private pool)
+ * @param h            header
+ * @param tagN         unused
+ * @param flags                Flags to control what information is loaded.
+ * @return             new file info set
+ */
+rpmfi rpmfiNewPool(rpmstrPool pool, Header h, rpmTagVal tagN, rpmfiFlags flags);
+
+/** \ingroup rpmfi
  * Return file type from mode_t.
  * @param mode         file mode bits (from header)
  * @return             file type