[PATCH v2 11/40] conf: convert virDomainCapsCPUModels to GObject

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/conf/domain_capabilities.c | 48 ++++++++++++++++++----------------
 src/conf/domain_capabilities.h | 10 ++++---
 src/libvirt_private.syms       |  1 +
 tests/cputest.c                | 35 ++++++++-----------------
 4 files changed, 44 insertions(+), 50 deletions(-)

diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index 921d795630..bc0a505cb9 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -45,19 +45,27 @@ VIR_ENUM_IMPL(virDomainCapsFeature,
 );
 
 static virClassPtr virDomainCapsClass;
-static virClassPtr virDomainCapsCPUModelsClass;
+G_DEFINE_TYPE(virDomainCapsCPUModels, vir_domain_caps_cpu_models, G_TYPE_OBJECT);
 
 static void virDomainCapsDispose(void *obj);
-static void virDomainCapsCPUModelsDispose(void *obj);
+static void virDomainCapsCPUModelsFinalize(GObject *obj);
+
+static void vir_domain_caps_cpu_models_init(virDomainCapsCPUModels *mod G_GNUC_UNUSED)
+{
+}
+
+static void vir_domain_caps_cpu_models_class_init(virDomainCapsCPUModelsClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->finalize = virDomainCapsCPUModelsFinalize;
+}
 
 static int virDomainCapsOnceInit(void)
 {
     if (!VIR_CLASS_NEW(virDomainCaps, virClassForObjectLockable()))
         return -1;
 
-    if (!VIR_CLASS_NEW(virDomainCapsCPUModels, virClassForObject()))
-        return -1;
-
     return 0;
 }
 
@@ -107,9 +115,9 @@ virDomainCapsDispose(void *obj)
 
 
 static void
-virDomainCapsCPUModelsDispose(void *obj)
+virDomainCapsCPUModelsFinalize(GObject *obj)
 {
-    virDomainCapsCPUModelsPtr cpuModels = obj;
+    virDomainCapsCPUModelsPtr cpuModels = VIR_DOMAIN_CAPS_CPU_MODELS(obj);
     size_t i;
 
     for (i = 0; i < cpuModels->nmodels; i++) {
@@ -118,6 +126,8 @@ virDomainCapsCPUModelsDispose(void *obj)
     }
 
     VIR_FREE(cpuModels->models);
+
+    G_OBJECT_CLASS(vir_domain_caps_cpu_models_parent_class)->finalize(obj);
 }
 
 
@@ -147,30 +157,26 @@ virDomainCapsNew(const char *path,
 virDomainCapsCPUModelsPtr
 virDomainCapsCPUModelsNew(size_t nmodels)
 {
-    virDomainCapsCPUModelsPtr cpuModels = NULL;
+    g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
 
     if (virDomainCapsInitialize() < 0)
         return NULL;
 
-    if (!(cpuModels = virObjectNew(virDomainCapsCPUModelsClass)))
-        return NULL;
+    cpuModels = VIR_DOMAIN_CAPS_CPU_MODELS(
+            g_object_new(VIR_TYPE_DOMAIN_CAPS_CPU_MODELS, NULL));
 
     if (VIR_ALLOC_N(cpuModels->models, nmodels) < 0)
-        goto error;
+        return NULL;
     cpuModels->nmodels_max = nmodels;
 
-    return cpuModels;
-
- error:
-    virObjectUnref(cpuModels);
-    return NULL;
+    return g_steal_pointer(&cpuModels);
 }
 
 
 virDomainCapsCPUModelsPtr
 virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr old)
 {
-    virDomainCapsCPUModelsPtr cpuModels;
+    g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
     size_t i;
 
     if (!(cpuModels = virDomainCapsCPUModelsNew(old->nmodels)))
@@ -181,14 +187,10 @@ virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr old)
                                       old->models[i].name,
                                       old->models[i].usable,
                                       old->models[i].blockers) < 0)
-            goto error;
+            return NULL;
     }
 
-    return cpuModels;
-
- error:
-    virObjectUnref(cpuModels);
-    return NULL;
+    return g_steal_pointer(&cpuModels);
 }
 
 
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index 9f4a23d015..88673ffe35 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -129,17 +129,21 @@ struct _virDomainCapsCPUModel {
     char **blockers; /* NULL-terminated list of usability blockers */
 };
 
