[PATCH 15/36] datatypes: convert virDomainCheckpoint to GObject

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/conf/virdomaincheckpointobjlist.c |  6 ++--
 src/datatypes.c                       | 44 ++++++++++++++++-----------
 src/datatypes.h                       | 14 ++++++---
 src/libvirt-domain-checkpoint.c       |  7 ++---
 src/libvirt_private.syms              |  1 -
 5 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/src/conf/virdomaincheckpointobjlist.c b/src/conf/virdomaincheckpointobjlist.c
index a4942ea706..5c457dc876 100644
--- a/src/conf/virdomaincheckpointobjlist.c
+++ b/src/conf/virdomaincheckpointobjlist.c
@@ -235,8 +235,10 @@ virDomainListCheckpoints(virDomainCheckpointObjListPtr checkpoints,
         VIR_FREE(names[i]);
     VIR_FREE(names);
     if (ret < 0 && list) {
-        for (i = 0; i < count; i++)
-            virObjectUnref(list[i]);
+        for (i = 0; i < count; i++) {
+            if (list[i])
+                g_object_unref(list[i]);
+        }
         VIR_FREE(list);
     }
     return ret;
diff --git a/src/datatypes.c b/src/datatypes.c
index 68fc216ffa..1e0861aa5f 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -36,7 +36,6 @@ VIR_LOG_INIT("datatypes");
 virClassPtr virConnectClass;
 virClassPtr virConnectCloseCallbackDataClass;
 virClassPtr virDomainClass;
-virClassPtr virDomainCheckpointClass;
 virClassPtr virDomainSnapshotClass;
 virClassPtr virInterfaceClass;
 virClassPtr virNetworkClass;
@@ -52,7 +51,6 @@ virClassPtr virStoragePoolClass;
 static void virConnectDispose(void *obj);
 static void virConnectCloseCallbackDataDispose(void *obj);
 static void virDomainDispose(void *obj);
-static void virDomainCheckpointDispose(void *obj);
 static void virDomainSnapshotDispose(void *obj);
 static void virInterfaceDispose(void *obj);
 static void virNetworkDispose(void *obj);
@@ -65,6 +63,22 @@ static void virStreamDispose(void *obj);
 static void virStorageVolDispose(void *obj);
 static void virStoragePoolDispose(void *obj);
 
+G_DEFINE_TYPE(virDomainCheckpoint, vir_domain_checkpoint, G_TYPE_OBJECT);
+static void virDomainCheckpointFinalize(GObject *obj);
+
+static void
+vir_domain_checkpoint_init(virDomainCheckpoint *dc G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_domain_checkpoint_class_init(virDomainCheckpointClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->finalize = virDomainCheckpointFinalize;
+}
+
 virClassPtr virAdmConnectClass;
 virClassPtr virAdmConnectCloseCallbackDataClass;
 
@@ -117,7 +131,6 @@ virDataTypesOnceInit(void)
     DECLARE_CLASS_LOCKABLE(virConnect);
     DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
     DECLARE_CLASS(virDomain);
-    DECLARE_CLASS(virDomainCheckpoint);
     DECLARE_CLASS(virDomainSnapshot);
     DECLARE_CLASS(virInterface);
     DECLARE_CLASS(virNetwork);
@@ -984,7 +997,7 @@ virNWFilterBindingDispose(void *obj)
  * @name: pointer to the domain checkpoint name
  *
  * Allocates a new domain checkpoint object. When the object is no longer needed,
- * virObjectUnref() must be called in order to not leak data.
+ * g_object_unref() must be called in order to not leak data.
  *
  * Returns a pointer to the domain checkpoint object, or NULL on error.
  */
@@ -992,30 +1005,25 @@ virDomainCheckpointPtr
 virGetDomainCheckpoint(virDomainPtr domain,
                        const char *name)
 {
-    virDomainCheckpointPtr ret = NULL;
+    g_autoptr(virDomainCheckpoint) ret = NULL;
 
     if (virDataTypesInitialize() < 0)
         return NULL;
 
-    virCheckDomainGoto(domain, error);
-    virCheckNonNullArgGoto(name, error);
+    virCheckDomainReturn(domain, NULL);
+    virCheckNonNullArgReturn(name, NULL);
 
-    if (!(ret = virObjectNew(virDomainCheckpointClass)))
-        goto error;
+    ret = VIR_DOMAIN_CHECKPOINT(g_object_new(VIR_TYPE_DOMAIN_CHECKPOINT, NULL));
     ret->name = g_strdup(name);
 
     ret->domain = virObjectRef(domain);
 
-    return ret;
-
- error:
-    virObjectUnref(ret);
-    return NULL;
+    return g_steal_pointer(&ret);
 }
 
 
 /**
- * virDomainCheckpointDispose:
+ * virDomainCheckpointFinalize:
  * @obj: the domain checkpoint to release
  *
  * Unconditionally release all memory associated with a checkpoint.
@@ -1025,13 +1033,15 @@ virGetDomainCheckpoint(virDomainPtr domain,
  * which may also be released if its ref count hits zero.
  */
 static void
-virDomainCheckpointDispose(void *obj)
+virDomainCheckpointFinalize(GObject *obj)
 {
-    virDomainCheckpointPtr checkpoint = obj;
+    virDomainCheckpointPtr checkpoint = VIR_DOMAIN_CHECKPOINT(obj);
     VIR_DEBUG("release checkpoint %p %s", checkpoint, checkpoint->name);
 
     VIR_FREE(checkpoint->name);
     virObjectUnref(checkpoint->domain);
+
+    G_OBJECT_CLASS(vir_domain_checkpoint_parent_class)->finalize(obj);
 }
 
 
diff --git a/src/datatypes.h b/src/datatypes.h
index 4e9f338f8b..13ad044126 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -32,7 +32,6 @@
 
 extern virClassPtr virConnectClass;
 extern virClassPtr virDomainClass;
-extern virClassPtr virDomainCheckpointClass;
 extern virClassPtr virDomainSnapshotClass;
 extern virClassPtr virInterfaceClass;
 extern virClassPtr virNetworkClass;
@@ -45,6 +44,13 @@ extern virClassPtr virStreamClass;
 extern virClassPtr virStorageVolClass;
 extern virClassPtr virStoragePoolClass;
 
+#define VIR_TYPE_DOMAIN_CHECKPOINT vir_domain_checkpoint_get_type()
+G_DECLARE_FINAL_TYPE(virDomainCheckpoint,
+                     vir_domain_checkpoint,
+                     VIR,
+                     DOMAIN_CHECKPOINT,
+                     GObject);
+
 extern virClassPtr virAdmConnectClass;
 
 #define VIR_TYPE_ADM_SERVER vir_adm_server_get_type()
@@ -327,8 +333,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
 
 #define virCheckDomainCheckpointReturn(obj, retval) \
     do { \
-        virDomainCheckpointPtr _check = (obj); \
-        if (!virObjectIsClass(_check, virDomainCheckpointClass) || \
+        virDomainCheckpointPtr _check = VIR_DOMAIN_CHECKPOINT(obj); \
+        if (!G_IS_OBJECT(_check) || !(G_OBJECT_TYPE(_check) == VIR_TYPE_DOMAIN_CHECKPOINT) || \
             !virObjectIsClass(_check->domain, virDomainClass) || \
             !virObjectIsClass(_check->domain->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_DOMAIN_CHECKPOINT, \
@@ -749,7 +755,7 @@ struct _virStream {
  * Internal structure associated with a domain checkpoint
  */
 struct _virDomainCheckpoint {
-    virObject parent;
+    GObject parent;
     char *name;
     virDomainPtr domain;
 };
diff --git a/src/libvirt-domain-checkpoint.c b/src/libvirt-domain-checkpoint.c
index 432c2d5a52..77ef434d30 100644
--- a/src/libvirt-domain-checkpoint.c
+++ b/src/libvirt-domain-checkpoint.c
@@ -535,14 +535,13 @@ virDomainCheckpointDelete(virDomainCheckpointPtr checkpoint,
 int
 virDomainCheckpointRef(virDomainCheckpointPtr checkpoint)
 {
-    VIR_DEBUG("checkpoint=%p, refs=%d", checkpoint,
-              checkpoint ? checkpoint->parent.u.s.refs : 0);
+    VIR_DEBUG("checkpoint=%p", checkpoint);
 
     virResetLastError();
 
     virCheckDomainCheckpointReturn(checkpoint, -1);
 
-    virObjectRef(checkpoint);
+    g_object_ref(checkpoint);
     return 0;
 }
 
@@ -565,6 +564,6 @@ virDomainCheckpointFree(virDomainCheckpointPtr checkpoint)
 
     virCheckDomainCheckpointReturn(checkpoint, -1);
 
-    virObjectUnref(checkpoint);
+    g_object_unref(checkpoint);
     return 0;
 }
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e276f55bb1..008d4fa08f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1349,7 +1349,6 @@ virConnectCloseCallbackDataClass;
 virConnectCloseCallbackDataGetCallback;
 virConnectCloseCallbackDataRegister;
 virConnectCloseCallbackDataUnregister;
-virDomainCheckpointClass;
 virDomainClass;
 virDomainSnapshotClass;
 virGetConnect;
-- 
2.25.1






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux