[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Function attributes

From: Garrett Rooney <rooneg_at_electricjellyfish.net>
Date: 2006-07-11 15:20:01 CEST

On 7/10/06, Nicolás Lichtmaier <nick@reloco.com.ar> wrote:
> I think Subversion code can benefit from the use of some function
> attributes. These are some that seem to be appropiate:
>
> malloc:
> This one marks the function as returning a newly allocated memory
> area (which ensures that no already existing pointer aliases this new
> pointer). I think it could be aplied to every function returning
> svn_error_t*.
>
> warn_unused_result:
> This one instruct gcc to give a warning if the returned value is
> discared. This too can be used with functions returning svn_error_t*, as
> it's a memory leak not to handle its return value.
>
> format_arg:
> This function attribute declares the function as receiving a mallloc
> style string. This is used in conjuction with gettext, so that xgettext
> can properly mark the strings as being printf format strings. Currently
> subversion lists all these functions when invoking xgettext, this is awful.
>
> sentinel:
> Ensures that the last parameter in a variadic function is NULL.
> There are many functions that expect this. This catches a silly but
> common error.
>
> APR defines __atribute__(x) to nothingif not in GCC, but many of these
> attributes are only implemented in recent gcc versions, as such this
> support is not sufficient. The proper way of doing this is by using
> defines like SVN_GCC_WARN_UNUSED_RESULT or SVN_GCC_SENTINEL, which would
> know what to do and when. This don't need to be done for attributes that
> has been implemented in GCC for ever, like "printf" or (I think) "malloc".
>
> What do you think? Is there value in this? If not I could find another
> hobbie =).

We actually had a discussion about the warn_unused_result one a while
back, and I believe ended up deciding not to add it for one reason or
another. Search the archives for more info. The others might be more
practical since they're less invasive, warn_unused_result basically
needed to be added to every single function for it to be helpful.

-garrett

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Jul 11 15:20:32 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.