Fix build problems caused by cache rework.

Pagesize no longer matters in architecture decisions, the entire cache file
is mmaped into the library. However, lots of intptr_t values are in use now,
so that value is important.

fc-lang now requires fcserialize.c, which has been added to the repository.
This commit is contained in:
Keith Packard 2006-08-30 04:24:03 -07:00
parent 7ce1967331
commit e3096d90fd
4 changed files with 165 additions and 13 deletions

View File

@ -26,9 +26,6 @@
#define ENDIAN_TEST 0x12345678 #define ENDIAN_TEST 0x12345678
#define MACHINE_SIGNATURE_SIZE (9*21 + 1) #define MACHINE_SIGNATURE_SIZE (9*21 + 1)
#define MACHINE_ARCH_SIZE 32
/* for when we don't have sysconf: */
#define FC_HARDCODED_PAGESIZE 8192
static char * static char *
FcCacheMachineSignature (void) FcCacheMachineSignature (void)
@ -44,11 +41,12 @@ FcCacheMachineSignature (void)
(unsigned int)sizeof (char), (unsigned int)sizeof (char),
(unsigned int)sizeof (char *), (unsigned int)sizeof (char *),
(unsigned int)sizeof (int), (unsigned int)sizeof (int),
(unsigned int)sizeof (intptr_t),
(unsigned int)sizeof (FcPattern), (unsigned int)sizeof (FcPattern),
(unsigned int)sizeof (FcPatternEltPtr), (unsigned int)sizeof (FcPatternEltPtr),
(unsigned int)sizeof (struct FcPatternElt *), (unsigned int)sizeof (struct FcPatternElt *),
(unsigned int)sizeof (FcPatternElt), (unsigned int)sizeof (FcPatternElt),
(unsigned int)sizeof (FcObjectPtr), (unsigned int)sizeof (FcObject),
(unsigned int)sizeof (FcValueListPtr), (unsigned int)sizeof (FcValueListPtr),
(unsigned int)sizeof (FcValue), (unsigned int)sizeof (FcValue),
(unsigned int)sizeof (FcValueBinding), (unsigned int)sizeof (FcValueBinding),
@ -59,13 +57,7 @@ FcCacheMachineSignature (void)
(unsigned int)sizeof (FcChar16), (unsigned int)sizeof (FcChar16),
(unsigned int)sizeof (FcCharLeaf), (unsigned int)sizeof (FcCharLeaf),
(unsigned int)sizeof (FcChar32), (unsigned int)sizeof (FcChar32),
(unsigned int)sizeof (FcCache), (unsigned int)sizeof (FcCache));
#if defined (HAVE_SYSCONF)
(unsigned int)sysconf(_SC_PAGESIZE)
#else
(unsigned int)FC_HARDCODED_PAGESIZE
#endif
);
return buf; return buf;
} }

View File

@ -28,8 +28,8 @@
@@@ name. Architecture names are used to construct file names, so @@@ name. Architecture names are used to construct file names, so
@@@ use something reasonable and don't include any spaces @@@ use something reasonable and don't include any spaces
@@@ @@@
@@@ name endian char char* int Pattern EltPtr Elt * Elt ObjPtr VLPtr Value Binding VL * CharSet Leaf** Char16 * Char16 Leaf Char32 Cache PageSize @@@ name endian char char* int intptr_t Pattern EltPtr Elt * Elt ObjPtr VLPtr Value Binding VL * CharSet Leaf** Char16 * Char16 Leaf Char32 Cache
x86 78563412_00000001_00000004_00000004_00000018_00000008_00000004_0000000c_00000004_00000008_0000000c_00000004_00000004_00000014_00000004_00000004_00000002_00000020_00000004_00000038_00001000 x86 78563412_00000001_00000004_00000004_00000004_00000010_00000004_00000004_00000008_00000004_00000004_0000000c_00000004_00000004_00000010_00000004_00000004_00000002_00000020_00000004_00000018
x86-64 78563412_00000001_00000008_00000004_00000020_00000010_00000008_00000018_00000004_00000010_00000010_00000004_00000008_00000020_00000008_00000008_00000002_00000020_00000004_00000040_00001000 x86-64 78563412_00000001_00000008_00000004_00000020_00000010_00000008_00000018_00000004_00000010_00000010_00000004_00000008_00000020_00000008_00000008_00000002_00000020_00000004_00000040_00001000
ppc-4k 12345678_00000001_00000004_00000004_00000018_00000008_00000004_0000000c_00000004_00000008_00000010_00000004_00000004_00000014_00000004_00000004_00000002_00000020_00000004_00000038_00001000 ppc-4k 12345678_00000001_00000004_00000004_00000018_00000008_00000004_0000000c_00000004_00000008_00000010_00000004_00000004_00000014_00000004_00000004_00000002_00000020_00000004_00000038_00001000
ppc-64k 12345678_00000001_00000004_00000004_00000018_00000008_00000004_0000000c_00000004_00000008_00000010_00000004_00000004_00000014_00000004_00000004_00000002_00000020_00000004_00000038_00010000 ppc-64k 12345678_00000001_00000004_00000004_00000018_00000008_00000004_0000000c_00000004_00000008_00000010_00000004_00000004_00000014_00000004_00000004_00000002_00000020_00000004_00000038_00010000

