]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Allow virFileCache data to be any GObject
authorJonathon Jongsma <jjongsma@redhat.com>
Wed, 13 Jul 2022 19:55:55 +0000 (14:55 -0500)
committerJonathon Jongsma <jjongsma@redhat.com>
Tue, 19 Sep 2023 19:28:49 +0000 (14:28 -0500)
Since the libvirt documentation suggests to prefer GObject over
virObject, and since virObject is a GObject, change virFileCache to
allow GObjects as data.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/util/virfilecache.c
src/util/virfilecache.h

index c730de066eab39da5b64e36b60aba68831129c96..6f698016a1e48cc55854734c8f20746c7c26268c 100644 (file)
@@ -170,7 +170,7 @@ virFileCacheLoad(virFileCache *cache,
     *data = g_steal_pointer(&loadData);
 
  cleanup:
-    virObjectUnref(loadData);
+    g_clear_pointer(&loadData, g_object_unref);
     return ret;
 }
 
@@ -207,7 +207,7 @@ virFileCacheNewData(virFileCache *cache,
             return NULL;
 
         if (virFileCacheSave(cache, name, data) < 0) {
-            g_clear_pointer(&data, virObjectUnref);
+            g_clear_object(&data);
         }
     }
 
@@ -239,7 +239,7 @@ virFileCacheNew(const char *dir,
     if (!(cache = virObjectNew(virFileCacheClass)))
         return NULL;
 
-    cache->table = virHashNew(virObjectUnref);
+    cache->table = virHashNew(g_object_unref);
 
     cache->dir = g_strdup(dir);
 
@@ -270,7 +270,7 @@ virFileCacheValidate(virFileCache *cache,
         if (*data) {
             VIR_DEBUG("Caching data '%p' for '%s'", *data, name);
             if (virHashAddEntry(cache->table, name, *data) < 0) {
-                g_clear_pointer(data, virObjectUnref);
+                g_clear_pointer(data, g_object_unref);
             }
         }
     }
@@ -300,7 +300,8 @@ virFileCacheLookup(virFileCache *cache,
     data = virHashLookup(cache->table, name);
     virFileCacheValidate(cache, name, &data);
 
-    virObjectRef(data);
+    if (data)
+        g_object_ref(data);
     virObjectUnlock(cache);
 
     return data;
@@ -331,7 +332,8 @@ virFileCacheLookupByFunc(virFileCache *cache,
     data = virHashSearch(cache->table, iter, iterData, &name);
     virFileCacheValidate(cache, name, &data);
 
-    virObjectRef(data);
+    if (data)
+        g_object_ref(data);
     virObjectUnlock(cache);
 
     return data;
index c3bc0f529ca17931a5c28a7f973164bb1f45a22b..944741c0a7341a6c269d9119d90bc8d797ac78b7 100644 (file)
@@ -48,7 +48,7 @@ typedef bool
  * @priv: private data created together with cache
  *
  * Creates a new data based on the @name.  The returned data must be
- * an instance of virObject.
+ * an instance of GObject.
  *
  * Returns data object or NULL on error.
  */