X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=src%2Ffccache.c;h=7e2c1bec9363068b2b2ec31fb743a4c00fdec348;hb=cc104e6a910427db009be36ec34125962889ecb8;hp=77a303d77a044e59bedb6a3ba70e0e030115aca5;hpb=17389539a046f7231447d531ef7f3d131c1d7515;p=fontconfig.git diff --git a/src/fccache.c b/src/fccache.c index 77a303d..7e2c1be 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -213,6 +213,17 @@ struct _FcCacheSkip { static FcCacheSkip *fcCacheChains[FC_CACHE_MAX_LEVEL]; static int fcCacheMaxLevel; +#if HAVE_RANDOM +# define FcRandom() random() +#else +# if HAVE_LRAND48 +# define FcRandom() lrand48() +# else +# if HAVE_RAND +# define FcRandom() rand() +# endif +# endif +#endif /* * Generate a random level number, distributed * so that each level is 1/4 as likely as the one before @@ -223,7 +234,7 @@ static int random_level (void) { /* tricky bit -- each bit is '1' 75% of the time */ - long int bits = random () | random (); + long int bits = FcRandom () | FcRandom (); int level = 0; while (++level < FC_CACHE_MAX_LEVEL) @@ -275,9 +286,18 @@ FcCacheInsert (FcCache *cache, struct stat *cache_stat) s->cache = cache; s->size = cache->size; s->ref = 1; - s->cache_dev = cache_stat->st_dev; - s->cache_ino = cache_stat->st_ino; - s->cache_mtime = cache_stat->st_mtime; + if (cache_stat) + { + s->cache_dev = cache_stat->st_dev; + s->cache_ino = cache_stat->st_ino; + s->cache_mtime = cache_stat->st_mtime; + } + else + { + s->cache_dev = 0; + s->cache_ino = 0; + s->cache_mtime = 0; + } /* * Insert into all fcCacheChains @@ -331,7 +351,6 @@ FcCacheRemove (FcCache *cache) update[i] = &next[i]; } s = next[0]; - assert (s->cache == cache); for (i = 0; i < fcCacheMaxLevel && *update[i] == s; i++) *update[i] = s->next[i]; while (fcCacheMaxLevel > 0 && fcCacheChains[fcCacheMaxLevel - 1] == NULL) @@ -348,7 +367,10 @@ FcCacheFindByStat (struct stat *cache_stat) if (s->cache_dev == cache_stat->st_dev && s->cache_ino == cache_stat->st_ino && s->cache_mtime == cache_stat->st_mtime) + { + s->ref++; return s->cache; + } return NULL; } @@ -656,6 +678,8 @@ FcDirCacheBuild (FcFontSet *set, const FcChar8 *dir, FcStrSet *dirs) FcSerializeDestroy (serialize); + FcCacheInsert (cache, NULL); + return cache; bail2: @@ -814,11 +838,16 @@ FcCacheCopySet args(const FcCache *c) if (!new) return NULL; for (i = 0; i < old->nfont; i++) - if (!FcFontSetAdd (new, FcFontSetFont (old, i))) + { + FcPattern *font = FcFontSetFont (old, i); + + FcPatternReference (font); + if (!FcFontSetAdd (new, font)) { FcFontSetDestroy (new); return NULL; } + } return new; } @@ -1083,3 +1112,6 @@ static void MD5Transform(FcChar32 buf[4], FcChar32 in[16]) buf[2] += c; buf[3] += d; } +#define __fccache__ +#include "fcaliastail.h" +#undef __fccache__