View File

@ -25,6 +25,7 @@
#include "fcint.h" #include "fcint.h"
#include "fccharset.c" #include "fccharset.c"
#include "fcstr.c" #include "fcstr.c"
#include "fcserialize.c"
/* /*
* fc-lang * fc-lang

159
src/fcserialize.c Normal file
View File

@ -0,0 +1,159 @@
/*
* Copyright © 2006 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include "fcint.h"
typedef union _FcAlign {
double d;
int i;
intptr_t ip;
off_t o;
FcBool b;
void *p;
} FcAlign;
intptr_t
FcAlignSize (intptr_t size)
{
intptr_t rem = size % sizeof (FcAlign);
if (rem)
size += sizeof (FcAlign) - rem;
return size;
}
/*
* Serialization helper object -- allocate space in the
* yet-to-be-created linear array for a serialized font set
*/
FcSerialize *
FcSerializeCreate (void)
{
FcSerialize *serialize;
serialize = malloc (sizeof (FcSerialize));
if (!serialize)
return NULL;
serialize->size = 0;
serialize->linear = NULL;
memset (serialize->buckets, '\0', sizeof (serialize->buckets));
return serialize;
}
void
FcSerializeDestroy (FcSerialize *serialize)
{
uintptr_t bucket;
for (bucket = 0; bucket < FC_SERIALIZE_HASH_SIZE; bucket++)
{
FcSerializeBucket *buck, *next;
for (buck = serialize->buckets[bucket]; buck; buck = next) {
next = buck->next;
free (buck);
}
}
free (serialize);
}
/*
* Allocate space for an object in the serialized array. Keep track
* of where the object is placed and only allocate one copy of each object
*/
FcBool
FcSerializeAlloc (FcSerialize *serialize, const void *object, int size)
{
uintptr_t bucket = ((uintptr_t) object) % FC_SERIALIZE_HASH_SIZE;
FcSerializeBucket *buck;
for (buck = serialize->buckets[bucket]; buck; buck = buck->next)
if (buck->object == object)
return FcTrue;
buck = malloc (sizeof (FcSerializeBucket));
if (!buck)
return FcFalse;
buck->object = object;
buck->offset = serialize->size;
buck->next = serialize->buckets[bucket];
serialize->buckets[bucket] = buck;
serialize->size += FcAlignSize (size);
return FcTrue;
}
/*
* Reserve space in the serialization array
*/
intptr_t
FcSerializeReserve (FcSerialize *serialize, int size)
{
intptr_t offset = serialize->size;
serialize->size += FcAlignSize (size);
return offset;
}
/*
* Given an object, return the offset in the serialized array where
* the serialized copy of the object is stored
*/
intptr_t
FcSerializeOffset (FcSerialize *serialize, const void *object)
{
uintptr_t bucket = ((uintptr_t) object) % FC_SERIALIZE_HASH_SIZE;
FcSerializeBucket *buck;
for (buck = serialize->buckets[bucket]; buck; buck = buck->next)
if (buck->object == object)
return buck->offset;
return 0;
}
/*
* Given a cache and an object, return a pointer to where
* the serialized copy of the object is stored
*/
void *
FcSerializePtr (FcSerialize *serialize, const void *object)
{
intptr_t offset = FcSerializeOffset (serialize, object);
if (!offset)
return NULL;
return (void *) ((char *) serialize->linear + offset);
}
FcBool
FcStrSerializeAlloc (FcSerialize *serialize, const FcChar8 *str)
{
return FcSerializeAlloc (serialize, str, strlen ((const char *) str) + 1);
}
FcChar8 *
FcStrSerialize (FcSerialize *serialize, const FcChar8 *str)
{
FcChar8 *str_serialize = FcSerializePtr (serialize, str);
if (!str_serialize)
return NULL;
strcpy ((char *) str_serialize, (const char *) str);
return str_serialize;
}