On Fri, May 25, 2018 at 11:03:01AM +0200, Andrea Bolognani wrote: > 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. I also like the alternative approach Andrea mentioned, especially since you can reuse it for structures using plain scalar types, e.g. a structure like typedef _virSomething virSomething; typedef virSomething * virSomethingPtr; struct _virSomething { int a; long b; bool c; }; ..where you don't really need to use VIR_AUTOPTR's complex clean functions since a simple virFree works just fine and it lets you to stay consistent with the usage of XPtr types which has also been mentioned already, just my 2c. Erik -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list