]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcpat.c
Add *NeededBytesAlign(), which overestimates the padding which is later
[fontconfig.git] / src / fcpat.c
index 4dc5e4b7bc15843e8d9c5d37012bae1258d2b2dc..bb922fef3914059dc53698ccd851a305b83a426e 100644 (file)
@@ -309,7 +309,7 @@ FcPatternDestroy (FcPattern *p)
 
     if (FcPatternFindFullFname (p))
     {
-       FcStrFree (FcPatternFindFullFname (p));
+       FcStrFree ((FcChar8 *)FcPatternFindFullFname (p));
        FcPatternAddFullFname (p, 0);
     }
 
@@ -1276,14 +1276,8 @@ FcPatternDuplicate (const FcPattern *orig)
                                FcValueCanonicalize(&FcValueListPtrU(l)->value),
                               FcTrue))
                goto bail1;
-
-       if (!strcmp ((char *)FcObjectPtrU((e + i)->object), FC_FILE))
-       {
-           FcChar8 * s;
-           FcPatternGetString (orig, FC_FILE, 0, &s);
-           FcPatternAddFullFname (new, FcPatternFindFullFname(orig));
-       }
     }
+    FcPatternTransferFullFname (new, orig);
 
     return new;
 
@@ -1436,6 +1430,8 @@ static void
 FcStrNewBank (void);
 static int
 FcStrNeededBytes (const FcChar8 * s);
+static int
+FcStrNeededBytesAlign (void);
 static void *
 FcStrDistributeBytes (FcCache * metadata, void * block_ptr);
 static const FcChar8 *
@@ -1447,6 +1443,8 @@ static void
 FcValueListNewBank (void);
 static int
 FcValueListNeededBytes (FcValueList * vl);
+static int
+FcValueListNeededBytesAlign (void);
 static void *
 FcValueListDistributeBytes (FcCache * metadata, void *block_ptr);
 static FcValueListPtr
@@ -1485,6 +1483,13 @@ FcPatternNeededBytes (FcPattern * p)
     return cum + sizeof (FcPattern) + sizeof(FcPatternElt)*p->num;
 }
 
+int
+FcPatternNeededBytesAlign (void)
+{
+    return __alignof__ (FcPattern) + __alignof__ (FcPatternElt) + 
+       FcValueListNeededBytesAlign ();
+}
+
 static FcBool
 FcPatternEnsureBank (int bi)
 {
@@ -1531,12 +1536,14 @@ FcPatternDistributeBytes (FcCache * metadata, void * block_ptr)
        return 0;
 
     fcpattern_ptr = 0;
+    block_ptr = ALIGN(block_ptr, FcPattern);
     fcpatterns[bi] = (FcPattern *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
                         (sizeof (FcPattern) * fcpattern_count));
     
     FcMemAlloc (FC_MEM_PATELT, sizeof (FcPatternElt) * fcpatternelt_count);
     fcpatternelt_ptr = 0;
+    block_ptr = ALIGN(block_ptr, FcPatternElt);
     fcpatternelts[bi] = (FcPatternElt *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
                         (sizeof (FcPatternElt) * fcpatternelt_count));
@@ -1609,12 +1616,14 @@ FcPatternUnserialize (FcCache metadata, void *block_ptr)
        return FcFalse;
 
     FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern) * metadata.pattern_count);
+    block_ptr = ALIGN(block_ptr, FcPattern);
     fcpatterns[bi] = (FcPattern *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
                         (sizeof (FcPattern) * metadata.pattern_count));
     
     FcMemAlloc (FC_MEM_PATELT, 
                sizeof (FcPatternElt) * metadata.patternelt_count);
+    block_ptr = ALIGN(block_ptr, FcPatternElt);
     fcpatternelts[bi] = (FcPatternElt *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
                         (sizeof (FcPatternElt) * metadata.patternelt_count));
@@ -1666,6 +1675,13 @@ FcValueListNeededBytes (FcValueList *p)
     return cum;
 }
 
+static int
+FcValueListNeededBytesAlign (void)
+{
+    return FcCharSetNeededBytesAlign() + FcLangSetNeededBytesAlign() + 
+       FcStrNeededBytesAlign() + __alignof__ (FcValueList);
+}
+
 static FcBool
 FcValueListEnsureBank (int bi)
 {
@@ -1700,6 +1716,7 @@ FcValueListDistributeBytes (FcCache * metadata, void *block_ptr)
 
     FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList) * fcvaluelist_count);
     fcvaluelist_ptr = 0;
+    block_ptr = ALIGN(block_ptr, FcValueList);
     fcvaluelists[bi] = (FcValueList *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
                         (sizeof (FcValueList) * fcvaluelist_count));
@@ -1780,6 +1797,7 @@ FcValueListUnserialize (FcCache metadata, void *block_ptr)
 
     FcMemAlloc (FC_MEM_VALLIST, 
                sizeof (FcValueList) * metadata.valuelist_count);
+    block_ptr = ALIGN(block_ptr, FcValueList);
     fcvaluelists[bi] = (FcValueList *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
                         (sizeof (FcValueList) * metadata.valuelist_count));
@@ -1856,6 +1874,11 @@ FcStrNeededBytes (const FcChar8 * s)
     b->next = 0;
     b->hash = hash;
     strcpy ((char *) (b + 1), (char *)s);
+
+    /* Yes, the following line is convoluted.  However, it is
+     * incorrect to replace the with a memset, because the C
+     * specification doesn't guarantee that the null pointer is
+     * the same as the zero bit pattern. */
     *(char **)((char *) (b + 1) + strlen((char *)s) + 1) = 0;
     *p = b;
 
@@ -1863,6 +1886,12 @@ FcStrNeededBytes (const FcChar8 * s)
     return strlen((char *)s) + 1;
 }
 
+static int
+FcStrNeededBytesAlign (void)
+{
+    return __alignof__ (char);
+}
+
 static FcBool
 FcStrEnsureBank (int bi)
 {
@@ -1893,6 +1922,7 @@ FcStrDistributeBytes (FcCache * metadata, void * block_ptr)
        return 0;
 
     FcMemAlloc (FC_MEM_STRING, sizeof (char) * fcstr_count);
+    block_ptr = ALIGN (block_ptr, FcChar8);
     static_strs[bi] = (FcChar8 *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + (sizeof (char) * fcstr_count));
     metadata->str_count = fcstr_count;
@@ -2003,5 +2033,7 @@ FcPatternTransferFullFname (const FcPattern *new, const FcPattern *orig)
 {
     FcChar8 * s;
     FcPatternGetString (orig, FC_FILE, 0, &s);
-    FcPatternAddFullFname (new, FcStrCopy (FcPatternFindFullFname(orig)));
+    FcPatternAddFullFname (new, 
+                          (char *)FcStrCopy 
+                          ((FcChar8 *)FcPatternFindFullFname(orig)));
 }