From b6baf3bbbc533c4176a8e8fcb349604803fe16ee Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 24 Apr 2019 01:00:45 -0400 Subject: [PATCH] lib: have dedicated, unique unsigned and signed enum FC mapping objects This patch makes the enumeration field class mapping API aligned with the structure field class member and variant field class option APIs. In other words, a signed or an unsigned enumeration field class mapping is now a dedicated type. An enumeration field class mapping object is unique and always belongs to its parent field class. bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const() and bt_field_class_signed_enumeration_borrow_mapping_by_index_const() now return borrowed enumeration field class mapping objects. You can use bt_field_class_unsigned_enumeration_mapping_as_mapping_const() to change a signed or unsigned enumeration field class mapping into a generic enumeration field class mapping. The API for a generic enumeration field class mapping is: const char *bt_field_class_enumeration_mapping_get_label( const bt_field_class_enumeration_mapping *mapping); uint64_t bt_field_class_enumeration_mapping_get_range_count( const bt_field_class_enumeration_mapping *mapping); You cannot create an enumeration field class mapping object: you still map a name to a specific range with bt_field_class_unsigned_enumeration_map_range() and bt_field_class_signed_enumeration_map_range(). This patch also makes the `flt.lttng-utils.debug-info` and `sink.ctf.fs` component classes use the updated API. Signed-off-by: Philippe Proulx Change-Id: Iba5da648ca69ec0ca0c5df09a9f383dd4b1e3972 Reviewed-on: https://review.gerrithub.io/c/eepp/babeltrace/+/451996 --- .../babeltrace/trace-ir/field-class-const.h | 55 ++++++++++------- .../trace-ir/field-class-internal.h | 3 + include/babeltrace/types.h | 5 +- lib/trace-ir/field-class.c | 60 ++++++------------- .../ctf/fs-sink/translate-ctf-ir-to-tsdl.c | 35 ++++++----- .../trace-ir-metadata-field-class-copy.c | 40 ++++++++----- 6 files changed, 106 insertions(+), 92 deletions(-) diff --git a/include/babeltrace/trace-ir/field-class-const.h b/include/babeltrace/trace-ir/field-class-const.h index 244218d8..eb9cb150 100644 --- a/include/babeltrace/trace-ir/field-class-const.h +++ b/include/babeltrace/trace-ir/field-class-const.h @@ -28,9 +28,10 @@ */ /* - * For bt_bool, bt_field_class bt_field_path - * bt_field_class_signed_enumeration_mapping_ranges - * bt_field_class_unsigned_enumeration_mapping_ranges, + * For bt_bool, bt_field_class, bt_field_path, + * bt_field_class_enumeration_mapping, + * bt_field_class_unsigned_enumeration_mapping, + * bt_field_class_signed_enumeration_mapping, * bt_field_class_enumeration_mapping_label_array */ #include @@ -83,32 +84,44 @@ extern bt_bool bt_field_class_real_is_single_precision( extern uint64_t bt_field_class_enumeration_get_mapping_count( const bt_field_class *field_class); -extern void bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( - const bt_field_class *field_class, uint64_t index, - const char **label, - const bt_field_class_unsigned_enumeration_mapping_ranges **ranges); +extern const bt_field_class_unsigned_enumeration_mapping * +bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( + const bt_field_class *field_class, uint64_t index); + +extern const bt_field_class_signed_enumeration_mapping * +bt_field_class_signed_enumeration_borrow_mapping_by_index_const( + const bt_field_class *field_class, uint64_t index); -extern void bt_field_class_signed_enumeration_borrow_mapping_by_index_const( - const bt_field_class *field_class, uint64_t index, - const char **label, - const bt_field_class_signed_enumeration_mapping_ranges **ranges); +static inline +const bt_field_class_enumeration_mapping * +bt_field_class_unsigned_enumeration_mapping_as_mapping_const( + const bt_field_class_unsigned_enumeration_mapping *mapping) +{ + return (const void *) mapping; +} + +static inline +const bt_field_class_enumeration_mapping * +bt_field_class_signed_enumeration_mapping_as_mapping_const( + const bt_field_class_signed_enumeration_mapping *mapping) +{ + return (const void *) mapping; +} -extern uint64_t -bt_field_class_unsigned_enumeration_mapping_ranges_get_range_count( - const bt_field_class_unsigned_enumeration_mapping_ranges *ranges); +extern const char *bt_field_class_enumeration_mapping_get_label( + const bt_field_class_enumeration_mapping *mapping); -extern uint64_t -bt_field_class_signed_enumeration_mapping_ranges_get_range_count( - const bt_field_class_signed_enumeration_mapping_ranges *ranges); +extern uint64_t bt_field_class_enumeration_mapping_get_range_count( + const bt_field_class_enumeration_mapping *mapping); extern void -bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index( - const bt_field_class_unsigned_enumeration_mapping_ranges *ranges, +bt_field_class_unsigned_enumeration_mapping_get_range_by_index( + const bt_field_class_unsigned_enumeration_mapping *mapping, uint64_t index, uint64_t *lower, uint64_t *upper); extern void -bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index( - const bt_field_class_signed_enumeration_mapping_ranges *ranges, +bt_field_class_signed_enumeration_mapping_get_range_by_index( + const bt_field_class_signed_enumeration_mapping *mapping, uint64_t index, int64_t *lower, int64_t *upper); extern bt_field_class_status diff --git a/include/babeltrace/trace-ir/field-class-internal.h b/include/babeltrace/trace-ir/field-class-internal.h index 77268c5f..7aabf623 100644 --- a/include/babeltrace/trace-ir/field-class-internal.h +++ b/include/babeltrace/trace-ir/field-class-internal.h @@ -130,6 +130,9 @@ struct bt_field_class_enumeration_mapping { GArray *ranges; }; +struct bt_field_class_unsigned_enumeration_mapping; +struct bt_field_class_signed_enumeration_mapping; + struct bt_field_class_enumeration { struct bt_field_class_integer common; diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index 72fcb9e8..9f71793a 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -92,8 +92,9 @@ typedef struct bt_event_class bt_event_class; typedef struct bt_event_header_field bt_event_header_field; typedef struct bt_field bt_field; typedef struct bt_field_class bt_field_class; -typedef struct bt_field_class_signed_enumeration_mapping_ranges bt_field_class_signed_enumeration_mapping_ranges; -typedef struct bt_field_class_unsigned_enumeration_mapping_ranges bt_field_class_unsigned_enumeration_mapping_ranges; +typedef struct bt_field_class_enumeration_mapping bt_field_class_enumeration_mapping; +typedef struct bt_field_class_signed_enumeration_mapping bt_field_class_signed_enumeration_mapping; +typedef struct bt_field_class_unsigned_enumeration_mapping bt_field_class_unsigned_enumeration_mapping; typedef struct bt_field_class_structure_member bt_field_class_structure_member; typedef struct bt_field_class_variant_option bt_field_class_variant_option; typedef struct bt_field_path bt_field_path; diff --git a/lib/trace-ir/field-class.c b/lib/trace-ir/field-class.c index dad075e8..b228fc0a 100644 --- a/lib/trace-ir/field-class.c +++ b/lib/trace-ir/field-class.c @@ -291,64 +291,44 @@ uint64_t bt_field_class_enumeration_get_mapping_count( return (uint64_t) enum_fc->mappings->len; } -void bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( - const struct bt_field_class *fc, uint64_t index, - const char **name, - const struct bt_field_class_unsigned_enumeration_mapping_ranges **ranges) +const struct bt_field_class_unsigned_enumeration_mapping * +bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( + const struct bt_field_class *fc, uint64_t index) { const struct bt_field_class_enumeration *enum_fc = (const void *) fc; - const struct bt_field_class_enumeration_mapping *mapping; BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_NON_NULL(name, "Name (output)"); - BT_ASSERT_PRE_NON_NULL(ranges, "Ranges (output)"); BT_ASSERT_PRE_VALID_INDEX(index, enum_fc->mappings->len); BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, "Field class"); - mapping = BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); - *name = mapping->label->str; - *ranges = (void *) mapping; + return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); } -void bt_field_class_signed_enumeration_borrow_mapping_by_index_const( - const struct bt_field_class *fc, uint64_t index, - const char **name, - const struct bt_field_class_signed_enumeration_mapping_ranges **ranges) +const struct bt_field_class_signed_enumeration_mapping * +bt_field_class_signed_enumeration_borrow_mapping_by_index_const( + const struct bt_field_class *fc, uint64_t index) { const struct bt_field_class_enumeration *enum_fc = (const void *) fc; - const struct bt_field_class_enumeration_mapping *mapping; BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_NON_NULL(name, "Name (output)"); - BT_ASSERT_PRE_NON_NULL(ranges, "Ranges (output)"); BT_ASSERT_PRE_VALID_INDEX(index, enum_fc->mappings->len); BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, "Field class"); - mapping = BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); - *name = mapping->label->str; - *ranges = (void *) mapping; + return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); } -static inline -uint64_t get_enumeration_field_class_mapping_range_count( +const char *bt_field_class_enumeration_mapping_get_label( const struct bt_field_class_enumeration_mapping *mapping) { - BT_ASSERT_PRE_NON_NULL(mapping, "Ranges"); - return (uint64_t) mapping->ranges->len; -} - -uint64_t bt_field_class_unsigned_enumeration_mapping_ranges_get_range_count( - const struct bt_field_class_unsigned_enumeration_mapping_ranges *ranges) -{ - return get_enumeration_field_class_mapping_range_count( - (const void *) ranges); + BT_ASSERT_PRE_NON_NULL(mapping, "Enumeration field class mapping"); + return mapping->label->str; } -uint64_t bt_field_class_signed_enumeration_mapping_ranges_get_range_count( - const struct bt_field_class_signed_enumeration_mapping_ranges *ranges) +uint64_t bt_field_class_enumeration_mapping_get_range_count( + const struct bt_field_class_enumeration_mapping *mapping) { - return get_enumeration_field_class_mapping_range_count( - (const void *) ranges); + BT_ASSERT_PRE_NON_NULL(mapping, "Enumeration field class mapping"); + return (uint64_t) mapping->ranges->len; } static inline @@ -367,16 +347,16 @@ void get_enumeration_field_class_mapping_range_at_index( *upper = range->upper.u; } -void bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index( - const struct bt_field_class_unsigned_enumeration_mapping_ranges *ranges, +void bt_field_class_unsigned_enumeration_mapping_get_range_by_index( + const struct bt_field_class_unsigned_enumeration_mapping *ranges, uint64_t index, uint64_t *lower, uint64_t *upper) { get_enumeration_field_class_mapping_range_at_index( (const void *) ranges, index, lower, upper); } -void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index( - const struct bt_field_class_signed_enumeration_mapping_ranges *ranges, +void bt_field_class_signed_enumeration_mapping_get_range_by_index( + const struct bt_field_class_signed_enumeration_mapping *ranges, uint64_t index, int64_t *lower, int64_t *upper) { get_enumeration_field_class_mapping_range_at_index( @@ -384,8 +364,6 @@ void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index( (uint64_t *) lower, (uint64_t *) upper); } - - enum bt_field_class_status bt_field_class_unsigned_enumeration_get_mapping_labels_by_value( const struct bt_field_class *fc, uint64_t value, diff --git a/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c b/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c index fef1d040..efc02b30 100644 --- a/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c +++ b/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c @@ -227,23 +227,30 @@ void append_integer_field_class(struct ctx *ctx, for (i = 0; i < bt_field_class_enumeration_get_mapping_count(ir_fc); i++) { const char *label; - const bt_field_class_unsigned_enumeration_mapping_ranges *u_ranges; - const bt_field_class_signed_enumeration_mapping_ranges *i_ranges; + const bt_field_class_enumeration_mapping *mapping; + const bt_field_class_unsigned_enumeration_mapping *u_mapping; + const bt_field_class_signed_enumeration_mapping *i_mapping; uint64_t range_count; uint64_t range_i; if (is_signed) { - bt_field_class_signed_enumeration_borrow_mapping_by_index_const( - ir_fc, i, &label, &i_ranges); - range_count = bt_field_class_signed_enumeration_mapping_ranges_get_range_count( - i_ranges); + i_mapping = bt_field_class_signed_enumeration_borrow_mapping_by_index_const( + ir_fc, i); + mapping = bt_field_class_signed_enumeration_mapping_as_mapping_const( + i_mapping); } else { - bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( - ir_fc, i, &label, &u_ranges); - range_count = bt_field_class_unsigned_enumeration_mapping_ranges_get_range_count( - u_ranges); + u_mapping = bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( + ir_fc, i); + mapping = bt_field_class_unsigned_enumeration_mapping_as_mapping_const( + u_mapping); } + label = bt_field_class_enumeration_mapping_get_label( + mapping); + range_count = + bt_field_class_enumeration_mapping_get_range_count( + mapping); + for (range_i = 0; range_i < range_count; range_i++) { append_indent(ctx); @@ -271,8 +278,8 @@ void append_integer_field_class(struct ctx *ctx, if (is_signed) { int64_t lower, upper; - bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index( - i_ranges, range_i, + bt_field_class_signed_enumeration_mapping_get_range_by_index( + i_mapping, range_i, &lower, &upper); if (lower == upper) { @@ -287,8 +294,8 @@ void append_integer_field_class(struct ctx *ctx, } else { uint64_t lower, upper; - bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index( - u_ranges, range_i, + bt_field_class_unsigned_enumeration_mapping_get_range_by_index( + u_mapping, range_i, &lower, &upper); if (lower == upper) { diff --git a/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c b/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c index 1434851b..a256beda 100644 --- a/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c +++ b/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c @@ -201,15 +201,21 @@ int field_class_unsigned_enumeration_copy( enum_mapping_count = bt_field_class_enumeration_get_mapping_count(in_field_class); for (i = 0; i < enum_mapping_count; i++) { const char *label; - const bt_field_class_unsigned_enumeration_mapping_ranges *ranges; + const bt_field_class_unsigned_enumeration_mapping *u_mapping; + const bt_field_class_enumeration_mapping *mapping; uint64_t range_index, range_count; /* Get the ranges and the range count. */ - bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( - in_field_class, i, &label, &ranges); + u_mapping = bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( + in_field_class, i); + mapping = bt_field_class_unsigned_enumeration_mapping_as_mapping_const( + u_mapping); range_count = - bt_field_class_unsigned_enumeration_mapping_ranges_get_range_count( - ranges); + bt_field_class_enumeration_mapping_get_range_count( + mapping); + label = bt_field_class_enumeration_mapping_get_label( + mapping); + /* * Iterate over all the ranges to add them to copied field * class. @@ -217,8 +223,8 @@ int field_class_unsigned_enumeration_copy( for (range_index = 0; range_index < range_count; range_index++) { uint64_t lower, upper; bt_field_class_status status; - bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index( - ranges, range_index, &lower, &upper); + bt_field_class_unsigned_enumeration_mapping_get_range_by_index( + u_mapping, range_index, &lower, &upper); BT_LOGD("Copying range in enumeration field class: " "label=%s, lower=%"PRId64", upper=%"PRId64, @@ -267,15 +273,21 @@ int field_class_signed_enumeration_copy( bt_field_class_enumeration_get_mapping_count(in_field_class); for (i = 0; i < enum_mapping_count; i++) { const char *label; - const bt_field_class_signed_enumeration_mapping_ranges *ranges; + const bt_field_class_signed_enumeration_mapping *i_mapping; + const bt_field_class_enumeration_mapping *mapping; uint64_t range_index, range_count; /* Get the ranges and the range count. */ - bt_field_class_signed_enumeration_borrow_mapping_by_index_const( - in_field_class, i, &label, &ranges); + i_mapping = bt_field_class_signed_enumeration_borrow_mapping_by_index_const( + in_field_class, i); + mapping = bt_field_class_signed_enumeration_mapping_as_mapping_const( + i_mapping); range_count = - bt_field_class_signed_enumeration_mapping_ranges_get_range_count( - ranges); + bt_field_class_enumeration_mapping_get_range_count( + mapping); + label = bt_field_class_enumeration_mapping_get_label( + mapping); + /* * Iterate over all the ranges to add them to copied field * class. @@ -283,8 +295,8 @@ int field_class_signed_enumeration_copy( for (range_index = 0; range_index < range_count; range_index++) { int64_t lower, upper; bt_field_class_status status; - bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index( - ranges, range_index, &lower, &upper); + bt_field_class_signed_enumeration_mapping_get_range_by_index( + i_mapping, range_index, &lower, &upper); BT_LOGD("Copying range in enumeration field class: " "label=%s, lower=%ld, upper=%ld", -- 2.34.1