]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcpat.c
Fix up fc-cache and fc-cat for no global cache changes.
[fontconfig.git] / src / fcpat.c
index ad6afc0065b0e6bb27061bc444ad58410f82be40..da1d4905539ceddf325d3b6495e863b5e81b9d7f 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "fcint.h"
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
-#include "fcint.h"
 
-static FcPattern ** fcpatterns = 0;
+static FcPattern ** _fcPatterns = 0;
 static int fcpattern_bank_count = 0, fcpattern_ptr, fcpattern_count;
-static FcPatternElt ** fcpatternelts = 0;
+FcPatternElt ** _fcPatternElts = 0;
 static int fcpatternelt_ptr, fcpatternelt_count;
-static FcValueList ** fcvaluelists = 0;
+FcValueList ** _fcValueLists = 0;
 static int fcvaluelist_bank_count = 0, fcvaluelist_ptr, fcvaluelist_count;
 
-static const char *
-FcPatternFindFullFname (const FcPattern *p);
 static FcPatternEltPtr
 FcPatternEltPtrCreateDynamic (FcPatternElt * e);
-
-/* If you are trying to duplicate an FcPattern which will be used for
- * rendering, be aware that (internally) you also have to use
- * FcPatternTransferFullFname to transfer the associated filename.  If
- * you are copying the font (externally) using FcPatternGetString,
- * then everything's fine; this caveat only applies if you're copying
- * the bits individually.  */
+static FcBool
+FcStrHashed (const FcChar8 *name);
 
 FcPattern *
 FcPatternCreate (void)
