On Fri, 2018-05-25 at 11:17 +0200, Erik Skultety wrote:
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.
I have to disagree here: I think every virSomething should have
a corresponding virSomethingFree() function, even when it ends up
doing nothing but calling VIR_FREE() or virObjectUnref().
Even when automatic cleaning will be in place, there will still
be cases in which you have to allocate an object and return it
for the caller to free, and not having to look up what specific
free function needs to be used because you can rely on the
existence of a consistently named one is a big plus in my book.
We're pretty bad at this already, let's not make it worse :)
--
Andrea Bolognani / Red Hat / Virtualization