[cairo] error handling questions

Behdad Esfahbod behdad at behdad.org
Sun Jul 1 12:47:18 PDT 2007

On Mon, 2007-06-18 at 16:52 -0400, Vladimir Vukicevic wrote:
> We've been using CAIRO_STATUS_NO_MEMORY as "unknown error" in a bunch of 
> places; I know that it's generally been the policy to use a real error 
> code, but would anyone mind if I were to introduce 
> distinguish between real OOM and unknown errors?

I'm in favor.

> Also, I'd like to add a bunch of #define's for the status messages that, 
> for debug builds, do something like:
> static cairo_status_t
> _cairo_return_error(cairo_status_t status)
> {
>    return status;
> }
> #define CAIRO_STATUS_NO_MEMORY (_cairo_return_error(CAIRO_STATUS_NO_MEMORY))
> etc.
> to make it possible to set a breakpoint at the spot where the error is 
> returned.  I'm not married to this approach, but right now it's hard to 
> figure out where an error is getting signaled upstream, and this seemed 
> like the easiest way to do it and avoid having to change a bunch of 
> existing code ("return CAIRO_STATUS_FOO;").

Any place that an error is initiated should call _cairo_error().  it's
not like that for many error paths right now and those should be fixed.
We don't have a strict rule though, I'm sure there are cases that
_cairo_error should not be called (for UNSUPPORTED only?).  Carl may
know how this is supposed to work, but I agree that our error handling
is still a bit messy.  Maybe Chris can do some magic using his valgrind
skins?  We probably need to go over all CAIRO_STATUS_* instance in the
code and double check it.

Also, feel free to make _cairo_error() do something if CAIRO_DEBUG env
var is set.  Options are raising SIGTRAP and printing a backtrace.  Back
to the old question: should we differentiate between debug and
production builds?  I'd say no.  Fontconfig respects FC_DEBUG in all
builds and it has been very handy.  The only thing I don't like here is
that to produce useful backtraces we need to use Jeff's

> Thoughts?
>      - Vlad


"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