On 26.02.2015 16:46, Peter Krempa wrote:
On Thu, Feb 26, 2015 at 15:17:17 +0100, Michal Privoznik wrote:
> In order to hide the object internals (and use just accessors
> everywhere), lets store a pointer to the object, instead of object
> itself.
>
> Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
> ---
> src/test/test_driver.c | 106 ++++++++++++++++++++++++-------------------------
> 1 file changed, 51 insertions(+), 55 deletions(-)
>
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index e2da1e2..90df0e7 100644
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -101,7 +101,7 @@ struct _testConn {
> virDomainXMLOptionPtr xmlopt;
> virNodeInfo nodeInfo;
> virDomainObjListPtr domains;
> - virNetworkObjList networks;
> + virNetworkObjListPtr networks;
> virInterfaceObjList ifaces;
> bool transaction_running;
> virInterfaceObjList backupIfaces;
> @@ -115,7 +115,7 @@ struct _testConn {
> virObjectEventStatePtr eventState;
> };
> typedef struct _testConn testConn;
> -typedef struct _testConn *testConnPtr;
> +typedef testConn *testConnPtr;
>
> static testConn defaultConn;
> static int defaultConnections;
> @@ -724,7 +724,8 @@ testOpenDefault(virConnectPtr conn)
> if (!(privconn->eventState = virObjectEventStateNew()))
> goto error;
>
> - if (!(privconn->domains = virDomainObjListNew()))
> + if (!(privconn->domains = virDomainObjListNew()) ||
> + VIR_ALLOC(privconn->networks) < 0)
> goto error;
Since you are going to convert the network structure to an objec
wouldn't it be better to add a constructor for the object right away
instead of having to do it later once you hide the struct?
That's just cosmetics IMO. The only benefit would be that the commit
turning the struct into virObject would be a few lines shorter. /me goes
and check how many VIR_ALLOCs are added in these patches. Er, two for
virNetworkObj, and 4 for virNetworkObjList. So in the end we would save
up 6 lines. I can do that if you think it's worth it though.
Michal