ctf.fs: bt_ctf_notif_iter_create(): assert() that all medops exist
[babeltrace.git] / formats / ctf / ir / field-types.c
index 49144162d49c9c25372a8e0963279453319cd61a..02a47b366d900cb0d5e1aa29019ab5a00558d480 100644 (file)
@@ -632,6 +632,33 @@ bool bt_ctf_field_type_enumeration_has_overlapping_ranges(
        return enumeration_type->has_overlapping_ranges;
 }
 
+static
+int bt_ctf_field_type_enumeration_get_mapping_name(
+               struct bt_ctf_field_type *enum_field_type,
+               int index,
+               const char **mapping_name)
+{
+       int ret = 0;
+       struct enumeration_mapping *mapping;
+
+       if (!enum_field_type || index < 0) {
+               ret = -1;
+               goto end;
+       }
+
+       mapping = get_enumeration_mapping(enum_field_type, index);
+       if (!mapping) {
+               ret = -1;
+               goto end;
+       }
+
+       if (mapping_name) {
+               *mapping_name = g_quark_to_string(mapping->string);
+       }
+end:
+       return ret;
+}
+
 static
 int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type *type)
 {
@@ -1119,50 +1146,6 @@ error:
        return NULL;
 }
 
-int bt_ctf_field_type_enumeration_get_mapping_name(
-               struct bt_ctf_field_type *enum_field_type,
-               int index,
-               const char **mapping_name)
-{
-       int ret = 0;
-       struct enumeration_mapping *mapping;
-
-       if (!enum_field_type || index < 0) {
-               ret = -1;
-               goto end;
-       }
-
-       mapping = get_enumeration_mapping(enum_field_type, index);
-       if (!mapping) {
-               ret = -1;
-               goto end;
-       }
-
-       if (mapping_name) {
-               *mapping_name = g_quark_to_string(mapping->string);
-       }
-end:
-       return ret;
-}
-
-int bt_ctf_field_type_enumeration_mapping_iterator_get_name(
-               struct bt_ctf_field_type_enumeration_mapping_iterator *iter,
-               const char **mapping_name)
-{
-       int ret = 0;
-
-       if (!iter) {
-               ret = -1;
-               goto end;
-       }
-
-       ret = bt_ctf_field_type_enumeration_get_mapping_name(
-                       &iter->enumeration_type->parent, iter->index,
-                       mapping_name);
-end:
-       return ret;
-}
-
 int bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
                struct bt_ctf_field_type_enumeration_mapping_iterator *iter,
                const char **mapping_name, int64_t *range_begin,
@@ -1879,22 +1862,30 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag(
                struct bt_ctf_field_type *type,
                struct bt_ctf_field *tag)
 {
+       int ret;
        const char *enum_value;
        struct bt_ctf_field_type *field_type = NULL;
+       struct bt_ctf_field_type_enumeration_mapping_iterator *iter = NULL;
 
        if (!type || !tag || type->declaration->id != BT_CTF_TYPE_ID_VARIANT) {
                goto end;
        }
 
-       enum_value = bt_ctf_field_enumeration_get_single_mapping_name(tag);
-       if (!enum_value) {
+       iter = bt_ctf_field_enumeration_get_mappings(tag);
+       if (!iter) {
+               goto end;
+       }
+
+       ret = bt_ctf_field_type_enumeration_mapping_iterator_get_signed(iter,
+               &enum_value, NULL, NULL);
+       if (ret) {
                goto end;
        }
 
-       /* Already increments field_type's reference count */
        field_type = bt_ctf_field_type_variant_get_field_type_by_name(
                type, enum_value);
 end:
+       bt_put(iter);
        return field_type;
 }
 
This page took 0.024326 seconds and 4 git commands to generate.