glib: Fix named destinations

Named destinations may be described by bytestrings, containing
embedded NULs and not being NUL terminated. That means they cannot
be exposed directly as char*.

The alternatives are to escape the string from the internal representation
when exposing it in the API (e.g. in PopplerDest.named_dest), or to
add parallel API exposing it as GString, or GBytes. This patch chooses
the first option, since the presence of these named destionations in the
public, not sealed, PopplerDest struct means that the second option would
need more API additions. The chosen option is simpler, and does not
need the API users to adapt unless they create the named dest strings
themselves, or consume them in ways other than calling poppler APIs.

The escaping scheme chosen simply replaces embedded NUL with "\0" and
escapes a literal backslash with "\\".  This is a minimal ABI change in
that some strings that previously worked unchanged as destinations
(those containing backslash) now don't work, but on the other hand,
previously it was impossible to use any destinations containing embedded

Add poppler_named_dest_{from,to}_bytestring() to perform that
conversion, and clarify the documentation for when you need them.

Based on a patch by José Aliste <>.
5 files changed