The string is not so large, we avoid fragmentation and duplication (especially in hashtable) --- libvirt-gobject/libvirt-gobject-connection.c | 12 +++++----- libvirt-gobject/libvirt-gobject-domain.c | 26 ++++++++++++++++------ libvirt-gobject/libvirt-gobject-domain.h | 2 +- libvirt-gobject/libvirt-gobject-network-filter.c | 26 ++++++++++++++++------ libvirt-gobject/libvirt-gobject-network-filter.h | 2 +- libvirt-gobject/libvirt-gobject-network.c | 24 ++++++++++++++------ libvirt-gobject/libvirt-gobject-network.h | 2 +- libvirt-gobject/libvirt-gobject-secret.c | 26 ++++++++++++++++------ libvirt-gobject/libvirt-gobject-secret.h | 2 +- libvirt-gobject/libvirt-gobject-storage-pool.c | 26 ++++++++++++++++------ libvirt-gobject/libvirt-gobject-storage-pool.h | 2 +- 11 files changed, 104 insertions(+), 46 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 4cbebe0..e99a08d 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -502,7 +502,7 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn, doms = g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, + NULL, g_object_unref); for (i = 0 ; i < nactive ; i++) { @@ -519,7 +519,7 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn, NULL)); g_hash_table_insert(doms, - gvir_domain_get_uuid(dom), + (gpointer)gvir_domain_get_uuid(dom), dom); } @@ -537,7 +537,7 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn, NULL)); g_hash_table_insert(doms, - gvir_domain_get_uuid(dom), + (gpointer)gvir_domain_get_uuid(dom), dom); } @@ -637,7 +637,7 @@ gboolean gvir_connection_fetch_storage_pools(GVirConnection *conn, NULL)); g_hash_table_insert(pools, - gvir_storage_pool_get_uuid(pool), + (gpointer)gvir_storage_pool_get_uuid(pool), pool); } @@ -657,7 +657,7 @@ gboolean gvir_connection_fetch_storage_pools(GVirConnection *conn, NULL)); g_hash_table_insert(pools, - gvir_storage_pool_get_uuid(pool), + (gpointer)gvir_storage_pool_get_uuid(pool), pool); } @@ -1060,7 +1060,7 @@ GVirDomain *gvir_connection_create_domain(GVirConnection *conn, g_mutex_lock(priv->lock); g_hash_table_insert(priv->domains, - gvir_domain_get_uuid(domain), + (gpointer)gvir_domain_get_uuid(domain), domain); g_mutex_unlock(priv->lock); diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 001c787..41545f2 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -39,6 +39,7 @@ extern gboolean debugFlag; struct _GVirDomainPrivate { virDomainPtr handle; + gchar uuid[VIR_UUID_STRING_BUFLEN]; }; G_DEFINE_TYPE(GVirDomain, gvir_domain, G_TYPE_OBJECT); @@ -122,6 +123,20 @@ static void gvir_domain_finalize(GObject *object) } +static void gvir_domain_constructed(GObject *object) +{ + GVirDomain *conn = GVIR_DOMAIN(object); + GVirDomainPrivate *priv = conn->priv; + + G_OBJECT_CLASS(gvir_domain_parent_class)->constructed(object); + + /* xxx we may want to turn this into an initable */ + if (virDomainGetUUIDString(priv->handle, priv->uuid) < 0) { + g_error("Failed to get domain UUID on %p", priv->handle); + } +} + + static void gvir_domain_class_init(GVirDomainClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -129,6 +144,7 @@ static void gvir_domain_class_init(GVirDomainClass *klass) object_class->finalize = gvir_domain_finalize; object_class->get_property = gvir_domain_get_property; object_class->set_property = gvir_domain_set_property; + object_class->constructed = gvir_domain_constructed; g_object_class_install_property(object_class, PROP_HANDLE, @@ -269,15 +285,11 @@ const gchar *gvir_domain_get_name(GVirDomain *dom) } -gchar *gvir_domain_get_uuid(GVirDomain *dom) +const gchar *gvir_domain_get_uuid(GVirDomain *dom) { - GVirDomainPrivate *priv = dom->priv; - char *uuid = g_new(gchar, VIR_UUID_STRING_BUFLEN); + g_return_val_if_fail(GVIR_IS_DOMAIN(dom), NULL); - if (virDomainGetUUIDString(priv->handle, uuid) < 0) { - g_error("Failed to get domain UUID on %p", priv->handle); - } - return uuid; + return dom->priv->uuid; } gint gvir_domain_get_id(GVirDomain *dom, diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h index 292f42e..4fb8541 100644 --- a/libvirt-gobject/libvirt-gobject-domain.h +++ b/libvirt-gobject/libvirt-gobject-domain.h @@ -91,7 +91,7 @@ GType gvir_domain_info_get_type(void); GType gvir_domain_handle_get_type(void); const gchar *gvir_domain_get_name(GVirDomain *dom); -gchar *gvir_domain_get_uuid(GVirDomain *dom); +const gchar *gvir_domain_get_uuid(GVirDomain *dom); gint gvir_domain_get_id(GVirDomain *dom, GError **err); diff --git a/libvirt-gobject/libvirt-gobject-network-filter.c b/libvirt-gobject/libvirt-gobject-network-filter.c index 020cdc0..eb10ce9 100644 --- a/libvirt-gobject/libvirt-gobject-network-filter.c +++ b/libvirt-gobject/libvirt-gobject-network-filter.c @@ -39,6 +39,7 @@ extern gboolean debugFlag; struct _GVirNetworkFilterPrivate { virNWFilterPtr handle; + gchar uuid[VIR_UUID_STRING_BUFLEN]; }; G_DEFINE_TYPE(GVirNetworkFilter, gvir_network_filter, G_TYPE_OBJECT); @@ -112,6 +113,20 @@ static void gvir_network_filter_finalize(GObject *object) } +static void gvir_network_filter_constructed(GObject *object) +{ + GVirNetworkFilter *nf = GVIR_NETWORK_FILTER(object); + GVirNetworkFilterPrivate *priv = nf->priv; + + G_OBJECT_CLASS(gvir_network_filter_parent_class)->constructed(object); + + /* xxx we may want to turn this into an initable */ + if (virNWFilterGetUUIDString(priv->handle, priv->uuid) < 0) { + g_error("Failed to get network filter UUID on %p", priv->handle); + } +} + + static void gvir_network_filter_class_init(GVirNetworkFilterClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -119,6 +134,7 @@ static void gvir_network_filter_class_init(GVirNetworkFilterClass *klass) object_class->finalize = gvir_network_filter_finalize; object_class->get_property = gvir_network_filter_get_property; object_class->set_property = gvir_network_filter_set_property; + object_class->constructed = gvir_network_filter_constructed; g_object_class_install_property(object_class, PROP_HANDLE, @@ -183,15 +199,11 @@ const gchar *gvir_network_filter_get_name(GVirNetworkFilter *filter) } -gchar *gvir_network_filter_get_uuid(GVirNetworkFilter *filter) +const gchar *gvir_network_filter_get_uuid(GVirNetworkFilter *filter) { - GVirNetworkFilterPrivate *priv = filter->priv; - char *uuid = g_new(gchar, VIR_UUID_STRING_BUFLEN); + g_return_val_if_fail(GVIR_IS_NETWORK_FILTER(filter), NULL); - if (virNWFilterGetUUIDString(priv->handle, uuid) < 0) { - g_error("Failed to get network_filter UUID on %p", priv->handle); - } - return uuid; + return filter->priv->uuid; } diff --git a/libvirt-gobject/libvirt-gobject-network-filter.h b/libvirt-gobject/libvirt-gobject-network-filter.h index b2b00df..f2c63cf 100644 --- a/libvirt-gobject/libvirt-gobject-network-filter.h +++ b/libvirt-gobject/libvirt-gobject-network-filter.h @@ -62,7 +62,7 @@ GType gvir_network_filter_get_type(void); GType gvir_network_filter_handle_get_type(void); const gchar *gvir_network_filter_get_name(GVirNetworkFilter *filter); -gchar *gvir_network_filter_get_uuid(GVirNetworkFilter *filter); +const gchar *gvir_network_filter_get_uuid(GVirNetworkFilter *filter); GVirConfigNetworkFilter *gvir_network_filter_get_config (GVirNetworkFilter *filter, diff --git a/libvirt-gobject/libvirt-gobject-network.c b/libvirt-gobject/libvirt-gobject-network.c index c9dd82d..158afa4 100644 --- a/libvirt-gobject/libvirt-gobject-network.c +++ b/libvirt-gobject/libvirt-gobject-network.c @@ -39,6 +39,7 @@ extern gboolean debugFlag; struct _GVirNetworkPrivate { virNetworkPtr handle; + gchar uuid[VIR_UUID_STRING_BUFLEN]; }; G_DEFINE_TYPE(GVirNetwork, gvir_network, G_TYPE_OBJECT); @@ -111,6 +112,18 @@ static void gvir_network_finalize(GObject *object) G_OBJECT_CLASS(gvir_network_parent_class)->finalize(object); } +static void gvir_network_constructed(GObject *object) +{ + GVirNetwork *net = GVIR_NETWORK(object); + GVirNetworkPrivate *priv = net->priv; + + G_OBJECT_CLASS(gvir_network_parent_class)->constructed(object); + + /* xxx we may want to turn this into an initable */ + if (virNetworkGetUUIDString(priv->handle, priv->uuid) < 0) { + g_error("Failed to get network UUID on %p", priv->handle); + } +} static void gvir_network_class_init(GVirNetworkClass *klass) { @@ -119,6 +132,7 @@ static void gvir_network_class_init(GVirNetworkClass *klass) object_class->finalize = gvir_network_finalize; object_class->get_property = gvir_network_get_property; object_class->set_property = gvir_network_set_property; + object_class->constructed = gvir_network_constructed; g_object_class_install_property(object_class, PROP_HANDLE, @@ -183,15 +197,11 @@ const gchar *gvir_network_get_name(GVirNetwork *network) } -gchar *gvir_network_get_uuid(GVirNetwork *network) +const gchar *gvir_network_get_uuid(GVirNetwork *network) { - GVirNetworkPrivate *priv = network->priv; - char *uuid = g_new(gchar, VIR_UUID_STRING_BUFLEN); + g_return_val_if_fail(GVIR_IS_NETWORK(network), NULL); - if (virNetworkGetUUIDString(priv->handle, uuid) < 0) { - g_error("Failed to get network UUID on %p", priv->handle); - } - return uuid; + return network->priv->uuid; } /** diff --git a/libvirt-gobject/libvirt-gobject-network.h b/libvirt-gobject/libvirt-gobject-network.h index 23437d0..79f37e7 100644 --- a/libvirt-gobject/libvirt-gobject-network.h +++ b/libvirt-gobject/libvirt-gobject-network.h @@ -66,7 +66,7 @@ GType gvir_network_get_type(void); GType gvir_network_handle_get_type(void); const gchar *gvir_network_get_name(GVirNetwork *network); -gchar *gvir_network_get_uuid(GVirNetwork *network); +const gchar *gvir_network_get_uuid(GVirNetwork *network); GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network, guint64 flags, diff --git a/libvirt-gobject/libvirt-gobject-secret.c b/libvirt-gobject/libvirt-gobject-secret.c index 112333d..ffff521 100644 --- a/libvirt-gobject/libvirt-gobject-secret.c +++ b/libvirt-gobject/libvirt-gobject-secret.c @@ -39,6 +39,7 @@ extern gboolean debugFlag; struct _GVirSecretPrivate { virSecretPtr handle; + gchar uuid[VIR_UUID_STRING_BUFLEN]; }; G_DEFINE_TYPE(GVirSecret, gvir_secret, G_TYPE_OBJECT); @@ -112,6 +113,20 @@ static void gvir_secret_finalize(GObject *object) } +static void gvir_secret_constructed(GObject *object) +{ + GVirSecret *conn = GVIR_SECRET(object); + GVirSecretPrivate *priv = conn->priv; + + G_OBJECT_CLASS(gvir_secret_parent_class)->constructed(object); + + /* xxx we may want to turn this into an initable */ + if (virSecretGetUUIDString(priv->handle, priv->uuid) < 0) { + g_error("Failed to get secret UUID on %p", priv->handle); + } +} + + static void gvir_secret_class_init(GVirSecretClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -119,6 +134,7 @@ static void gvir_secret_class_init(GVirSecretClass *klass) object_class->finalize = gvir_secret_finalize; object_class->get_property = gvir_secret_get_property; object_class->set_property = gvir_secret_set_property; + object_class->constructed = gvir_secret_constructed; g_object_class_install_property(object_class, PROP_HANDLE, @@ -170,15 +186,11 @@ GType gvir_secret_handle_get_type(void) } -gchar *gvir_secret_get_uuid(GVirSecret *secret) +const gchar *gvir_secret_get_uuid(GVirSecret *secret) { - GVirSecretPrivate *priv = secret->priv; - char *uuid = g_new(gchar, VIR_UUID_STRING_BUFLEN); + g_return_val_if_fail(GVIR_IS_SECRET(secret), NULL); - if (virSecretGetUUIDString(priv->handle, uuid) < 0) { - g_error("Failed to get secret UUID on %p", priv->handle); - } - return uuid; + return secret->priv->uuid; } diff --git a/libvirt-gobject/libvirt-gobject-secret.h b/libvirt-gobject/libvirt-gobject-secret.h index 0023245..443ffde 100644 --- a/libvirt-gobject/libvirt-gobject-secret.h +++ b/libvirt-gobject/libvirt-gobject-secret.h @@ -63,7 +63,7 @@ GType gvir_secret_get_type(void); GType gvir_secret_handle_get_type(void); const gchar *gvir_secret_get_name(GVirSecret *secret); -gchar *gvir_secret_get_uuid(GVirSecret *secret); +const gchar *gvir_secret_get_uuid(GVirSecret *secret); GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret, guint64 flags, diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c index 0959642..0e796f9 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.c +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c @@ -39,6 +39,7 @@ extern gboolean debugFlag; struct _GVirStoragePoolPrivate { virStoragePoolPtr handle; + gchar uuid[VIR_UUID_STRING_BUFLEN]; }; G_DEFINE_TYPE(GVirStoragePool, gvir_storage_pool, G_TYPE_OBJECT); @@ -112,6 +113,20 @@ static void gvir_storage_pool_finalize(GObject *object) } +static void gvir_storage_pool_constructed(GObject *object) +{ + GVirStoragePool *conn = GVIR_STORAGE_POOL(object); + GVirStoragePoolPrivate *priv = conn->priv; + + G_OBJECT_CLASS(gvir_storage_pool_parent_class)->constructed(object); + + /* xxx we may want to turn this into an initable */ + if (virStoragePoolGetUUIDString(priv->handle, priv->uuid) < 0) { + g_error("Failed to get storage pool UUID on %p", priv->handle); + } +} + + static void gvir_storage_pool_class_init(GVirStoragePoolClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -119,6 +134,7 @@ static void gvir_storage_pool_class_init(GVirStoragePoolClass *klass) object_class->finalize = gvir_storage_pool_finalize; object_class->get_property = gvir_storage_pool_get_property; object_class->set_property = gvir_storage_pool_set_property; + object_class->constructed = gvir_storage_pool_constructed; g_object_class_install_property(object_class, PROP_HANDLE, @@ -183,15 +199,11 @@ const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool) } -gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool) +const gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool) { - GVirStoragePoolPrivate *priv = pool->priv; - char *uuid = g_new(gchar, VIR_UUID_STRING_BUFLEN); + g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL); - if (virStoragePoolGetUUIDString(priv->handle, uuid) < 0) { - g_error("Failed to get storage_pool UUID on %p", priv->handle); - } - return uuid; + return pool->priv->uuid; } diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.h b/libvirt-gobject/libvirt-gobject-storage-pool.h index ffd5db7..e91827e 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.h +++ b/libvirt-gobject/libvirt-gobject-storage-pool.h @@ -63,7 +63,7 @@ GType gvir_storage_pool_get_type(void); GType gvir_storage_pool_handle_get_type(void); const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool); -gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool); +const gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool); GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool, guint64 flags, -- 1.7.6.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list