-typedef struct _virDomainCapsCPUModels virDomainCapsCPUModels;
+#define VIR_TYPE_DOMAIN_CAPS_CPU_MODELS vir_domain_caps_cpu_models_get_type()
+G_DECLARE_FINAL_TYPE(virDomainCapsCPUModels,
+                     vir_domain_caps_cpu_models,
+                     VIR,
+                     DOMAIN_CAPS_CPU_MODELS,
+                     GObject);
 typedef virDomainCapsCPUModels *virDomainCapsCPUModelsPtr;
 struct _virDomainCapsCPUModels {
-    virObject parent;
+    GObject parent;
 
     size_t nmodels_max;
     size_t nmodels;
     virDomainCapsCPUModelPtr models;
 };
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainCapsCPUModels, virObjectUnref);
 
 typedef struct _virDomainCapsCPU virDomainCapsCPU;
 typedef virDomainCapsCPU *virDomainCapsCPUPtr;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 043a3afae8..33ee7069de 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -204,6 +204,7 @@ virDomainAuditVcpu;
 
 
 # conf/domain_capabilities.h
+vir_domain_caps_cpu_models_get_type;
 virDomainCapsCPUModelsAdd;
 virDomainCapsCPUModelsCopy;
 virDomainCapsCPUModelsGet;
diff --git a/tests/cputest.c b/tests/cputest.c
index 0a91892f4e..ad19721717 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -571,7 +571,7 @@ cpuTestCPUID(bool guest, const void *arg)
     char *host = NULL;
     virCPUDefPtr cpu = NULL;
     char *result = NULL;
-    virDomainCapsCPUModelsPtr models = NULL;
+    g_autoptr(virDomainCapsCPUModels) models = NULL;
 
     hostFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir,
                                virArchToString(data->arch), data->host);
@@ -613,7 +613,6 @@ cpuTestCPUID(bool guest, const void *arg)
     virCPUDataFree(hostData);
     virCPUDefFree(cpu);
     VIR_FREE(result);
-    virObjectUnref(models);
     return ret;
 }
 
@@ -785,8 +784,8 @@ cpuTestUpdateLive(const void *arg)
     virCPUDataPtr disabledData = NULL;
     char *expectedFile = NULL;
     virCPUDefPtr expected = NULL;
-    virDomainCapsCPUModelsPtr hvModels = NULL;
-    virDomainCapsCPUModelsPtr models = NULL;
+    g_autoptr(virDomainCapsCPUModels) hvModels = NULL;
+    g_autoptr(virDomainCapsCPUModels) models = NULL;
     int ret = -1;
 
     cpuFile = g_strdup_printf("cpuid-%s-guest", data->host);
@@ -862,8 +861,6 @@ cpuTestUpdateLive(const void *arg)
     virCPUDataFree(disabledData);
     VIR_FREE(expectedFile);
     virCPUDefFree(expected);
-    virObjectUnref(hvModels);
-    virObjectUnref(models);
     return ret;
 }
 
@@ -935,7 +932,7 @@ static const char *ppc_models_list[] = { "POWER6", "POWER7", "POWER8", NULL };
 static virDomainCapsCPUModelsPtr
 cpuTestInitModels(const char **list)
 {
-    virDomainCapsCPUModelsPtr cpus;
+    g_autoptr(virDomainCapsCPUModels) cpus = NULL;
     const char **model;
 
     if (!(cpus = virDomainCapsCPUModelsNew(0)))
@@ -944,25 +941,21 @@ cpuTestInitModels(const char **list)
     for (model = list; *model; model++) {
         if (virDomainCapsCPUModelsAdd(cpus, *model,
                                       VIR_DOMCAPS_CPU_USABLE_UNKNOWN, NULL) < 0)
-            goto error;
+            return NULL;
     }
 
-    return cpus;
-
- error:
-    virObjectUnref(cpus);
-    return NULL;
+    return g_steal_pointer(&cpus);
 }
 
 
 static int
 mymain(void)
 {
-    virDomainCapsCPUModelsPtr model486 = NULL;
-    virDomainCapsCPUModelsPtr nomodel = NULL;
-    virDomainCapsCPUModelsPtr models = NULL;
-    virDomainCapsCPUModelsPtr haswell = NULL;
-    virDomainCapsCPUModelsPtr ppc_models = NULL;
+    g_autoptr(virDomainCapsCPUModels) model486 = NULL;
+    g_autoptr(virDomainCapsCPUModels) nomodel = NULL;
+    g_autoptr(virDomainCapsCPUModels) models = NULL;
+    g_autoptr(virDomainCapsCPUModels) haswell = NULL;
+    g_autoptr(virDomainCapsCPUModels) ppc_models = NULL;
     int ret = 0;
 
 #if WITH_QEMU
@@ -1273,12 +1266,6 @@ mymain(void)
     qemuTestDriverFree(&driver);
 #endif
 
-    virObjectUnref(model486);
-    virObjectUnref(nomodel);
-    virObjectUnref(models);
-    virObjectUnref(haswell);
-    virObjectUnref(ppc_models);
-
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-- 
2.25.3






[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