Change fpLookupList() to return malloced memory
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 13 Sep 2012 21:21:04 +0000 (00:21 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 14 Sep 2012 10:37:03 +0000 (13:37 +0300)
- Eliminates one place where knowledge about fingerprint internals
  has been needed, now rpmfi just gets (an supposedly) opaque blob back.

lib/fprint.c
lib/fprint.h
lib/rpmfi.c

index 037fc6a..ae5d337 100644 (file)
@@ -249,27 +249,29 @@ int fpLookupEquals(fingerPrintCache cache, fingerPrint *fp,
     return FP_EQUAL(*fp, ofp);
 }
 
-void fpLookupList(fingerPrintCache cache, rpmstrPool pool,
+fingerPrint * fpLookupList(fingerPrintCache cache, rpmstrPool pool,
                  rpmsid * dirNames, rpmsid * baseNames,
                  const uint32_t * dirIndexes, 
-                 int fileCount, fingerPrint * fpList)
+                 int fileCount)
 {
+    fingerPrint * fps = xmalloc(fileCount * sizeof(*fps));
     int i;
 
     for (i = 0; i < fileCount; i++) {
        /* If this is in the same directory as the last file, don't bother
           redoing all of this work */
        if (i > 0 && dirIndexes[i - 1] == dirIndexes[i]) {
-           fpList[i].entry = fpList[i - 1].entry;
-           fpList[i].subDir = fpList[i - 1].subDir;
-           fpList[i].baseName = rpmstrPoolStr(pool, baseNames[i]);
+           fps[i].entry = fps[i - 1].entry;
+           fps[i].subDir = fps[i - 1].subDir;
+           fps[i].baseName = rpmstrPoolStr(pool, baseNames[i]);
        } else {
            fpLookup(cache,
                     rpmstrPoolStr(pool, dirNames[dirIndexes[i]]),
                     rpmstrPoolStr(pool, baseNames[i]),
-                    1, &fpList[i]);
+                    1, &fps[i]);
        }
     }
+    return fps;
 }
 
 /* Check file for to be installed symlinks in their path and correct their fp */
index 5866df2..4fb923e 100644 (file)
@@ -123,13 +123,12 @@ int fpEqual(const fingerPrint * key1, const fingerPrint * key2);
  * @param baseNames    file base names
  * @param dirIndexes   index into dirNames for each baseNames
  * @param fileCount    number of file entries
- * @retval fpList      pointer to array of finger prints
+ * @return             pointer to array of finger prints
  */
 RPM_GNUC_INTERNAL
-void fpLookupList(fingerPrintCache cache, rpmstrPool pool,
-                 rpmsid * dirNames, rpmsid * baseNames,
-                 const uint32_t * dirIndexes, 
-                 int fileCount, fingerPrint * fpList);
+fingerPrint * fpLookupList(fingerPrintCache cache, rpmstrPool pool,
+                          rpmsid * dirNames, rpmsid * baseNames,
+                          const uint32_t * dirIndexes, int fileCount);
 
 #ifdef __cplusplus
 }
index 826b0d2..18363f1 100644 (file)
@@ -1298,9 +1298,9 @@ rpm_loff_t rpmfiFReplacedSizeIndex(rpmfi fi, int ix)
 void rpmfiFpLookup(rpmfi fi, fingerPrintCache fpc)
 {
     if (fi->fc > 0 && fi->fps == NULL) {
-       fi->fps = xcalloc(fi->fc, sizeof(*fi->fps));
+       fi->fps = fpLookupList(fpc, fi->pool,
+                              fi->dnid, fi->bnid, fi->dil, fi->fc);
     }
-    fpLookupList(fpc, fi->pool, fi->dnid, fi->bnid, fi->dil, fi->fc, fi->fps);
 }
 
 /*