@@ -68,7 +61,8 @@ FcValueDestroy (FcValue v)
 {
     switch (v.type) {
     case FcTypeString:
-       FcStrFree ((FcChar8 *) v.u.s);
+        if (!FcStrHashed (v.u.s))
+            FcStrFree ((FcChar8 *) v.u.s);
        break;
     case FcTypeMatrix:
        FcMatrixFree ((FcMatrix *) v.u.m);
@@ -149,7 +143,8 @@ FcValueListDestroy (FcValueListPtr l)
     {
        switch (FcValueListPtrU(l)->value.type) {
        case FcTypeString:
-           FcStrFree ((FcChar8 *)FcValueListPtrU(l)->value.u.s);
+            if (!FcStrHashed ((FcChar8 *)FcValueListPtrU(l)->value.u.s))
+                FcStrFree ((FcChar8 *)FcValueListPtrU(l)->value.u.s);
            break;
        case FcTypeMatrix:
            FcMatrixFree ((FcMatrix *)FcValueListPtrU(l)->value.u.m);
@@ -236,32 +231,31 @@ FcStringHash (const FcChar8 *s)
 }
 
 static FcChar32
-FcValueHash (const FcValue *v0)
+FcValueHash (const FcValue *v)
 {
-    FcValue v = FcValueCanonicalize(v0);
-    switch (v.type) {
+    switch (fc_storage_type(v)) {
     case FcTypeVoid:
        return 0;
     case FcTypeInteger:
-       return (FcChar32) v.u.i;
+       return (FcChar32) v->u.i;
     case FcTypeDouble:
-       return FcDoubleHash (v.u.d);
+       return FcDoubleHash (v->u.d);
     case FcTypeString:
-       return FcStringHash (v.u.s);
+       return FcStringHash (fc_value_string(v));
     case FcTypeBool:
-       return (FcChar32) v.u.b;
+       return (FcChar32) v->u.b;
     case FcTypeMatrix:
-       return (FcDoubleHash (v.u.m->xx) ^ 
-               FcDoubleHash (v.u.m->xy) ^ 
-               FcDoubleHash (v.u.m->yx) ^ 
-               FcDoubleHash (v.u.m->yy));
+       return (FcDoubleHash (v->u.m->xx) ^ 
+               FcDoubleHash (v->u.m->xy) ^ 
+               FcDoubleHash (v->u.m->yx) ^ 
+               FcDoubleHash (v->u.m->yy));
     case FcTypeCharSet:
-       return (FcChar32) v.u.c->num;
+       return (FcChar32) fc_value_charset(v)->num;
     case FcTypeFTFace:
-       return FcStringHash ((const FcChar8 *) ((FT_Face) v.u.f)->family_name) ^
-              FcStringHash ((const FcChar8 *) ((FT_Face) v.u.f)->style_name);
+       return FcStringHash ((const FcChar8 *) ((FT_Face) v->u.f)->family_name) ^
+              FcStringHash ((const FcChar8 *) ((FT_Face) v->u.f)->style_name);
     case FcTypeLangSet:
-       return FcLangSetHash (v.u.l);
+       return FcLangSetHash (fc_value_langset(v));
     }
     return FcFalse;
 }
@@ -289,12 +283,12 @@ static FcChar32
 FcValueListHash (FcValueListPtr l)
 {
     FcChar32   hash = 0;
+    FcValueList *l_ptrU;
     
-    while (FcValueListPtrU(l))
+    for (l_ptrU = FcValueListPtrU(l); l_ptrU; 
+        l_ptrU = FcValueListPtrU(l_ptrU->next))
     {
-       hash = ((hash << 1) | (hash >> 31)) ^ 
-           FcValueHash (&FcValueListPtrU(l)->value);
-       l = FcValueListPtrU(l)->next;
+       hash = ((hash << 1) | (hash >> 31)) ^ FcValueHash (&l_ptrU->value);
     }
     return hash;
 }
@@ -307,12 +301,6 @@ FcPatternDestroy (FcPattern *p)
     if (p->ref == FC_REF_CONSTANT || --p->ref > 0)
        return;
 
-    if (FcPatternFindFullFname (p))
-    {
-       FcStrFree ((FcChar8 *)FcPatternFindFullFname (p));
-       FcPatternAddFullFname (p, 0);
-    }
-
     for (i = 0; i < p->num; i++)
        FcValueListDestroy ((FcPatternEltU(p->elts)+i)->values);
 
@@ -328,366 +316,6 @@ FcPatternDestroy (FcPattern *p)
     free (p);
 }
 
-#define FC_VALUE_LIST_HASH_SIZE            257
-#define FC_PATTERN_HASH_SIZE       67
-
-typedef struct _FcValueListEnt FcValueListEnt;
-
-struct _FcValueListEnt {
-    FcValueListEnt  *next;
-    FcValueListPtr  list;
-    FcChar32       hash, pad;
-};
-
-typedef union _FcValueListAlign {
-    FcValueListEnt  ent;
-    FcValueList            list;
-} FcValueListAlign;
-
-static int         FcValueListFrozenCount[FcTypeLangSet + 1];
-static int         FcValueListFrozenBytes[FcTypeLangSet + 1];
-static char        FcValueListFrozenName[][8] = {
-    "Void", 
-    "Integer", 
-    "Double", 
-    "String", 
-    "Bool",
-    "Matrix",
-    "CharSet",
-    "FTFace",
-    "LangSet"
-};
-
-void
-FcValueListReport (void);
-    
-void
-FcValueListReport (void)
-{
-    FcType  t;
-
-    printf ("Fc Frozen Values:\n");
-    printf ("\t%8s %9s %9s\n", "Type", "Count", "Bytes");
-    for (t = FcTypeVoid; t <= FcTypeLangSet; t++)
-       printf ("\t%8s %9d %9d\n", FcValueListFrozenName[t],
-               FcValueListFrozenCount[t], FcValueListFrozenBytes[t]);
-}
-
-static FcValueListEnt *
-FcValueListEntCreate (FcValueListPtr h)
-{
-    FcValueListAlign   *ea;
-    FcValueListEnt  *e;
-    FcValueListPtr  l;
-    FcValueList     *new;
-    int                    n;
-    int                    size;
-
-    n = 0;
-    for (l = h; FcValueListPtrU(l); l = FcValueListPtrU(l)->next)
-       n++;
-    size = sizeof (FcValueListAlign) + n * sizeof (FcValueList);
-    FcValueListFrozenCount[FcValueListPtrU(h)->value.type]++;
-    FcValueListFrozenBytes[FcValueListPtrU(h)->value.type] += size;
-    // this leaks for some reason
-    ea = malloc (sizeof (FcValueListAlign));
-    if (!ea)
-       return 0;
-    new = malloc (n * sizeof (FcValueList));
-    if (!new)
-        return 0;
-    memset(new, 0, n * sizeof (FcValueList));
-    FcMemAlloc (FC_MEM_VALLIST, size);
-    e = &ea->ent;
-    e->list = (FcValueListPtr) FcValueListPtrCreateDynamic(new);
-    for (l = h; FcValueListPtrU(l); 
-        l = FcValueListPtrU(l)->next, new++)
-    {
-       if ((FcValueListPtrU(l)->value.type & ~FC_STORAGE_STATIC) == FcTypeString)
-       {
-           new->value.type = FcTypeString;
-           new->value.u.s = FcStrStaticName
-               (fc_value_string(&FcValueListPtrU(l)->value));
-       }
-       else
-       {
-           new->value = FcValueSave (FcValueCanonicalize
-                                     (&FcValueListPtrU(l)->value));
-       }
-       new->binding = FcValueListPtrU(l)->binding;
-       if (FcValueListPtrU(FcValueListPtrU(l)->next))
-       {
-           new->next = FcValueListPtrCreateDynamic(new + 1);
-       }
-       else
-       {
-           new->next = FcValueListPtrCreateDynamic(0);
-       }
-    }
-    return e;
-}
-
-static void
-FcValueListEntDestroy (FcValueListEnt *e)
-{
-    FcValueListPtr     l;
-
-    FcValueListFrozenCount[FcValueListPtrU(e->list)->value.type]--;
-
-    /* XXX: We should perform these two operations with "size" as
-       computed in FcValueListEntCreate, but we don't have access to
-       that value here. Without this, the FcValueListFrozenBytes
-       values will be wrong as will the FcMemFree counts.
-
-       FcValueListFrozenBytes[e->list->value.type] -= size;
-       FcMemFree (FC_MEM_VALLIST, size);
-    */
-
-    for (l = e->list; FcValueListPtrU(l); 
-        l = FcValueListPtrU(l)->next)
-    {
-       if (FcValueListPtrU(l)->value.type != FcTypeString)
-           FcValueDestroy (FcValueListPtrU(l)->value);
-    }
-    /* XXX: Are we being too chummy with the implementation here to
-       free(e) when it was actually the enclosing FcValueListAlign
-       that was allocated? */
-    free (e);
-}
-
-static int     FcValueListTotal;
-static int     FcValueListUsed;
-
-static FcValueListEnt   *FcValueListHashTable[FC_VALUE_LIST_HASH_SIZE];
-
-static FcValueListPtr
-FcValueListFreeze (FcValueListPtr l)
-{
-    FcChar32               hash = FcValueListHash (l);
-    FcValueListEnt         **bucket = &FcValueListHashTable[hash % FC_VALUE_LIST_HASH_SIZE];
-    FcValueListEnt         *ent;
-
-    FcValueListTotal++;
-    for (ent = *bucket; ent; ent = ent->next)
-    {
-       if (ent->hash == hash && FcValueListEqual (ent->list, l))
-           return ent->list;
-    }
-
-    ent = FcValueListEntCreate (l);
-    if (!ent)
-       return FcValueListPtrCreateDynamic(0);
-
-    FcValueListUsed++;
-    ent->hash = hash;
-    ent->next = *bucket;
-    *bucket = ent;
-    return ent->list;
-}
-
-static void
-FcValueListThawAll (void)
-{
-    int i;
-    FcValueListEnt     *ent, *next;
-
-    for (i = 0; i < FC_VALUE_LIST_HASH_SIZE; i++)
-    {
-       for (ent = FcValueListHashTable[i]; ent; ent = next)
-       {
-           next = ent->next;
-           FcValueListEntDestroy (ent);
-       }
-       FcValueListHashTable[i] = 0;
-    }
-
-    FcValueListTotal = 0;
-    FcValueListUsed = 0;
-}
-
-static FcChar32
-FcPatternBaseHash (FcPattern *b)
-{
-    FcChar32   hash = b->num;
-    int                i;
-
-    for (i = 0; i < b->num; i++)
-       hash = ((hash << 1) | (hash >> 31)) ^ 
-           (long) (FcValueListPtrU((FcPatternEltU(b->elts)+i)->values));
-    return hash;
-}
-
-typedef struct _FcPatternEnt FcPatternEnt;
-
-struct _FcPatternEnt {
-    FcPatternEnt    *next;
-    FcChar32       hash;
-    FcPattern              *pattern;
-};
-
-static int     FcPatternTotal;
-static int     FcPatternUsed;
-
-static FcPatternEnt    *FcPatternHashTable[FC_VALUE_LIST_HASH_SIZE];
-
-static FcPattern *
-FcPatternBaseFreeze (FcPattern *b)
-{
-    FcPattern           *ep;
-    FcPatternElt       *epp;
-    FcChar32           hash = FcPatternBaseHash (b);
-    FcPatternEnt       **bucket = &FcPatternHashTable[hash % FC_VALUE_LIST_HASH_SIZE];
-    FcPatternEnt       *ent;
-    int                        i;
-
-    FcPatternTotal++;
-    for (ent = *bucket; ent; ent = ent->next)
-    {
-        if (ent->hash == hash && b->num == ent->pattern->num)
-        {
-           for (i = 0; i < b->num; i++)
-           {
-               if (FcObjectPtrCompare((FcPatternEltU(b->elts)+i)->object,
-                                      (FcPatternEltU(ent->pattern->elts)+i)->object) != 0)
-                   break;
-               if (FcValueListPtrU((FcPatternEltU(b->elts)+i)->values) != 
-                    FcValueListPtrU((FcPatternEltU(ent->pattern->elts)+i)->values))
-                   break;
-           }
-           if (i == b->num)
-               return ent->pattern;
-       }
-    }
-
-    /*
-     * Compute size of pattern + elts
-     */
-    ent = malloc (sizeof (FcPatternEnt));
-    if (!ent)
-       return 0;
-
-    FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPatternEnt));
-    FcPatternUsed++;
-
-    ep = FcPatternCreate();
-    if (!ep)
-        return 0;
-    ent->pattern = ep;
-    epp = malloc(b->num * sizeof (FcPatternElt));
-    if (!epp)
-        goto bail;
-    ep->elts = FcPatternEltPtrCreateDynamic(epp);
-
-    FcMemAlloc (FC_MEM_PATELT, sizeof (FcPatternElt)*(b->num));
-
-    ep->num = b->num;
-    ep->size = b->num;
-    ep->ref = FC_REF_CONSTANT;
-
-    for (i = 0; i < b->num; i++)
-    {
-       (FcPatternEltU(ep->elts)+i)->values = 
-           (FcPatternEltU(b->elts)+i)->values;
-       (FcPatternEltU(ep->elts)+i)->object = 
-           (FcPatternEltU(b->elts)+i)->object;
-    }
-
-    if (FcPatternFindElt (b, FC_FILE))
-       FcPatternTransferFullFname (ep, b);
-
-    ent->hash = hash;
-    ent->next = *bucket;
-    *bucket = ent;
-    return ent->pattern;
- bail:
-    free(ent);
-    FcMemFree (FC_MEM_PATTERN, sizeof (FcPatternEnt));
-    FcPatternUsed--;
-    return 0;
-}
-
-static void
-FcPatternBaseThawAll (void)
-{
-    int i;
-    FcPatternEnt       *ent, *next;
-
-    for (i = 0; i < FC_VALUE_LIST_HASH_SIZE; i++)
-    {
-       for (ent = FcPatternHashTable[i]; ent; ent = next)
-       {
-           next = ent->next;
-           free (ent);
-       }
-       FcPatternHashTable[i] = 0;
-    }
-
-    FcPatternTotal = 0;
-    FcPatternUsed = 0;
-}
-
-FcPattern *
-FcPatternFreeze (FcPattern *p)
-{
-    FcPattern  *b, *n = 0;
-    FcPatternElt *e;
-    int                i;
-    
-    if (p->ref == FC_REF_CONSTANT)
-       return p;
-
-    b = FcPatternCreate();
-    if (!b)
-        return 0;
-
-    b->num = p->num;
-    b->size = b->num;
-    b->ref = 1;
-
-    e = malloc(b->num * sizeof (FcPatternElt));
-    if (!e)
-        return 0;
-    b->elts = FcPatternEltPtrCreateDynamic(e);
-    FcMemAlloc (FC_MEM_PATELT, sizeof (FcPatternElt)*(b->num));
-
-    /*
-     * Freeze object lists
-     */
-    for (i = 0; i < p->num; i++)
-    {
-       (FcPatternEltU(b->elts)+i)->object = 
-           (FcPatternEltU(p->elts)+i)->object;
-       (FcPatternEltU(b->elts)+i)->values = 
-           FcValueListFreeze((FcPatternEltU(p->elts)+i)->values);
-       if (!FcValueListPtrU((FcPatternEltU(p->elts)+i)->values))
-           goto bail;
-    }
-
-    if (FcPatternFindElt (p, FC_FILE))
-       FcPatternTransferFullFname (b, p);
-
-    /*
-     * Freeze base
-     */
-    n = FcPatternBaseFreeze (b);
-#ifdef CHATTY
-    if (FcDebug() & FC_DBG_MEMORY)
-    {
-       printf ("ValueLists: total %9d used %9d\n", FcValueListTotal, FcValueListUsed);
-       printf ("Patterns:   total %9d used %9d\n", FcPatternTotal, FcPatternUsed);
-    }
-#endif
- bail:
-    free(FcPatternEltU(b->elts));
-    b->elts = FcPatternEltPtrCreateDynamic(0);
-    FcMemFree (FC_MEM_PATELT, sizeof (FcPatternElt)*(b->num));
-    b->num = -1;
-#ifdef DEBUG
-    assert (FcPatternEqual (n, p));
-#endif
-    return n;
-}
-
 static int
 FcPatternPosition (const FcPattern *p, const char *object)
 {
@@ -869,7 +497,14 @@ FcPatternAddWithBinding  (FcPattern            *p,
     new = FcValueListPtrCreateDynamic(newp);
     FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList));
     /* dup string */
-    value = FcValueSave (value);
+    if (value.type == FcTypeString)
+    {
+       value.u.s = FcStrStaticName (value.u.s);
+       if (!value.u.s)
+           value.type = FcTypeVoid;
+    }
+    else
+       value = FcValueSave (value);
     if (value.type == FcTypeVoid)
        goto bail1;
 
@@ -1024,6 +659,13 @@ FcPatternAddString (FcPattern *p, const char *object, const FcChar8 *s)
 {
     FcValue    v;
 
+    if (!s)
+    {
+       v.type = FcTypeVoid;
+       v.u.s = 0;
+       return FcPatternAdd (p, object, v, FcTrue);
+    }
+
     v.type = FcTypeString;
     v.u.s = FcStrStaticName(s);
     return FcPatternAdd (p, object, v, FcTrue);
@@ -1157,41 +799,6 @@ FcPatternGetString (const FcPattern *p, const char *object, int id, FcChar8 ** s
     if (v.type != FcTypeString)
         return FcResultTypeMismatch;
 
-    if (FcObjectToPtr(object) == FcObjectToPtr(FC_FILE))
-    {
-       const char *fn, *fpath;
-       FcChar8 *fname;
-       int size;
-
-       fn = FcPatternFindFullFname(p);
-       if (fn)
-       {
-           *s = (FcChar8 *) fn;
-           return FcResultMatch;
-       }
-
-       if (!p->bank)
-       {
-           *s = (FcChar8 *) v.u.s;
-           return FcResultMatch;
-       }
-
-       fpath = FcCacheFindBankDir (p->bank);
-       size = strlen((char*)fpath) + 1 + strlen ((char *)v.u.s) + 1;
-       fname = malloc (size);
-       if (!fname)
-           return FcResultOutOfMemory;
-
-       FcMemAlloc (FC_MEM_STRING, size);
-       strcpy ((char *)fname, (char *)fpath);
-       strcat ((char *)fname, "/");
-       strcat ((char *)fname, (char *)v.u.s);
-       
-       FcPatternAddFullFname (p, (const char *)fname);
-       *s = (FcChar8 *)fname;
-       return FcResultMatch;
-    }
-
     *s = (FcChar8 *) v.u.s;
     return FcResultMatch;
 }
@@ -1296,7 +903,6 @@ FcPatternDuplicate (const FcPattern *orig)
                               FcTrue))
                goto bail1;
     }
