From c47a6dc6fb544baff5b6fe977c992822693208b8 Mon Sep 17 00:00:00 2001 From: compudj Date: Thu, 24 Jun 2004 19:13:42 +0000 Subject: [PATCH] gobjects referenced in attributes. No more recursive_free git-svn-id: http://ltt.polymtl.ca/svn@611 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/lttv/lttv/attribute.c | 10 +++++++--- ltt/branches/poly/lttv/lttv/attribute.h | 5 +++-- ltt/branches/poly/lttv/lttv/iattribute.c | 3 ++- ltt/branches/poly/lttv/lttv/iattribute.h | 10 ++++++++-- ltt/branches/poly/lttv/lttv/state.c | 4 ++-- ltt/branches/poly/lttv/lttv/stats.c | 3 --- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/ltt/branches/poly/lttv/lttv/attribute.c b/ltt/branches/poly/lttv/lttv/attribute.c index a862cdf7..db6fa6a6 100644 --- a/ltt/branches/poly/lttv/lttv/attribute.c +++ b/ltt/branches/poly/lttv/lttv/attribute.c @@ -161,6 +161,10 @@ lttv_attribute_remove(LttvAttribute *self, unsigned i) a = &g_array_index(self->attributes, Attribute, i); + /* If the element is a gobject, unreference it. */ + if(a->type == LTTV_GOBJECT && a->value.dv_gobject != NULL) + g_object_unref(a->value.dv_gobject); + /* Remove the array element and its entry in the name index */ g_hash_table_remove(self->names, GUINT_TO_POINTER(a->name)); @@ -234,7 +238,7 @@ lttv_attribute_find(LttvAttribute *self, LttvAttributeName name, } -void lttv_attribute_recursive_free(LttvAttribute *self) +/*void lttv_attribute_recursive_free(LttvAttribute *self) { int i, nb; @@ -249,7 +253,7 @@ void lttv_attribute_recursive_free(LttvAttribute *self) } } g_object_unref(self); -} +}*/ void lttv_attribute_recursive_add(LttvAttribute *dest, LttvAttribute *src) @@ -272,7 +276,7 @@ void lttv_attribute_recursive_add(LttvAttribute *dest, LttvAttribute *src) else { g_assert(lttv_attribute_find(dest, a->name, a->type, &value)); switch(a->type) { - case LTTV_INT: + case LTTV_INT: *value.v_int += a->value.dv_int; break; case LTTV_UINT: diff --git a/ltt/branches/poly/lttv/lttv/attribute.h b/ltt/branches/poly/lttv/lttv/attribute.h index 76ed2f1e..517b4787 100644 --- a/ltt/branches/poly/lttv/lttv/attribute.h +++ b/ltt/branches/poly/lttv/lttv/attribute.h @@ -19,7 +19,7 @@ #ifndef ATTRIBUTE_H #define ATTRIBUTE_H -/* FIXME : unnamed attributed not implemented */ +/* FIXME : unnamed attributes not implemented */ #include #include @@ -110,7 +110,8 @@ gboolean lttv_attribute_find(LttvAttribute *self, LttvAttributeName name, /* Free recursively a tree of attributes. All contained gobject of type LttvAttribute are freed (unreferenced) recursively. */ -void lttv_attribute_recursive_free(LttvAttribute *self); +// Now done by default. +// void lttv_attribute_recursive_free(LttvAttribute *self); /* Add items from a tree of attributes to another tree. */ diff --git a/ltt/branches/poly/lttv/lttv/iattribute.c b/ltt/branches/poly/lttv/lttv/iattribute.c index 4293c828..ef357dd5 100644 --- a/ltt/branches/poly/lttv/lttv/iattribute.c +++ b/ltt/branches/poly/lttv/lttv/iattribute.c @@ -270,7 +270,8 @@ void lttv_iattribute_copy_value(LttvAttributeType t, LttvAttributeValue dest, break; case LTTV_GOBJECT: - *(dest.v_gobject) = *(src.v_gobject); + *(dest.v_gobject) = *(src.v_gobject); + if(*(dest.v_gobject) != NULL) g_object_ref(*(dest.v_gobject)); break; case LTTV_NONE: diff --git a/ltt/branches/poly/lttv/lttv/iattribute.h b/ltt/branches/poly/lttv/lttv/iattribute.h index 0bf10ad7..0783077f 100644 --- a/ltt/branches/poly/lttv/lttv/iattribute.h +++ b/ltt/branches/poly/lttv/lttv/iattribute.h @@ -16,7 +16,7 @@ * MA 02111-1307, USA. */ -/* FIXME : unnamed attributed not implemented */ +/* FIXME : unnamed attributes not implemented */ #ifndef IATTRIBUTE_H #define IATTRIBUTE_H @@ -30,6 +30,13 @@ and access functions over a wide range of structures. The names are represented by unique integer identifiers, GQuarks. */ +/* Please note that adding a value of type gobject that is non null does not + * increment the reference count of this object : the actual reference to + * the object is "given" to the attribute tree. When the gobject value + * is removed, the object is unreferenced. A value copy through + * lttv_iattribute_copy_value does increase the reference count of the + * gobject. */ + typedef GQuark LttvAttributeName; typedef enum _LttvAttributeType { @@ -127,7 +134,6 @@ LttvAttributeType lttv_iattribute_get_by_name(LttvIAttribute *self, LttvAttributeValue lttv_iattribute_add(LttvIAttribute *self, LttvAttributeName name, LttvAttributeType t); - /* Remove an attribute */ void lttv_iattribute_remove(LttvIAttribute *self, unsigned i); diff --git a/ltt/branches/poly/lttv/lttv/state.c b/ltt/branches/poly/lttv/lttv/state.c index aa235f2d..d8cbe8c6 100644 --- a/ltt/branches/poly/lttv/lttv/state.c +++ b/ltt/branches/poly/lttv/lttv/state.c @@ -472,6 +472,7 @@ static void state_saved_free(LttvTraceState *self, LttvAttribute *container) tracefiles_tree = lttv_attribute_find_subdir(container, LTTV_STATE_TRACEFILES); + g_object_ref(G_OBJECT(tracefiles_tree)); lttv_attribute_remove_by_name(container, LTTV_STATE_TRACEFILES); type = lttv_attribute_get_by_name(container, LTTV_STATE_PROCESSES, @@ -495,7 +496,7 @@ static void state_saved_free(LttvTraceState *self, LttvAttribute *container) g_assert(type == LTTV_POINTER); if(*(value.v_pointer) != NULL) g_free(*(value.v_pointer)); } - lttv_attribute_recursive_free(tracefiles_tree); + g_object_unref(G_OBJECT(tracefiles_tree)); } @@ -522,7 +523,6 @@ static void free_saved_state(LttvTraceState *self) } lttv_attribute_remove_by_name(self->parent.t_a, LTTV_STATE_SAVED_STATES); - lttv_attribute_recursive_free(saved_states); } diff --git a/ltt/branches/poly/lttv/lttv/stats.c b/ltt/branches/poly/lttv/lttv/stats.c index d36438dc..fa697d0c 100644 --- a/ltt/branches/poly/lttv/lttv/stats.c +++ b/ltt/branches/poly/lttv/lttv/stats.c @@ -149,7 +149,6 @@ fini(LttvTracesetStats *self) if(*(v.v_uint) == 0) { lttv_attribute_remove_by_name(self->parent.parent.ts_a, LTTV_STATS); - lttv_attribute_recursive_free(self->stats); } self->stats = NULL; @@ -165,12 +164,10 @@ fini(LttvTracesetStats *self) if(*(v.v_uint) == 0) { lttv_attribute_remove_by_name(tcs->parent.parent.t_a,LTTV_STATS); - lttv_attribute_recursive_free(tcs->stats); tracefiles_stats = lttv_attribute_find_subdir(tcs->parent.parent.t_a, LTTV_STATS_TRACEFILES); lttv_attribute_remove_by_name(tcs->parent.parent.t_a, LTTV_STATS_TRACEFILES); - lttv_attribute_recursive_free(tracefiles_stats); } tcs->stats = NULL; -- 2.34.1