X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Fenum.c;h=6ad4d45038eabf37da04b05944b290d3bff983fe;hp=bfed769de4889cb8e55bc6c80ccc9ffd3c645cc7;hb=8a4035bcbfe691490b031f08533676597f72a4ac;hpb=d65d8abbc711906be828fce0a57df1be95b7ccf0 diff --git a/types/enum.c b/types/enum.c index bfed769d..6ad4d450 100644 --- a/types/enum.c +++ b/types/enum.c @@ -62,8 +62,10 @@ GArray *enum_uint_to_quark_set(const struct type_class_enum *enum_class, g_array_index(ranges, struct enum_range, ranges->len) = iter->range; } } - if (!ranges) + if (!ranges) { ranges = qs; + g_array_ref(ranges); + } return ranges; } @@ -101,8 +103,10 @@ GArray *enum_int_to_quark_set(const struct type_class_enum *enum_class, uint64_t g_array_index(ranges, struct enum_range, ranges->len) = iter->range; } } - if (!ranges) + if (!ranges) { ranges = qs; + g_array_ref(ranges); + } return ranges; } @@ -202,7 +206,7 @@ void enum_signed_insert_value_to_quark_set(struct type_class_enum *enum_class, g_array_set_size(array, 1); g_array_index(array, GQuark, array->len - 1) = q; g_hash_table_insert(enum_class->table.value_to_quark_set, - (gconstpointer) v, array); + (gpointer) v, array); } else { g_array_set_size(array, array->len + 1); g_array_index(array, GQuark, array->len - 1) = q; @@ -222,7 +226,7 @@ void enum_unsigned_insert_value_to_quark_set(struct type_class_enum *enum_class, g_array_set_size(array, 1); g_array_index(array, GQuark, array->len - 1) = q; g_hash_table_insert(enum_class->table.value_to_quark_set, - (gconstpointer) v, array); + (gpointer) v, array); } else { g_array_set_size(array, array->len + 1); g_array_index(array, GQuark, array->len - 1) = q; @@ -233,9 +237,8 @@ void enum_unsigned_insert_value_to_quark_set(struct type_class_enum *enum_class, GArray *enum_quark_to_range_set(const struct type_class_enum *enum_class, GQuark q) { - gconstpointer v = g_hash_table_lookup(enum_class->table.quark_to_range_set, - (gconstpointer) (unsigned long) q); - return (GArray *) v; + return g_hash_table_lookup(enum_class->table.quark_to_range_set, + (gconstpointer) (unsigned long) q); } static @@ -339,9 +342,17 @@ void enum_copy(struct stream_pos *dest, const struct format *fdest, { struct type_class_enum *enum_class = container_of(type_class, struct type_class_enum, p.p); + GArray *array; GQuark v; - v = fsrc->enum_read(src, enum_class); + array = fsrc->enum_read(src, enum_class); + assert(array); + /* + * Arbitrarily choose the first one. + * TODO: use direct underlying type read/write intead. Not doing it for + * now to test enum read and write code. + */ + v = g_array_index(array, GQuark, 0); return fdest->enum_write(dest, enum_class, v); }