Re: Lifetime of strings from FcPatternGetString

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On Tue, 2008-07-08 at 15:37 -0700, Sairus Patel wrote:
> Hello all,
> It’s not clear from the FC documentation how long we can expect a
> string returned from a pattern by FcPatternGetString to remain valid.

You shouldn't count on them being valid any longer than the pattern is

> The doc does say that FcPatternGetString provides a pointer to the
> actual string within the pattern, but as in the code snippet below,
> the pattern is destroyed but I've observed that the returned filename
> value seems to remain usable.

The strings will have varying lifetimes depending on what kind of
pattern you're using. 

Patterns from font files are live as long as that directory cache is
mapped, which is generally the same as the application lifetime unless
the directory is rescanned. Of course, any patterns in use by the
application will hold the whole directory content from being freed.

Patterns created by the user will end up with strings that are dumped
into a shared data structure, and so they have lifetime equal to the
program itself.

> Am I purely lucky that the memory is still valid, or are these strings
> “atoms” i.e. strings that remain valid for the entire lifetime of
> FontConfig? Is this documented anywhere?

Most of the time, the strings will persist, but strings in patterns
loaded from disk can go away when the pattern is freed. "don't do that".
Note that these patterns are entirely shared, so it's almost free
(again, except when the directory is rescanned) to hold a reference to
the pattern if you need to store the string somewhere.


Attachment: signature.asc
Description: This is a digitally signed message part

Fontconfig mailing list

[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux