[cairo] [RFC] Error handling

Behdad Esfahbod behdad at behdad.org
Wed May 23 16:57:51 PDT 2007

On Tue, 2007-05-22 at 09:39 -0400, Chris Wilson wrote:
> One aspect of my recent work on performing malloc failure testing of
> cairo-test was a need to review the error handling. On the
> memfault-fixup
> branch (still not quite ready for public consumption) I have a few
> patches that attempt to consistently apply the inert object semantics.
> In order to check that I've understood the principles sufficiently,
> I've
> pulled together a document to describe error handling within Cairo.
> Please review.
> The next question is where should the document live? Should it be like
> CODING_STYLE and live in the top level or should it be transformed
> into
> part of doc/ (though I'm not sure how)?

Thanks Chris for the writeup.  I'm not sure that we want to put the
entire quotes in the git repo, but regardless, CODING_STYLE makes more
sense to me as it's mostly about internal organization of the code.

I'm more interested in improving cairo's error handling to be more
developer friendly.  Things we may want to do:

  - If input arguments are nonsensical (NULL, etc), hit a separate
function, something like _cairo_precondition_error(), and make that
write something to stderr if it's a devel build or an env var is set.

  - In _cairo_error() emit a SIGTRAP?  Unconditionally?  Under some env

  - If the debug level set through the env var is high enough, print a
backtrace in _cairo_error().

The SIGTRAP one is probably not that useful if we add the rest.  So, the
proposal is for an env var CAIRO_DEBUG that takes an integer value.  The
hard part is to go on and add precondition checks to all public APIs.

> --
> Chris Wilson 

"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