[cairo] On allowing NULL font options

Behdad Esfahbod behdad at behdad.org
Thu Jan 17 17:17:58 PST 2008

On Thu, 2008-01-17 at 17:39 -0500, Chris Wilson wrote:
>     [cairo-font-options] Treat NULL as a default cairo_font_options_t
>     Interpret a NULL cairo_font_options_t as the default values - i.e
>     as if it were a fresh pointer returned by
> cairo_font_options_create().

I thought about this before.  I think we shouldn't doing it.  Currently
the cairo practice is: no NULL.

You have started accepting NULL as valid input here and there, as UTF-8
text first and now font options.  As logical that may sound, it
increasingly suggests that NULL is actually Ok, like in many other
libraries (glib, Pango, ...).  But they have very different conventions.
For example, in cairo, you should never check for NULL return from
constructors.  If you write your code in any sensible way, then it's
just easier to say "never deal with null" than "null is ok as input, not
don't check output for null, check status instead".

Anyway, that's my main input.  If we want to allow this NULL, then need
to do the same about matrices, then other things, then people always
have to check docs to see whether NULL is valid input to one function or
not.  Like one needs to do with glib and Pango.  Sure, would be nice if
everyone accepted NULL, but the fact that cairo_create() can't ever
accept NULL usefully (because of font options, etc that need to be real
for cairo_t to be useful) makes me think we should give up the
temptation to make all cairo API NULL-friendly.

My 0.02 CAD obviously,


"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759

More information about the cairo mailing list