[libvirt] [GSoC] Design ideas for implementing cleanup attribute

Andrea Bolognani abologna at redhat.com
Fri May 25 09:03:01 UTC 2018


On Fri, 2018-05-25 at 10:46 +0200, Pavel Hrdina wrote:
> On Fri, May 25, 2018 at 10:32:04AM +0200, Andrea Bolognani wrote:
> > I'm probably missing something, but couldn't you just have
> > 
> >   #define VIR_AUTOFREE(type) __attribute__((cleanup(virFree))) type
> > 
> > which you would then use as
> > 
> >     VIR_AUTOFREE(char *) string = NULL;
> > 
> > instead?
> 
> Yes you can have that as well, but it doesn't look ugly to you? :)

Quite the opposite - not only it's consistent with the other
macros, but it also cleanly separates the type from the variable
name, which I consider a plus.

Personally, even though

  char *string;

and friends are the accepted way to declare pointer variables,
I've always been slightly annoyed by the fact that type name and
variable name end up being partially mixed together.

Don't get me wrong, something like

  char* string;

would still look wrong to me, because I'm just so used to the
other way! But in the context of that macro I think we really get
the best of both worlds :)

> If majority will agree on that I don't care, just my opinion.

Yeah, same here.

-- 
Andrea Bolognani / Red Hat / Virtualization




More information about the libvir-list mailing list