-    FcPatternTransferFullFname (new, orig);
 
     return new;
 
@@ -1364,6 +970,19 @@ static struct objectBucket {
     FcChar32           hash;
 } *FcObjectBuckets[OBJECT_HASH_SIZE];
 
+static FcBool
+FcStrHashed (const FcChar8 *name)
+{
+    FcChar32           hash = FcStringHash (name);
+    struct objectBucket        **p;
+    struct objectBucket        *b;
+
+    for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
+       if (b->hash == hash && !strcmp ((char *)name, (char *) (b + 1)))
+            return FcTrue;
+    return FcFalse;
+}
+
 const FcChar8 *
 FcStrStaticName (const FcChar8 *name)
 {
@@ -1412,21 +1031,10 @@ FcStrStaticNameFini (void)
 void
 FcPatternFini (void)
 {
-    FcPatternBaseThawAll ();
-    FcValueListThawAll ();
     FcStrStaticNameFini ();
     FcObjectStaticNameFini ();
 }
 
-FcPatternElt *
-FcPatternEltU (FcPatternEltPtr pei)
-{
-    if (pei.bank == FC_BANK_DYNAMIC)
-       return pei.u.dyn;
-
-    return &fcpatternelts[FcCacheBankToIndex(pei.bank)][pei.u.stat];
-}
-
 static FcPatternEltPtr
 FcPatternEltPtrCreateDynamic (FcPatternElt * e)
 {
@@ -1456,7 +1064,7 @@ FcStrDistributeBytes (FcCache * metadata, void * block_ptr);
 static const FcChar8 *
 FcStrSerialize (int bank, const FcChar8 * s);
 static void *
-FcStrUnserialize (FcCache metadata, void *block_ptr);
+FcStrUnserialize (FcCache metadata, void *block_ptr);
 
 static void
 FcValueListNewBank (void);
@@ -1469,7 +1077,7 @@ FcValueListDistributeBytes (FcCache * metadata, void *block_ptr);
 static FcValueListPtr
 FcValueListSerialize(int bank, FcValueList *pi);
 static void *
-FcValueListUnserialize (FcCache metadata, void *block_ptr);
+FcValueListUnserialize (FcCache metadata, void *block_ptr);
 
 
 void
@@ -1505,7 +1113,7 @@ FcPatternNeededBytes (FcPattern * p)
 int
 FcPatternNeededBytesAlign (void)
 {
-    return __alignof__ (FcPattern) + __alignof__ (FcPatternElt) + 
+    return fc_alignof (FcPattern) + fc_alignof (FcPatternElt) + 
        FcValueListNeededBytesAlign ();
 }
 
@@ -1516,27 +1124,27 @@ FcPatternEnsureBank (int bi)
     FcPatternElt **ep;
     int i;
 
-    if (!fcpatterns || fcpattern_bank_count <= bi)
+    if (!_fcPatterns || fcpattern_bank_count <= bi)
     {
        int new_count = bi + 4;
-       pp = realloc (fcpatterns, sizeof (FcPattern *) * new_count);
+       pp = realloc (_fcPatterns, sizeof (FcPattern *) * new_count);
        if (!pp)
            return 0;
 
        FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern *) * new_count);
-       fcpatterns = pp;
+       _fcPatterns = pp;
 
-       ep = realloc (fcpatternelts, sizeof (FcPatternElt *) * new_count);
+       ep = realloc (_fcPatternElts, sizeof (FcPatternElt *) * new_count);
        if (!ep)
            return 0;
 
        FcMemAlloc (FC_MEM_PATELT, sizeof (FcPatternElt *) * new_count);
-       fcpatternelts = ep;
+       _fcPatternElts = ep;
 
        for (i = fcpattern_bank_count; i < new_count; i++)
        {
-           fcpatterns[i] = 0;
-           fcpatternelts[i] = 0;
+           _fcPatterns[i] = 0;
+           _fcPatternElts[i] = 0;
        }
 
        fcpattern_bank_count = new_count;
@@ -1556,14 +1164,14 @@ FcPatternDistributeBytes (FcCache * metadata, void * block_ptr)
 
     fcpattern_ptr = 0;
     block_ptr = ALIGN(block_ptr, FcPattern);
-    fcpatterns[bi] = (FcPattern *)block_ptr;
+    _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;
+    _fcPatternElts[bi] = (FcPatternElt *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
                         (sizeof (FcPatternElt) * fcpatternelt_count));
 
@@ -1584,10 +1192,10 @@ FcPatternSerialize (int bank, FcPattern *old)
     FcValueListPtr v, nv_head, nvp;
     int i, elts, bi = FcCacheBankToIndex(bank);
 
-    p = &fcpatterns[bi][fcpattern_ptr++];
+    p = &_fcPatterns[bi][fcpattern_ptr++];
     p->bank = bank;
     elts = fcpatternelt_ptr;
-    nep = &fcpatternelts[bi][elts];
+    nep = &_fcPatternElts[bi][elts];
     if (!nep)
        return FcFalse;
 
@@ -1628,24 +1236,24 @@ FcPatternSerialize (int bank, FcPattern *old)
 }
 
 void *
