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(a)redhat.com>
---
src/util/virfilecache.c | 14 ++++++++------
src/util/virfilecache.h | 2 +-
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c
index bad37c9f00..eaedf6db7e 100644
--- a/src/util/virfilecache.c
+++ b/src/util/virfilecache.c
@@ -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;
diff --git a/src/util/virfilecache.h b/src/util/virfilecache.h
index 81be8feef5..f0d220cc86 100644
--- a/src/util/virfilecache.h
+++ b/src/util/virfilecache.h
@@ -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.
*/
--
2.37.3