]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcpat.c
Because we've changed FcPatternAddString to use FcStrStaticName and not
[fontconfig.git] / src / fcpat.c
index cc87ff07b05343fb216a910a5709c44f8f017d92..e2bdd3035f1dfd03067dd4d50531c007115d6b4b 100644 (file)
@@ -34,10 +34,13 @@ static int fcpatternelt_ptr, fcpatternelt_count;
 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);
+static FcBool
+FcStrHashed (const FcChar8 *name);
+
+static const char *
+FcPatternFindFullFname (const FcPattern *p);
 
 /* If you are trying to duplicate an FcPattern which will be used for
  * rendering, be aware that (internally) you also have to use
@@ -68,7 +71,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 +153,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);
@@ -1024,6 +1029,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);
@@ -1364,6 +1376,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)
 {