-FcPatternUnserialize (FcCache metadata, void *block_ptr)
+FcPatternUnserialize (FcCache metadata, void *block_ptr)
 {
-    int bi = FcCacheBankToIndex(metadata.bank);
+    int bi = FcCacheBankToIndex(metadata->bank);
     if (!FcPatternEnsureBank(bi))
        return FcFalse;
 
-    FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern) * metadata.pattern_count);
+    FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern) * metadata->pattern_count);
     block_ptr = ALIGN(block_ptr, FcPattern);
-    fcpatterns[bi] = (FcPattern *)block_ptr;
+    _fcPatterns[bi] = (FcPattern *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
-                        (sizeof (FcPattern) * metadata.pattern_count));
+                        (sizeof (FcPattern) * metadata->pattern_count));
     
     FcMemAlloc (FC_MEM_PATELT, 
-               sizeof (FcPatternElt) * metadata.patternelt_count);
+               sizeof (FcPatternElt) * metadata->patternelt_count);
     block_ptr = ALIGN(block_ptr, FcPatternElt);
-    fcpatternelts[bi] = (FcPatternElt *)block_ptr;
+    _fcPatternElts[bi] = (FcPatternElt *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
-                        (sizeof (FcPatternElt) * metadata.patternelt_count));
+                        (sizeof (FcPatternElt) * metadata->patternelt_count));
        
     block_ptr = FcStrUnserialize (metadata, block_ptr);
     block_ptr = FcValueListUnserialize (metadata, block_ptr);
