[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: Peter N. Lundblad <peter_at_famlundblad.se>
Date: 2006-07-11 15:39:45 CEST

Garrett Rooney writes:
> 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*.
> >
This means nearly every function, and since the common case for svn_error_t*
returning functions is to return NULL, I don't think this optimization
opportunity would be worth the clutter.

> > 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.

The reason for not wanting this is also the extra clutter. I think Julian Foad
made a script to automatically add this attribute so this can be
checked from time to time. (It is a useful warning, however.)

> > format_arg:
> > This function attribute declares the function as receiving a mallloc

I assume you mean printf:-)

> > 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.

I don't see why this is awful. We only have a handful of these
functions, but if you find a nice way to use this attribute here, feel
free to provide a patch.

> > 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.

Seems useful to me.

> > 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".
> >

I think giving the compiler more info to catch more bugs is valuable,
as long as it doesn't clutter the code too much. (For example,
someone had a proposal to give the compiler the opportunity to warn
for unused variables, but avoid that warning for some args like pools,
but that involved lots of macro invocations in each function which was
not nice.


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:40:25 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.