X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Ftypes%2Fenum.c;h=6243345140d1b5b196278daf80f3a3d447857d87;hp=a62d84e712ef6104802f3301197cdc85c859b3c8;hb=c054553dac076f91196b372fa19efaf2adc4e4f9;hpb=4c8bfb7e0a9cef6e74cefa38ed54bf8cbd424183 diff --git a/formats/ctf/types/enum.c b/formats/ctf/types/enum.c index a62d84e7..62433451 100644 --- a/formats/ctf/types/enum.c +++ b/formats/ctf/types/enum.c @@ -3,7 +3,7 @@ * * Enumeration mapping strings (quarks) from/to integers. * - * Copyright 2010 - Mathieu Desnoyers + * Copyright 2010, 2011 - Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,11 @@ #include #include -GQuark ctf_enum_read(struct stream_pos *pos, - const struct type_class_enum *src) +/* + * The caller should unref the GArray. + */ +GArray *ctf_enum_read(struct stream_pos *pos, + const struct type_class_enum *src) { const struct type_class_integer *int_class = &src->p; @@ -29,30 +32,33 @@ GQuark ctf_enum_read(struct stream_pos *pos, uint64_t v; v = ctf_uint_read(pos, int_class); - return enum_uint_to_quark(src, v); + return enum_uint_to_quark_set(src, v); } else { int64_t v; v = ctf_int_read(pos, int_class); - return enum_int_to_quark(src, v); + return enum_int_to_quark_set(src, v); } } +/* + * Arbitrarily choose the start of the first matching range. + */ void ctf_enum_write(struct stream_pos *pos, - const struct type_class_enum *dest, - GQuark q) + const struct type_class_enum *dest, + GQuark q) { const struct type_class_integer *int_class = &dest->p; + GArray *array; - if (!int_class->signedness) { - uint64_t v; + array = enum_quark_to_range_set(dest, q); + assert(array); - v = enum_quark_to_uint(dest, q); + if (!int_class->signedness) { + uint64_t v = g_array_index(array, struct enum_range, 0).start._unsigned; ctf_uint_write(pos, int_class, v); } else { - int64_t v; - - v = enum_quark_to_int(dest, q); + int64_t v = g_array_index(array, struct enum_range, 0).start._unsigned; ctf_int_write(pos, int_class, v); } }