@@ -1672,7 +1280,8 @@ FcValueListNeededBytes (FcValueList *p)
         vl; 
         vl = FcValueListPtrU(vl->next))
     {
-       FcValue v = FcValueCanonicalize(&vl->value); // unserialize just in case
+        /* unserialize just in case */
+        FcValue v = FcValueCanonicalize(&vl->value); 
 
        switch (v.type)
        {
@@ -1698,7 +1307,7 @@ static int
 FcValueListNeededBytesAlign (void)
 {
     return FcCharSetNeededBytesAlign() + FcLangSetNeededBytesAlign() + 
-       FcStrNeededBytesAlign() + __alignof__ (FcValueList);
+       FcStrNeededBytesAlign() + fc_alignof (FcValueList);
 }
 
 static FcBool
@@ -1706,19 +1315,19 @@ FcValueListEnsureBank (int bi)
 {
     FcValueList **pvl;
 
-    if (!fcvaluelists || fcvaluelist_bank_count <= bi)
+    if (!_fcValueLists || fcvaluelist_bank_count <= bi)
     {
        int new_count = bi + 2, i;
 
-       pvl = realloc (fcvaluelists, sizeof (FcValueList *) * new_count);
+       pvl = realloc (_fcValueLists, sizeof (FcValueList *) * new_count);
        if (!pvl)
            return FcFalse;
 
        FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList *) * new_count);
 
-       fcvaluelists = pvl;
+       _fcValueLists = pvl;
        for (i = fcvaluelist_bank_count; i < new_count; i++)
-           fcvaluelists[i] = 0;
+           _fcValueLists[i] = 0;
 
        fcvaluelist_bank_count = new_count;
     }
@@ -1736,7 +1345,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;
+    _fcValueLists[bi] = (FcValueList *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
                         (sizeof (FcValueList) * fcvaluelist_count));
     metadata->valuelist_count = fcvaluelist_count;
@@ -1761,11 +1370,11 @@ FcValueListSerialize(int bank, FcValueList *pi)
        return new;
     }
 
