X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Flttv%2Fattribute.c;h=b4402b25921f5073d4a74d6027eeea85dc45242e;hb=e05fc742955a6cef80d4e2ab88dd589bace6b6c8;hp=db6fa6a6396ace93e02f2140db03022d1b719ac2;hpb=c47a6dc6fb544baff5b6fe977c992822693208b8;p=lttv.git diff --git a/ltt/branches/poly/lttv/lttv/attribute.c b/ltt/branches/poly/lttv/lttv/attribute.c index db6fa6a6..b4402b25 100644 --- a/ltt/branches/poly/lttv/lttv/attribute.c +++ b/ltt/branches/poly/lttv/lttv/attribute.c @@ -16,8 +16,14 @@ * MA 02111-1307, USA. */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include #include #include +#include typedef union _AttributeValue { int dv_int; @@ -40,7 +46,8 @@ typedef struct _Attribute { } Attribute; -LttvAttributeValue address_of_value(LttvAttributeType t, AttributeValue *v) +static __inline__ LttvAttributeValue address_of_value(LttvAttributeType t, + AttributeValue *v) { LttvAttributeValue va; @@ -55,6 +62,7 @@ LttvAttributeValue address_of_value(LttvAttributeType t, AttributeValue *v) case LTTV_POINTER: va.v_pointer = &v->dv_pointer; break; case LTTV_STRING: va.v_string = &v->dv_string; break; case LTTV_GOBJECT: va.v_gobject = &v->dv_gobject; break; + case LTTV_NONE: break; } return va; } @@ -75,6 +83,7 @@ AttributeValue init_value(LttvAttributeType t) case LTTV_POINTER: v.dv_pointer = NULL; break; case LTTV_STRING: v.dv_string = NULL; break; case LTTV_GOBJECT: v.dv_gobject = NULL; break; + case LTTV_NONE: break; } return v; } @@ -173,7 +182,7 @@ lttv_attribute_remove(LttvAttribute *self, unsigned i) /* The element used to replace the removed element has its index entry all wrong now. Reinsert it with its new position. */ - if(self->attributes->len != i){ + if(likely(self->attributes->len != i)){ g_hash_table_remove(self->names, GUINT_TO_POINTER(a->name)); g_hash_table_insert(self->names, GUINT_TO_POINTER(a->name), GUINT_TO_POINTER(i + 1)); } @@ -185,7 +194,7 @@ lttv_attribute_remove_by_name(LttvAttribute *self, LttvAttributeName name) unsigned i; i = (unsigned)g_hash_table_lookup(self->names, GUINT_TO_POINTER(name)); - if(i == 0) g_error("remove by name non existent attribute"); + if(unlikely(i == 0)) g_error("remove by name non existent attribute"); lttv_attribute_remove(self, i - 1); } @@ -205,9 +214,9 @@ lttv_attribute_find_subdir(LttvAttribute *self, LttvAttributeName name) LttvAttribute *new; i = (unsigned)g_hash_table_lookup(self->names, GUINT_TO_POINTER(name)); - if(i != 0) { + if(likely(i != 0)) { a = g_array_index(self->attributes, Attribute, i - 1); - if(a.type == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(a.value.dv_gobject)) { + if(likely(a.type == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(a.value.dv_gobject))) { return LTTV_ATTRIBUTE(a.value.dv_gobject); } else return NULL; @@ -226,9 +235,9 @@ lttv_attribute_find(LttvAttribute *self, LttvAttributeName name, Attribute *a; i = (unsigned)g_hash_table_lookup(self->names, GUINT_TO_POINTER(name)); - if(i != 0) { + if(likely(i != 0)) { a = &g_array_index(self->attributes, Attribute, i - 1); - if(a->type != t) return FALSE; + if(unlikely(a->type != t)) return FALSE; *v = address_of_value(t, &(a->value)); return TRUE; } @@ -360,7 +369,7 @@ lttv_attribute_write_xml(LttvAttribute *self, FILE *fp, int pos, int indent) fprintf(fp, "TYPE=DOUBLE VALUE=%f/>\n", a->value.dv_double); break; case LTTV_TIME: - fprintf(fp, "TYPE=TIME SEC=%u NSEC=%u/>\n", a->value.dv_time.tv_sec, + fprintf(fp, "TYPE=TIME SEC=%lu NSEC=%lu/>\n", a->value.dv_time.tv_sec, a->value.dv_time.tv_nsec); break; case LTTV_POINTER: @@ -386,9 +395,7 @@ lttv_attribute_write_xml(LttvAttribute *self, FILE *fp, int pos, int indent) void lttv_attribute_read_xml(LttvAttribute *self, FILE *fp) { - int i, nb, res; - - Attribute *a; + int res; char buffer[256], type[10]; @@ -437,12 +444,12 @@ lttv_attribute_read_xml(LttvAttribute *self, FILE *fp) } else if(strcmp(type, "DOUBLE") == 0) { value = lttv_attribute_add(self, name, LTTV_DOUBLE); - res = fscanf(fp, " VALUE=%f/>", value.v_double); + res = fscanf(fp, " VALUE=%lf/>", value.v_double); g_assert(res == 1); } else if(strcmp(type, "TIME") == 0) { value = lttv_attribute_add(self, name, LTTV_TIME); - res = fscanf(fp, " SEC=%u NSEC=%u/>", &(value.v_time->tv_sec), + res = fscanf(fp, " SEC=%lu NSEC=%lu/>", &(value.v_time->tv_sec), &(value.v_time->tv_nsec)); g_assert(res == 2); } @@ -513,12 +520,12 @@ attribute_interface_init (gpointer g_iface, gpointer iface_data) } - static void attribute_instance_init (GTypeInstance *instance, gpointer g_class) { LttvAttribute *self = (LttvAttribute *)instance; - self->names = g_hash_table_new(g_direct_hash, g_direct_equal); + self->names = g_hash_table_new(g_direct_hash, + g_direct_equal); self->attributes = g_array_new(FALSE, FALSE, sizeof(Attribute)); } @@ -526,11 +533,15 @@ attribute_instance_init (GTypeInstance *instance, gpointer g_class) static void attribute_finalize (LttvAttribute *self) { - g_hash_table_destroy(self->names); + guint i; g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "attribute_finalize()"); + + for(i=0;iattributes->len;i++) { + lttv_attribute_remove(self, i); + } + + g_hash_table_destroy(self->names); g_array_free(self->attributes, TRUE); - G_OBJECT_CLASS(g_type_class_peek_parent( - g_type_class_peek(LTTV_ATTRIBUTE_TYPE)))->finalize(G_OBJECT(self)); } @@ -556,7 +567,8 @@ lttv_attribute_get_type (void) NULL, /* class_data */ sizeof (LttvAttribute), 0, /* n_preallocs */ - (GInstanceInitFunc) attribute_instance_init /* instance_init */ + (GInstanceInitFunc) attribute_instance_init, /* instance_init */ + NULL /* value handling */ }; static const GInterfaceInfo iattribute_info = {