[cairo] Add attribute(warn_unused_result)
behdad at behdad.org
Wed Mar 21 11:41:31 PDT 2007
On Wed, 2007-03-21 at 12:51 -0400, Chris Wilson wrote:
> This adds a compiler check that the function result is used by the
> caller and enables it by default for all cairo_private functions and
> for public API that returns a cairo_status_t.
> Unfortunately, I have found no way to disable the spurious warnings
> from gcc when applying the attribute to variables or functions
> returning void. To placate gcc, new function types have been
> introduced to manually avoid the warning. So we now have
> cairo_public_warn/cairo_public and cairo_private/cairo_private_no_warn
> - choosen as the majority of internal functions should be checking for
> errors!, whereas only a minority of the public API requires an
> immediate error check.
> To extend the warning to all functions, a new function type has been
> introduced to cover static functions:
This is very neat stuff... I like the idea of marking every function
with a variant of cairo_public, cairo_private, and cairo_static. The
part I don't like is where those markings are placed. cairo_static
comes at function declaration site, while the others come at the
prototype, and for cairo_public, a slim_hidden should follow the
definition... May not be easy to improve these. In an ideal world, we
won't have to mark them at all:
- Symbols starting with cairo_ are public
- Symbols starting with _cairo_ are private
- All other symbols are static
But go get that in C...
The only part I really displike is the "cairo_private_no_warn void".
While cairo_private_no_warn is useful for other places too, can we have
a cairo_private_void instead?
Also note that we already #define __attribute__() if not using gcc, so
some of the checks may be relaxed, but that's not a big deal.
Anyway, I really hope Carl gets to throwing in his wisdom and get your
stuff polished and committed before they rot.
"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