-    fcvaluelists[bi][fcvaluelist_ptr] = *pi;
+    _fcValueLists[bi][fcvaluelist_ptr] = *pi;
     new.bank = bank;
     new.u.stat = fcvaluelist_ptr++;
-    fcvaluelists[bi][new.u.stat].value = FcValueCanonicalize (&pi->value);
-    v = &fcvaluelists[bi][new.u.stat].value;
+    _fcValueLists[bi][new.u.stat].value = FcValueCanonicalize (&pi->value);
+    v = &_fcValueLists[bi][new.u.stat].value;
     switch (v->type)
     {
     case FcTypeString:
@@ -1807,19 +1416,19 @@ FcValueListSerialize(int bank, FcValueList *pi)
 }
 
 static void *
-FcValueListUnserialize (FcCache metadata, void *block_ptr)
+FcValueListUnserialize (FcCache metadata, void *block_ptr)
 {
-    int bi = FcCacheBankToIndex(metadata.bank);
+    int bi = FcCacheBankToIndex(metadata->bank);
 
     if (!FcValueListEnsureBank(bi))
        return 0;
 
     FcMemAlloc (FC_MEM_VALLIST, 
-               sizeof (FcValueList) * metadata.valuelist_count);
+               sizeof (FcValueList) * metadata->valuelist_count);
     block_ptr = ALIGN(block_ptr, FcValueList);
