* 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 FcPatternEltPtr
FcPatternEltPtrCreateDynamic (FcPatternElt * e);
+static FcBool
+FcStrHashed (const FcChar8 *name);
FcPattern *
FcPatternCreate (void)
{
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);
{
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);
}
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;
}
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;
}
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;
- }
-
- 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;
- }
- /*
- * 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)
{
{
FcPatternElt *e;
FcValueListPtr new, *prev;
- FcValueList * newp;
+ FcValueList *newp;
+ FcObjectPtr objectPtr;
if (p->ref == FC_REF_CONSTANT)
goto bail0;
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;
+ /* quick and dirty hack to enable FcCompareFamily/FcCompareString
+ * speedup: only allow strings to be added under the FC_FAMILY,
+ * FC_FOUNDRY, FC_STYLE, FC_RASTERIZER keys.
+ * and charsets under FC_CHARSET key.
+ * This is slightly semantically different from the old behaviour,
+ * but fonts shouldn't be getting non-strings here anyway.
+ * a better hack would use FcBaseObjectTypes to check all objects. */
+ objectPtr = FcObjectToPtr(object);
+ if ((objectPtr == FcObjectToPtr(FC_FAMILY)
+ || objectPtr == FcObjectToPtr(FC_FOUNDRY)
+ || objectPtr == FcObjectToPtr(FC_STYLE)
+ || objectPtr == FcObjectToPtr(FC_RASTERIZER))
+ && value.type != FcTypeString)
+ goto bail1;
+ if (objectPtr == FcObjectToPtr(FC_CHARSET)
+ && value.type != FcTypeCharSet)
+ goto bail1;
+
FcValueListPtrU(new)->value = value;
FcValueListPtrU(new)->binding = binding;
FcValueListPtrU(new)->next = FcValueListPtrCreateDynamic(0);
{
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);
return r;
if (v.type != FcTypeString)
return FcResultTypeMismatch;
+
*s = (FcChar8 *) v.u.s;
return FcResultMatch;
}
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)
{
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)
{
FcStrNewBank (void);
static int
FcStrNeededBytes (const FcChar8 * s);
+static int
+FcStrNeededBytesAlign (void);
static void *
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);
static int
FcValueListNeededBytes (FcValueList * vl);
+static int
+FcValueListNeededBytesAlign (void);
static void *
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
return cum + sizeof (FcPattern) + sizeof(FcPatternElt)*p->num;
}
+int
+FcPatternNeededBytesAlign (void)
+{
+ return fc_alignof (FcPattern) + fc_alignof (FcPatternElt) +
+ FcValueListNeededBytesAlign ();
+}
+
static FcBool
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;
return 0;
fcpattern_ptr = 0;
- fcpatterns[bi] = (FcPattern *)block_ptr;
+ 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;
- fcpatternelts[bi] = (FcPatternElt *)block_ptr;
+ block_ptr = ALIGN(block_ptr, FcPatternElt);
+ _fcPatternElts[bi] = (FcPatternElt *)block_ptr;
block_ptr = (void *)((char *)block_ptr +
(sizeof (FcPatternElt) * fcpatternelt_count));
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;
}
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);
- fcpatterns[bi] = (FcPattern *)block_ptr;
+ 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));
+ (sizeof (FcPattern) * metadata->pattern_count));
FcMemAlloc (FC_MEM_PATELT,
- sizeof (FcPatternElt) * metadata.patternelt_count);
- fcpatternelts[bi] = (FcPatternElt *)block_ptr;
+ 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));
+ (sizeof (FcPatternElt) * metadata->patternelt_count));
block_ptr = FcStrUnserialize (metadata, block_ptr);
block_ptr = FcValueListUnserialize (metadata, block_ptr);
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)
{
return cum;
}
+static int
+FcValueListNeededBytesAlign (void)
+{
+ return FcCharSetNeededBytesAlign() + FcLangSetNeededBytesAlign() +
+ FcStrNeededBytesAlign() + fc_alignof (FcValueList);
+}
+
static FcBool
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;
}
FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList) * fcvaluelist_count);
fcvaluelist_ptr = 0;
- fcvaluelists[bi] = (FcValueList *)block_ptr;
+ block_ptr = ALIGN(block_ptr, FcValueList);
+ _fcValueLists[bi] = (FcValueList *)block_ptr;
block_ptr = (void *)((char *)block_ptr +
(sizeof (FcValueList) * fcvaluelist_count));
metadata->valuelist_count = fcvaluelist_count;
return new;
}
- fcvaluelists[bi][fcvaluelist_ptr] = *pi;
+ _fcValueLists[bi][fcvaluelist_ptr] = *pi;
new.bank = bank;
new.u.stat = fcvaluelist_ptr++;
- 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:
}
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);
- fcvaluelists[bi] = (FcValueList *)block_ptr;
+ 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));
+ (sizeof (FcValueList) * metadata->valuelist_count));
block_ptr = FcCharSetUnserialize(metadata, block_ptr);
block_ptr = FcLangSetUnserialize(metadata, 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)
{
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)))
b->next = 0;
b->hash = hash;
strcpy ((char *) (b + 1), (char *)s);
- *(char **)((char *) (b + 1) + strlen((char *)s) + 1) = 0;
+
+ /* 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. */
+ /* 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;
return strlen((char *)s) + 1;
}
+static int
+FcStrNeededBytesAlign (void)
+{
+ return fc_alignof (char);
+}
+
static FcBool
FcStrEnsureBank (int bi)
{
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;
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;
}
}
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;
}
-