Module ptr

Source
Expand description

Pointers and offset’s within fontconfig’s cache.

Fontconfig’s cache is stuctured as a collection of structs. These structs are encoded in the cache by writing their bytes into a cache file. (So the format is architecture-dependent.) The structs reference each other using relative offsets, so for example in the struct

struct FcPattern {
    int num;
    int size;
    intptr_t elts_offset;
    int ref;
}

the elements num, size, and ref are just plain old data, and the element elts_offset says that there is some other struct (which happens to be an FcPatternElt in this case) stored at the location base_offset + elts_offset, where base_offset is the offset of the FcPattern. Note that elts_offset is signed: it can be negative.

We encode these offsets using Offset, so for example the struct above gets translated to

struct PatternData {
    num: c_int,
    size: c_int,
    elts_offset: Offset<PatternElt>,
    ref: c_int,
}

Sometimes, the structs in fontconfig contain pointers instead of offsets, like for example

struct FcPatternElt {
    FcObject object;
    FcValueList *values;
}

In this case, fontconfig actually handles two cases: if the lowest-order bit of values is 0 it’s treated as a normal pointer, but if the lowest-order bit is 1 then that bit is set to zero and values is treated as an offset. When the struct came from a cache file that was serialized to disk (which we always are in this crate), it should always be in the “offset” case. That is, these pointers get treated almost the same as offsets, except that we need to sanity-check the low-order bit and then set it to zero. We encode these as PtrOffset, so for example the struct above gets translated to

struct PatternEltData {
    object: c_int,
    values: PtrOffset<ValueList>,
}

Structs§

Array
A reference to an array of serialized fontconfig structs.
Offset
A relative offset to another struct in the cache.
Ptr
A reference to a fontconfig struct that’s been serialized in a buffer.
PtrOffset
A relative offset to another struct in the cache, which is encoded as a pointer in fontconfig.

Traits§

IntoOffset
This is basically equivalent to TryInto<Offset<T>, Error=Error>, but having this alias makes type inference work better.