[libvirt] [PATCH v2 11/11] interface: Alter virInterfaceObjListAssignDef @def param

John Ferlan posted 11 patches 8 years, 8 months ago
There is a newer version of this series
[libvirt] [PATCH v2 11/11] interface: Alter virInterfaceObjListAssignDef @def param
Posted by John Ferlan 8 years, 8 months ago
Rather than pass by value, let's pass by reference since the object ends
up "owning" the XML definition, let's make that ownership a bit more real.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/conf/virinterfaceobj.c | 12 +++++++-----
 src/conf/virinterfaceobj.h |  2 +-
 src/test/test_driver.c     |  5 ++---
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index 51c3c82..f7352d2 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -235,8 +235,10 @@ virInterfaceObjListClone(virInterfaceObjListPtr interfaces)
         }
 
         VIR_FREE(xml);
-        if (!(obj = virInterfaceObjListAssignDef(dest, backup)))
+        if (!(obj = virInterfaceObjListAssignDef(dest, &backup))) {
+            virInterfaceDefFree(backup);
             goto error;
+        }
         virInterfaceObjEndAPI(&obj);
     }
 
@@ -250,13 +252,13 @@ virInterfaceObjListClone(virInterfaceObjListPtr interfaces)
 
 virInterfaceObjPtr
 virInterfaceObjListAssignDef(virInterfaceObjListPtr interfaces,
-                             virInterfaceDefPtr def)
+                             virInterfaceDefPtr *def)
 {
     virInterfaceObjPtr obj;
 
-    if ((obj = virInterfaceObjListFindByName(interfaces, def->name))) {
+    if ((obj = virInterfaceObjListFindByName(interfaces, (*def)->name))) {
         virInterfaceDefFree(obj->def);
-        obj->def = def;
+        VIR_STEAL_PTR(obj->def, *def);
 
         return obj;
     }
@@ -270,7 +272,7 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr interfaces,
         return NULL;
     }
 
-    obj->def = def;
+    VIR_STEAL_PTR(obj->def, *def);
     return virObjectRef(obj);
 
 }
diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h
index 2b9e1b2..0000ee9 100644
--- a/src/conf/virinterfaceobj.h
+++ b/src/conf/virinterfaceobj.h
@@ -65,7 +65,7 @@ virInterfaceObjListClone(virInterfaceObjListPtr interfaces);
 
 virInterfaceObjPtr
 virInterfaceObjListAssignDef(virInterfaceObjListPtr interfaces,
-                             virInterfaceDefPtr def);
+                             virInterfaceDefPtr *def);
 
 void
 virInterfaceObjListRemove(virInterfaceObjListPtr interfaces,
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index fb95319..4b4a782 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1021,7 +1021,7 @@ testParseInterfaces(testDriverPtr privconn,
         if (!def)
             goto error;
 
-        if (!(obj = virInterfaceObjListAssignDef(privconn->ifaces, def))) {
+        if (!(obj = virInterfaceObjListAssignDef(privconn->ifaces, &def))) {
             virInterfaceDefFree(def);
             goto error;
         }
@@ -3903,9 +3903,8 @@ testInterfaceDefineXML(virConnectPtr conn,
     if (!(def = virInterfaceDefParseString(xmlStr)))
         goto cleanup;
 
-    if ((obj = virInterfaceObjListAssignDef(privconn->ifaces, def)) == NULL)
+    if (!(obj = virInterfaceObjListAssignDef(privconn->ifaces, &def)))
         goto cleanup;
-    def = NULL;
     objdef = virInterfaceObjGetDef(obj);
 
     ret = virGetInterface(conn, objdef->name, objdef->mac);
-- 
2.9.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 11/11] interface: Alter virInterfaceObjListAssignDef @def param
Posted by Peter Krempa 8 years, 8 months ago
On Fri, May 26, 2017 at 07:59:10 -0400, John Ferlan wrote:
> Rather than pass by value, let's pass by reference since the object ends
> up "owning" the XML definition, let's make that ownership a bit more real.
> 
> Signed-off-by: John Ferlan <jferlan@redhat.com>
> ---
>  src/conf/virinterfaceobj.c | 12 +++++++-----
>  src/conf/virinterfaceobj.h |  2 +-
>  src/test/test_driver.c     |  5 ++---
>  3 files changed, 10 insertions(+), 9 deletions(-)

As said in the previous series. This is introducing a lot of complexity
tue to the double pointers and really is not very helpful in making the
code understandable.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 11/11] interface: Alter virInterfaceObjListAssignDef @def param
Posted by John Ferlan 8 years, 8 months ago

On 05/26/2017 08:55 AM, Peter Krempa wrote:
> On Fri, May 26, 2017 at 07:59:10 -0400, John Ferlan wrote:
>> Rather than pass by value, let's pass by reference since the object ends
>> up "owning" the XML definition, let's make that ownership a bit more real.
>>
>> Signed-off-by: John Ferlan <jferlan@redhat.com>
>> ---
>>  src/conf/virinterfaceobj.c | 12 +++++++-----
>>  src/conf/virinterfaceobj.h |  2 +-
>>  src/test/test_driver.c     |  5 ++---
>>  3 files changed, 10 insertions(+), 9 deletions(-)
> 
> As said in the previous series. This is introducing a lot of complexity
> tue to the double pointers and really is not very helpful in making the
> code understandable.
> 

As in nodedev, I can drop this one. Dropping one at the end of these
series is a whole lot easier that one earlier when it comes to merge
conflict resolution.

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list