[cairo] error handling

Behdad Esfahbod behdad at behdad.org
Tue May 29 14:47:08 PDT 2007


On Tue, 2007-05-29 at 11:10 +0100, Baz wrote:
> 
> There's two problems here: the scaled font was in an error state, and
> that didn't propogate to the cairo_t; and the scaled font was in an
> error state for no good reason, we should have returned a status_t
> instead. The first problem is something we should just fix, right?

Right.  And Chris's patch does this I assume.


> The policy on when to return a status_t is bit vague though. I can
> understand a policy where operations that shouldn't affect cairo's
> state fail this way - this is what's happened to the getters, and
> would work for glyph_extents, text_extents, text_to_glyphs. I see less
> distinction between a failure in cairo_text_path and, say,
> cairo_append_path though?

Why?  If the programmer writes the code correctly, there is no way
cairo_append_path() would fail.  cairo_text_path() on the other hand can
easily "fail" if the programmer reads valid UTF-8 from user and passes
it to cairo_text_path(), simply because the font doesn't cover all
characters.  It should be forgiven, but also give programmer the option
to detect it.


> Oh while we're at it - get_current_point should return a status_t too
> :) (I think this has been discussed before)

Yes.


> I'll work up some patches to give us something more concrete to look
> at.

Great.  We've been talking about these for ages.  Other candidates for
change in the future are cairo_device_to_user() and
cairo_device_to_user_distance(), for when you set a non-invertible
matrix on cairo_t, but for now, doing so puts cairo_t in error status,
so we need to fix that first (which is not easy, btw).

I also remember some discussion about making _destroy() functions return
status.  Not sure what the conclusion there was.  BTW, Chris, how's
cairo_object_t work going?

You may want to dig previous discussion threads and/or cairo.def for
other cases that can use a status return.


> Cheers,
> Baz 
-- 
behdad
http://behdad.org/

"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