diff options
author | marha <marha@users.sourceforge.net> | 2013-01-07 12:17:07 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2013-01-07 12:17:07 +0100 |
commit | 0e950715b62dcf30ffbf69831bf932fd348537e5 (patch) | |
tree | 83fdafc455e9906f029e2e1ad926fb35c98e7be9 /fontconfig/src/fcpat.c | |
parent | 506537495e6d808f219361a5b270510c752e7a2e (diff) | |
parent | 3f553aaceddc9b09363c73d9bea40eaea8164fc4 (diff) | |
download | vcxsrv-0e950715b62dcf30ffbf69831bf932fd348537e5.tar.gz vcxsrv-0e950715b62dcf30ffbf69831bf932fd348537e5.tar.bz2 vcxsrv-0e950715b62dcf30ffbf69831bf932fd348537e5.zip |
Merge remote-tracking branch 'origin/released'
* origin/released:
pixman xkbcomp libX11 libXau mesa fontconfig xserver xkeyboard-config git update 7 jan 2013
Conflicts:
fontconfig/src/fcatomic.c
pixman/pixman/pixman-mmx.c
pixman/pixman/pixman-sse2.c
xorg-server/dix/dispatch.c
xorg-server/hw/xwin/wincursor.c
xorg-server/hw/xwin/winmsg.c
xorg-server/hw/xwin/winscrinit.c
xorg-server/hw/xwin/winsetsp.c
xorg-server/hw/xwin/winwin32rootless.c
xorg-server/xfixes/cursor.c
Diffstat (limited to 'fontconfig/src/fcpat.c')
-rw-r--r-- | fontconfig/src/fcpat.c | 150 |
1 files changed, 34 insertions, 116 deletions
diff --git a/fontconfig/src/fcpat.c b/fontconfig/src/fcpat.c index 62e47ca7e..b3b155d4d 100644 --- a/fontconfig/src/fcpat.c +++ b/fontconfig/src/fcpat.c @@ -22,9 +22,8 @@ #include "fcint.h" #include "fcftint.h" -#include <stdlib.h> -#include <string.h> -#include <assert.h> + +/* Objects MT-safe for readonly access. */ FcPattern * FcPatternCreate (void) @@ -34,21 +33,19 @@ FcPatternCreate (void) p = (FcPattern *) malloc (sizeof (FcPattern)); if (!p) return 0; - FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern)); p->num = 0; p->size = 0; p->elts_offset = FcPtrToOffset (p, NULL); - p->ref = 1; + FcRefInit (&p->ref, 1); return p; } void FcValueDestroy (FcValue v) { - switch (v.type) { + switch ((int) v.type) { case FcTypeString: - if (!FcSharedStrFree (v.u.s)) - FcStrFree ((FcChar8 *) v.u.s); + FcFree (v.u.s); break; case FcTypeMatrix: FcMatrixFree ((FcMatrix *) v.u.m); @@ -69,7 +66,7 @@ FcValueCanonicalize (const FcValue *v) { FcValue new; - switch (v->type) + switch ((int) v->type) { case FcTypeString: new.u.s = FcValueString(v); @@ -93,9 +90,9 @@ FcValueCanonicalize (const FcValue *v) FcValue FcValueSave (FcValue v) { - switch (v.type) { + switch ((int) v.type) { case FcTypeString: - v.u.s = FcSharedStr (v.u.s); + v.u.s = FcStrdup (v.u.s); if (!v.u.s) v.type = FcTypeVoid; break; @@ -123,15 +120,7 @@ FcValueSave (FcValue v) FcValueListPtr FcValueListCreate (void) { - FcValueListPtr ret; - - ret = calloc (1, sizeof (FcValueList)); - if (ret) - { - FcMemAlloc(FC_MEM_VALLIST, sizeof (FcValueList)); - } - - return ret; + return calloc (1, sizeof (FcValueList)); } void @@ -140,10 +129,9 @@ FcValueListDestroy (FcValueListPtr l) FcValueListPtr next; for (; l; l = next) { - switch (l->value.type) { + switch ((int) l->value.type) { case FcTypeString: - if (!FcSharedStrFree ((FcChar8 *)l->value.u.s)) - FcStrFree ((FcChar8 *)l->value.u.s); + FcFree (l->value.u.s); break; case FcTypeMatrix: FcMatrixFree ((FcMatrix *)l->value.u.m); @@ -160,7 +148,6 @@ FcValueListDestroy (FcValueListPtr l) break; } next = FcValueListNext(l); - FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList)); free(l); } } @@ -369,22 +356,23 @@ FcPatternDestroy (FcPattern *p) int i; FcPatternElt *elts; - if (p->ref == FC_REF_CONSTANT) + if (!p) + return; + + if (FcRefIsConst (&p->ref)) { FcCacheObjectDereference (p); return; } - if (--p->ref > 0) + if (FcRefDec (&p->ref) != 1) return; elts = FcPatternElts (p); for (i = 0; i < p->num; i++) FcValueListDestroy (FcPatternEltValues(&elts[i])); - FcMemFree (FC_MEM_PATELT, p->size * sizeof (FcPatternElt)); free (elts); - FcMemFree (FC_MEM_PATTERN, sizeof (FcPattern)); free (p); } @@ -454,9 +442,6 @@ FcPatternObjectInsertElt (FcPattern *p, FcObject object) if (!e) return FcFalse; p->elts_offset = FcPtrToOffset (p, e); - if (p->size) - FcMemFree (FC_MEM_PATELT, p->size * sizeof (FcPatternElt)); - FcMemAlloc (FC_MEM_PATELT, s * sizeof (FcPatternElt)); while (p->size < s) { e[p->size].object = 0; @@ -558,7 +543,7 @@ FcPatternObjectListAdd (FcPattern *p, FcPatternElt *e; FcValueListPtr l, *prev; - if (p->ref == FC_REF_CONSTANT) + if (FcRefIsConst (&p->ref)) goto bail0; /* @@ -568,12 +553,10 @@ FcPatternObjectListAdd (FcPattern *p, { if (!FcObjectValidType (object, l->value.type)) { - if (FcDebug() & FC_DBG_OBJTYPES) - { - printf ("FcPattern object %s does not accept value ", - FcObjectName (object)); - FcValuePrint (l->value); - } + fprintf (stderr, + "Fontconfig warning: FcPattern object %s does not accept value", FcObjectName (object)); + FcValuePrintFile (stderr, l->value); + fprintf (stderr, "\n"); goto bail0; } } @@ -612,7 +595,7 @@ FcPatternObjectAddWithBinding (FcPattern *p, FcPatternElt *e; FcValueListPtr new, *prev; - if (p->ref == FC_REF_CONSTANT) + if (FcRefIsConst (&p->ref)) goto bail0; new = FcValueListCreate (); @@ -628,12 +611,11 @@ FcPatternObjectAddWithBinding (FcPattern *p, */ if (!FcObjectValidType (object, value.type)) { - if (FcDebug() & FC_DBG_OBJTYPES) - { - printf ("FcPattern object %s does not accept value ", - FcObjectName (object)); - FcValuePrint (value); - } + fprintf (stderr, + "Fontconfig warning: FcPattern object %s does not accept value", + FcObjectName (object)); + FcValuePrintFile (stderr, value); + fprintf (stderr, "\n"); goto bail1; } @@ -662,7 +644,6 @@ FcPatternObjectAddWithBinding (FcPattern *p, bail2: FcValueDestroy (value); bail1: - FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList)); free (new); bail0: return FcFalse; @@ -892,7 +873,7 @@ FcPatternObjectGetInteger (const FcPattern *p, FcObject object, int id, int *i) r = FcPatternObjectGet (p, object, id, &v); if (r != FcResultMatch) return r; - switch (v.type) { + switch ((int) v.type) { case FcTypeDouble: *i = (int) v.u.d; break; @@ -921,7 +902,7 @@ FcPatternObjectGetDouble (const FcPattern *p, FcObject object, int id, double *d r = FcPatternObjectGet (p, object, id, &v); if (r != FcResultMatch) return r; - switch (v.type) { + switch ((int) v.type) { case FcTypeDouble: *d = v.u.d; break; @@ -1076,8 +1057,8 @@ bail0: void FcPatternReference (FcPattern *p) { - if (p->ref != FC_REF_CONSTANT) - p->ref++; + if (!FcRefIsConst (&p->ref)) + FcRefInc (&p->ref); else FcCacheObjectReference (p); } @@ -1163,69 +1144,6 @@ bail0: return NULL; } -#define OBJECT_HASH_SIZE 251 -static struct objectBucket { - struct objectBucket *next; - FcChar32 hash; - int ref_count; -} *FcObjectBuckets[OBJECT_HASH_SIZE]; - -FcBool -FcSharedStrFree (const FcChar8 *name) -{ - FcChar32 hash = FcStringHash (name); - struct objectBucket **p; - struct objectBucket *b; - int size; - - for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next)) - if (b->hash == hash && ((char *)name == (char *) (b + 1))) - { - b->ref_count--; - if (!b->ref_count) - { - *p = b->next; - size = sizeof (struct objectBucket) + strlen ((char *)name) + 1; - size = (size + 3) & ~3; - FcMemFree (FC_MEM_SHAREDSTR, size); - free (b); - } - return FcTrue; - } - return FcFalse; -} - -const FcChar8 * -FcSharedStr (const FcChar8 *name) -{ - FcChar32 hash = FcStringHash (name); - struct objectBucket **p; - struct objectBucket *b; - int size; - - for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next)) - if (b->hash == hash && !strcmp ((char *)name, (char *) (b + 1))) - { - b->ref_count++; - return (FcChar8 *) (b + 1); - } - size = sizeof (struct objectBucket) + strlen ((char *)name) + 1; - /* - * workaround valgrind warning because glibc takes advantage of how it knows memory is - * allocated to implement strlen by reading in groups of 4 - */ - size = (size + 3) & ~3; - b = malloc (size); - FcMemAlloc (FC_MEM_SHAREDSTR, size); - if (!b) - return NULL; - b->next = 0; - b->hash = hash; - b->ref_count = 1; - strcpy ((char *) (b + 1), (char *)name); - *p = b; - return (FcChar8 *) (b + 1); -} FcBool FcPatternSerializeAlloc (FcSerialize *serialize, const FcPattern *pat) @@ -1257,7 +1175,7 @@ FcPatternSerialize (FcSerialize *serialize, const FcPattern *pat) return NULL; *pat_serialized = *pat; pat_serialized->size = pat->num; - pat_serialized->ref = FC_REF_CONSTANT; + FcRefSetConst (&pat_serialized->ref); elts_serialized = FcSerializePtr (serialize, elts); if (!elts_serialized) @@ -1293,7 +1211,7 @@ FcValueListSerializeAlloc (FcSerialize *serialize, const FcValueList *vl) { if (!FcSerializeAlloc (serialize, vl, sizeof (FcValueList))) return FcFalse; - switch (vl->value.type) { + switch ((int) vl->value.type) { case FcTypeString: if (!FcStrSerializeAlloc (serialize, vl->value.u.s)) return FcFalse; @@ -1339,7 +1257,7 @@ FcValueListSerialize (FcSerialize *serialize, const FcValueList *vl) vl_serialized->next = NULL; vl_serialized->value.type = vl->value.type; - switch (vl->value.type) { + switch ((int) vl->value.type) { case FcTypeInteger: vl_serialized->value.u.i = vl->value.u.i; break; |