-    fcvaluelists[bi] = (FcValueList *)block_ptr;
+    _fcValueLists[bi] = (FcValueList *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
-                        (sizeof (FcValueList) * metadata.valuelist_count));
+                        (sizeof (FcValueList) * metadata->valuelist_count));
 
     block_ptr = FcCharSetUnserialize(metadata, block_ptr);
     block_ptr = FcLangSetUnserialize(metadata, block_ptr);
@@ -1827,15 +1436,6 @@ FcValueListUnserialize (FcCache metadata, void *block_ptr)
     return block_ptr;
 }
 
-FcValueList * 
-FcValueListPtrU (FcValueListPtr pi)
-{
-    if (pi.bank == FC_BANK_DYNAMIC)
-        return pi.u.dyn;
-
-    return &fcvaluelists[FcCacheBankToIndex(pi.bank)][pi.u.stat];
-}
-
 FcValueListPtr
 FcValueListPtrCreateDynamic(FcValueList * p)
 {
@@ -1881,6 +1481,7 @@ FcStrNeededBytes (const FcChar8 * s)
     struct objectBucket **p;
     struct objectBucket *b;
     int                 size;
+    FcChar8 *const null = 0;
 
     for (p = &FcStrBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
         if (b->hash == hash && !strcmp ((char *)s, (char *) (b + 1)))
@@ -1898,7 +1499,8 @@ FcStrNeededBytes (const FcChar8 * s)
      * 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;
+    /* Misaligned pointers are not guaranteed to work, either! */
+    memcpy (((char *) (b + 1) + strlen((char *)s) + 1), &null, sizeof (null));
     *p = b;
 
     fcstr_count += strlen((char *)s) + 1;
@@ -1908,7 +1510,7 @@ FcStrNeededBytes (const FcChar8 * s)
 static int
 FcStrNeededBytesAlign (void)
 {
-    return __alignof__ (char);
+    return fc_alignof (char);
 }
 
 static FcBool
@@ -1961,13 +1563,15 @@ FcStrSerialize (int bank, const FcChar8 * s)
     for (p = &FcStrBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
         if (b->hash == hash && !strcmp ((char *)s, (char *) (b + 1)))
        {
-           FcChar8 * t = *(FcChar8 **)(((FcChar8 *)(b + 1)) + strlen ((char *)s) + 1);
+           FcChar8 * t;
+           memcpy (&t, ((FcChar8 *)(b + 1)) + strlen ((char *)s) + 1, sizeof (FcChar8 *));
            if (!t)
            {
                strcpy((char *)(static_strs[bi] + fcstr_ptr), (char *)s);
-               *(FcChar8 **)((FcChar8 *) (b + 1) + strlen((char *)s) + 1) = (static_strs[bi] + fcstr_ptr);
+               t = static_strs[bi] + fcstr_ptr;
+               memcpy ((FcChar8 *) (b + 1) + strlen((char *)s) + 1, &t, sizeof (FcChar8 *));
                fcstr_ptr += strlen((char *)s) + 1;
-               t = *(FcChar8 **)(((FcChar8 *)(b + 1)) + strlen ((char *)s) + 1);
+               memcpy (&t, ((FcChar8 *)(b + 1)) + strlen ((char *)s) + 1, sizeof (FcChar8 *));
            }
            return t;
        }
@@ -1975,85 +1579,17 @@ FcStrSerialize (int bank, const FcChar8 * s)
 }
 
 static void *
-FcStrUnserialize (FcCache metadata, void *block_ptr)
+FcStrUnserialize (FcCache metadata, void *block_ptr)
 {
-    int bi = FcCacheBankToIndex(metadata.bank);
+    int bi = FcCacheBankToIndex(metadata->bank);
     if (!FcStrEnsureBank(bi))
        return 0;
 
-    FcMemAlloc (FC_MEM_STRING, sizeof (char) * metadata.str_count);
+    FcMemAlloc (FC_MEM_STRING, sizeof (char) * metadata->str_count);
     block_ptr = ALIGN (block_ptr, FcChar8);
     static_strs[bi] = (FcChar8 *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
-                        (sizeof (char) * metadata.str_count));
+                        (sizeof (char) * metadata->str_count));
 
     return block_ptr;
 }
-
-/* we don't store these in the FcPattern itself because
- * we don't want to serialize the directory names */
-
-/* I suppose this should be cleaned, too... */
-typedef struct _FcPatternDirMapping {
-    const FcPattern    *p;
-    const char *fname;
-} FcPatternDirMapping;
-
-#define PATTERNDIR_HASH_SIZE    31
-static struct patternDirBucket {
-    struct patternDirBucket    *next;
-    FcPatternDirMapping                m;
-} FcPatternDirBuckets[PATTERNDIR_HASH_SIZE];
-
-void
-FcPatternAddFullFname (const FcPattern *p, const char *fname)
-{
-    struct patternDirBucket    *pb;
-
-    /* N.B. FcPatternHash fails, since it's contents-based, not
-     * address-based, and we're in the process of mutating the FcPattern. */
-    for (pb = &FcPatternDirBuckets
-             [((int)p / sizeof (FcPattern *)) % PATTERNDIR_HASH_SIZE];
-         pb->m.p != p && pb->next; 
-         pb = pb->next)
-        ;
-
-    if (pb->m.p == p)
-    {
-        pb->m.fname = fname;
-        return;
-    }
-
-    pb->next = malloc (sizeof (struct patternDirBucket));
-    if (!pb->next)
-        return;
-    FcMemAlloc (FC_MEM_CACHE, sizeof (struct patternDirBucket));
-
-    pb->next->next = 0;
-    pb->next->m.p = p;
-    pb->next->m.fname = fname;
-}
-
-static const char *
-FcPatternFindFullFname (const FcPattern *p)
-{
-    struct patternDirBucket    *pb;
-
-    for (pb = &FcPatternDirBuckets
-             [((int)p / sizeof (FcPattern *)) % PATTERNDIR_HASH_SIZE]; 
-         pb; pb = pb->next)
-       if (pb->m.p == p)
-           return pb->m.fname;
-
-    return 0;
-}
-
-void
-FcPatternTransferFullFname (const FcPattern *new, const FcPattern *orig)
-{
-    FcChar8 * s;
-    FcPatternGetString (orig, FC_FILE, 0, &s);
-    FcPatternAddFullFname (new, 
-                          (char *)FcStrCopy 
-                          ((FcChar8 *)FcPatternFindFullFname(orig)));
-}