Forward port cworth's patch to branch.

This commit is contained in:
Patrick Lam 2005-07-15 18:49:12 +00:00
parent 0fa680f076
commit e1b9d091c6
5 changed files with 59 additions and 21 deletions

View File

@ -1,3 +1,18 @@
2005-07-15 Carl Worth <cworth@cworth.org>
* src/fcint.h:
* src/fcinit.c: (FcFini):
* src/fcpat.c: (FcPatternFini): Rename FcPatternThawAll to
FcPatternFini.
* src/fcpat.c: (FcObjectStaticName), (FcObjectStaticNameFini):
Pull the FcObjectStateName hash table out to file scope, and add
FcObjectStaticNameFini so that FcFini will cleanup this hash table
as well.
* src/fcxml.c: (FcConfigParseAndLoad): Clear FILE* to NULL after
fclose.
2005-06-16 Patrick Lam <plam@MIT.EDU> 2005-06-16 Patrick Lam <plam@MIT.EDU>
reviewed by: keithp reviewed by: keithp

View File

@ -116,7 +116,7 @@ FcFini (void)
if (_fcConfig) if (_fcConfig)
FcConfigDestroy (_fcConfig); FcConfigDestroy (_fcConfig);
FcPatternThawAll (); FcPatternFini ();
FcCharSetThawAll (); FcCharSetThawAll ();
} }

View File

@ -812,7 +812,7 @@ FcPattern *
FcPatternFreeze (FcPattern *p); FcPatternFreeze (FcPattern *p);
void void
FcPatternThawAll (void); FcPatternFini (void);
FcBool FcBool
FcPatternAppend (FcPattern *p, FcPattern *s); FcPatternAppend (FcPattern *p, FcPattern *s);

View File

@ -651,13 +651,6 @@ FcPatternFreeze (FcPattern *p)
return n; return n;
} }
void
FcPatternThawAll (void)
{
FcPatternBaseThawAll ();
FcValueListThawAll ();
}
static int static int
FcPatternPosition (const FcPattern *p, const char *object) FcPatternPosition (const FcPattern *p, const char *object)
{ {
@ -1584,7 +1577,7 @@ struct objectBucket {
struct objectBucket *next; struct objectBucket *next;
FcChar32 hash; FcChar32 hash;
}; };
static struct objectBucket **buckets = 0; static struct objectBucket **FcObjectBuckets = 0;
FcObjectPtr FcObjectPtr
FcObjectStaticName (const char *name) FcObjectStaticName (const char *name)
@ -1596,13 +1589,13 @@ FcObjectStaticName (const char *name)
int size; int size;
FcObjectPtr new; FcObjectPtr new;
if (!buckets) if (!FcObjectBuckets)
{ {
buckets = malloc(sizeof (struct objectBucket *)*OBJECT_HASH_SIZE); FcObjectBuckets = malloc(sizeof (struct objectBucket *)*OBJECT_HASH_SIZE);
memset (buckets, 0, sizeof (struct objectBucket *)*OBJECT_HASH_SIZE); memset (FcObjectBuckets, 0, sizeof (struct objectBucket *)*OBJECT_HASH_SIZE);
} }
for (p = &buckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next)) for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
{ {
FcObjectPtr bp = *((FcObjectPtr *) (b + 1)); FcObjectPtr bp = *((FcObjectPtr *) (b + 1));
if (b->hash == hash && FcObjectPtrU(bp) && !strcmp (name, FcObjectPtrU(bp))) if (b->hash == hash && FcObjectPtrU(bp) && !strcmp (name, FcObjectPtrU(bp)))
@ -1649,7 +1642,7 @@ FcObjectStaticName (const char *name)
objectptr_alloc = s; objectptr_alloc = s;
} }
size = sizeof (struct objectBucket) + sizeof (FcObjectPtr); size = sizeof (struct objectBucket) + strlen (name) + 1;
b = malloc (size); b = malloc (size);
if (!b) if (!b)
return 0; return 0;
@ -1709,11 +1702,11 @@ FcObjectRebuildStaticNameHashtable (void)
int i; int i;
struct objectBucket *b, *bn; struct objectBucket *b, *bn;
if (buckets) if (FcObjectBuckets)
{ {
for (i = 0; i < OBJECT_HASH_SIZE; i++) for (i = 0; i < OBJECT_HASH_SIZE; i++)
{ {
b = buckets[i]; b = FcObjectBuckets[i];
while (b) while (b)
{ {
bn = b->next; bn = b->next;
@ -1723,11 +1716,11 @@ FcObjectRebuildStaticNameHashtable (void)
b = bn; b = bn;
} }
} }
free (buckets); free (FcObjectBuckets);
} }
buckets = malloc(sizeof (struct objectBucket *)*OBJECT_HASH_SIZE); FcObjectBuckets = malloc(sizeof (struct objectBucket *)*OBJECT_HASH_SIZE);
memset (buckets, 0, sizeof (struct objectBucket *)*OBJECT_HASH_SIZE); memset (FcObjectBuckets, 0, sizeof (struct objectBucket *)*OBJECT_HASH_SIZE);
for (i = 1; i < objectptr_count; i++) for (i = 1; i < objectptr_count; i++)
{ {
@ -1738,7 +1731,7 @@ FcObjectRebuildStaticNameHashtable (void)
struct objectBucket **p; struct objectBucket **p;
int size; int size;
for (p = &buckets[hash % OBJECT_HASH_SIZE]; (b = *p); for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p);
p = &(b->next)) p = &(b->next))
; ;
size = sizeof (struct objectBucket) + sizeof (FcObjectPtr); size = sizeof (struct objectBucket) + sizeof (FcObjectPtr);
@ -1948,3 +1941,32 @@ FcObjectPrepareSerialize (FcObjectPtr si)
bail: bail:
return FcFalse; return FcFalse;
} }
static void
FcObjectStaticNameFini (void)
{
int i, size;
struct objectBucket *b, *next;
char *name;
for (i = 0; i < OBJECT_HASH_SIZE; i++)
{
for (b = FcObjectBuckets[i]; b; b = next)
{
next = b->next;
name = (char *) (b + 1);
size = sizeof (struct objectBucket) + strlen (name) + 1;
FcMemFree (FC_MEM_STATICSTR, size);
free (b);
}
FcObjectBuckets[i] = 0;
}
}
void
FcPatternFini (void)
{
FcPatternBaseThawAll ();
FcValueListThawAll ();
FcObjectStaticNameFini ();
}

View File

@ -2374,6 +2374,7 @@ bail2:
XML_ParserFree (p); XML_ParserFree (p);
bail1: bail1:
fclose (f); fclose (f);
f = NULL;
bail0: bail0:
if (error && complain) if (error && complain)
{ {