Fix: lib/ctf-ir/event-class.c: fix warnings on `ret` condition
[babeltrace.git] / lib / ctf-ir / field-types.c
index 4d7f3fee5971700fe0a9c18a5074c0d7a3814af2..6df6bdf1dabd4aca28d699b8181c694133bc0e3c 100644 (file)
@@ -306,6 +306,14 @@ void destroy_enumeration_mapping(struct enumeration_mapping *mapping)
 static
 void destroy_structure_field(struct structure_field *field)
 {
+       if (!field) {
+               return;
+       }
+
+       BT_LOGD("Destroying structure/variant field type's field object: "
+               "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
+               field, field->type, g_quark_to_string(field->name));
+       BT_LOGD_STR("Putting field type.");
        bt_put(field->type);
        g_free(field);
 }
@@ -397,8 +405,12 @@ void bt_ctf_field_type_init(struct bt_ctf_field_type *type, bt_bool init_bo)
        type->serialize = type_serialize_funcs[type->id];
 
        if (init_bo) {
-               int ret = bt_ctf_field_type_set_byte_order(type,
-                       BT_CTF_BYTE_ORDER_NATIVE);
+               int ret;
+               const enum bt_ctf_byte_order bo = BT_CTF_BYTE_ORDER_NATIVE;
+
+               BT_LOGD("Setting initial field type's byte order: bo=%s",
+                       bt_ctf_byte_order_string(bo));
+               ret = bt_ctf_field_type_set_byte_order(type, bo);
                assert(ret == 0);
        }
 
@@ -450,15 +462,10 @@ void bt_ctf_field_type_destroy(struct bt_object *obj)
        struct bt_ctf_field_type *type;
        enum bt_ctf_field_type_id type_id;
 
-       BT_LOGD("Destroying field type object: addr=%p", obj);
        type = container_of(obj, struct bt_ctf_field_type, base);
        type_id = type->id;
-       if (type_id <= BT_CTF_FIELD_TYPE_ID_UNKNOWN ||
-                       type_id >= BT_CTF_NR_TYPE_IDS) {
-               BT_LOGW("Unknown field type ID: addr=%p, id=%d", obj, type_id);
-               return;
-       }
-
+       assert(type_id > BT_CTF_FIELD_TYPE_ID_UNKNOWN &&
+               type_id < BT_CTF_NR_TYPE_IDS);
        type_destroy_funcs[type_id](type);
 }
 
@@ -749,6 +756,7 @@ int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type *type)
        tag_mappings_count =
                bt_ctf_field_type_enumeration_get_mapping_count(
                        (struct bt_ctf_field_type *) variant->tag);
+       assert(tag_mappings_count >= 0);
 
        /*
         * Validate that each mapping found in the tag has a name which
@@ -844,6 +852,7 @@ int bt_ctf_field_type_validate(struct bt_ctf_field_type *type)
 
        if (!ret && type->frozen) {
                /* Field type is valid */
+               BT_LOGV("Marking field type as valid: addr=%p", type);
                type->valid = 1;
        }
 
@@ -1225,6 +1234,9 @@ void bt_ctf_field_type_enum_iter_destroy(struct bt_object *obj)
                        struct bt_ctf_field_type_enumeration_mapping_iterator,
                        base);
 
+       BT_LOGD("Destroying enumeration field type mapping iterator: addr=%p",
+               obj);
+       BT_LOGD_STR("Putting parent enumeration field type.");
        bt_put(&iter->enumeration_type->parent);
        g_free(iter);
 }
@@ -1283,13 +1295,18 @@ bt_ctf_field_type_enumeration_find_mappings_by_name(
 
        iter->u.name_quark = g_quark_try_string(name);
        if (!iter->u.name_quark) {
-               BT_LOGE("Cannot get GQuark: string=\"%s\"", name);
+               BT_LOGV("No such enumeration field type mapping name: "
+                       "ft-addr=%p, mapping-name=\"%s\"",
+                       type, name);
                goto error;
        }
 
        /* Advance iterator to first entry, or leave index at -1. */
        if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter)) {
                /* No entry found. */
+               BT_LOGV("No such enumeration field type mapping name: "
+                       "ft-addr=%p, mapping-name=\"%s\"",
+                       type, name);
                goto error;
        }
 
@@ -1349,6 +1366,8 @@ int bt_ctf_field_type_enumeration_mapping_iterator_next(
                        break;
                }
                default:
+                       BT_LOGF("Invalid enumeration field type mapping iterator type: "
+                               "type=%d", iter->type);
                        abort();
                }
        }
@@ -1497,6 +1516,7 @@ int bt_ctf_field_type_enumeration_get_mapping_signed(
 
        if (mapping_name) {
                *mapping_name = g_quark_to_string(mapping->string);
+               assert(*mapping_name);
        }
 
        if (range_begin) {
@@ -1534,6 +1554,7 @@ int bt_ctf_field_type_enumeration_get_mapping_unsigned(
 
        if (mapping_name) {
                *mapping_name = g_quark_to_string(mapping->string);
+               assert(*mapping_name);
        }
 
        if (range_begin) {
@@ -2154,6 +2175,7 @@ int bt_ctf_field_type_structure_get_field_by_index(
        }
        if (field_name) {
                *field_name = g_quark_to_string(field->name);
+               assert(*field_name);
        }
 end:
        return ret;
@@ -2181,14 +2203,19 @@ struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name(
 
        name_quark = g_quark_try_string(name);
        if (!name_quark) {
-               BT_LOGE("Cannot get GQuark: string=\"%s\"", name);
+               BT_LOGV("No such structure field type field name: "
+                       "ft-addr=%p, field-name=\"%s\"",
+                       type, name);
                goto end;
        }
 
        structure = container_of(type, struct bt_ctf_field_type_structure,
                parent);
        if (!g_hash_table_lookup_extended(structure->field_name_to_index,
-               GUINT_TO_POINTER(name_quark), NULL, (gpointer *)&index)) {
+                       GUINT_TO_POINTER(name_quark), NULL, (gpointer *)&index)) {
+               BT_LOGV("No such structure field type field name: "
+                       "ft-addr=%p, field-name=\"%s\"",
+                       type, name);
                goto end;
        }
 
@@ -2465,13 +2492,18 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name(
 
        name_quark = g_quark_try_string(field_name);
        if (!name_quark) {
-               BT_LOGE("Cannot get GQuark: string=\"%s\"", field_name);
+               BT_LOGV("No such variant field type field name: "
+                       "ft-addr=%p, field-name=\"%s\"",
+                       type, field_name);
                goto end;
        }
 
        variant = container_of(type, struct bt_ctf_field_type_variant, parent);
        if (!g_hash_table_lookup_extended(variant->field_name_to_index,
-               GUINT_TO_POINTER(name_quark), NULL, (gpointer *)&index)) {
+                       GUINT_TO_POINTER(name_quark), NULL, (gpointer *)&index)) {
+               BT_LOGV("No such variant field type field name: "
+                       "ft-addr=%p, field-name=\"%s\"",
+                       type, field_name);
                goto end;
        }
 
@@ -2596,6 +2628,7 @@ int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type *type,
        }
        if (field_name) {
                *field_name = g_quark_to_string(field->name);
+               assert(*field_name);
        }
 end:
        return ret;
@@ -3251,7 +3284,6 @@ void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type)
                return;
        }
 
-       BT_LOGD("Freezing field type: addr=%p", type);
        type->freeze(type);
 }
 
@@ -3279,7 +3311,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed(
 
        field_name_quark = query.mapping_name;
        if (!g_hash_table_lookup_extended(variant->field_name_to_index,
-               GUINT_TO_POINTER(field_name_quark), NULL, &index)) {
+                       GUINT_TO_POINTER(field_name_quark), NULL, &index)) {
                goto end;
        }
 
@@ -3333,13 +3365,11 @@ int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type,
        assert(type);
        assert(context);
 
-       BT_LOGD("Serializing field type's metadata: "
-               "ft-addr=%p, metadata-context-addr=%p", type, context);
-
        /* Make sure field type is valid before serializing it */
        ret = bt_ctf_field_type_validate(type);
        if (ret) {
-               BT_LOGW_STR("Cannot serialize field type's metadata: field type is invalid.");
+               BT_LOGW("Cannot serialize field type's metadata: field type is invalid: "
+                       "addr=%p", type);
                goto end;
        }
 
@@ -3352,8 +3382,6 @@ struct bt_ctf_field_type *bt_ctf_field_type_copy(struct bt_ctf_field_type *type)
 {
        struct bt_ctf_field_type *copy = NULL;
 
-       BT_LOGD("Copying field type object: addr=%p", type);
-
        if (!type) {
                BT_LOGW_STR("Invalid parameter: field type is NULL.");
                goto end;
@@ -3366,7 +3394,6 @@ struct bt_ctf_field_type *bt_ctf_field_type_copy(struct bt_ctf_field_type *type)
        }
 
        copy->alignment = type->alignment;
-       BT_LOGD("Copied field type object: copy-ft-addr=%p", copy);
 end:
        return copy;
 }
@@ -3402,7 +3429,9 @@ int bt_ctf_field_type_structure_get_field_name_index(
 
        name_quark = g_quark_try_string(name);
        if (!name_quark) {
-               BT_LOGE("Cannot get GQuark: string=\"%s\"", name);
+               BT_LOGV("No such structure field type field name: "
+                       "ft-addr=%p, field-name=\"%s\"",
+                       type, name);
                ret = -1;
                goto end;
        }
@@ -3410,7 +3439,11 @@ int bt_ctf_field_type_structure_get_field_name_index(
        structure = container_of(type, struct bt_ctf_field_type_structure,
                parent);
        if (!g_hash_table_lookup_extended(structure->field_name_to_index,
-               GUINT_TO_POINTER(name_quark), NULL, (gpointer *)&index)) {
+                       GUINT_TO_POINTER(name_quark),
+                       NULL, (gpointer *)&index)) {
+               BT_LOGV("No such structure field type field name: "
+                       "ft-addr=%p, field-name=\"%s\"",
+                       type, name);
                ret = -1;
                goto end;
        }
@@ -3450,7 +3483,9 @@ int bt_ctf_field_type_variant_get_field_name_index(
 
        name_quark = g_quark_try_string(name);
        if (!name_quark) {
-               BT_LOGE("Cannot get GQuark: string=\"%s\"", name);
+               BT_LOGV("No such variant field type field name: "
+                       "ft-addr=%p, field-name=\"%s\"",
+                       type, name);
                ret = -1;
                goto end;
        }
@@ -3458,7 +3493,11 @@ int bt_ctf_field_type_variant_get_field_name_index(
        variant = container_of(type, struct bt_ctf_field_type_variant,
                parent);
        if (!g_hash_table_lookup_extended(variant->field_name_to_index,
-               GUINT_TO_POINTER(name_quark), NULL, (gpointer *)&index)) {
+                       GUINT_TO_POINTER(name_quark),
+                       NULL, (gpointer *)&index)) {
+               BT_LOGV("No such variant field type field name: "
+                       "ft-addr=%p, field-name=\"%s\"",
+                       type, name);
                ret = -1;
                goto end;
        }
@@ -3582,6 +3621,7 @@ void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type *type)
        }
 
        BT_LOGD("Destroying integer field type object: addr=%p", type);
+       BT_LOGD_STR("Putting mapped clock class.");
        bt_put(integer->mapped_clock);
        g_free(integer);
 }
@@ -3598,6 +3638,7 @@ void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type *type)
 
        BT_LOGD("Destroying enumeration field type object: addr=%p", type);
        g_ptr_array_free(enumeration->entries, TRUE);
+       BT_LOGD_STR("Putting container field type.");
        bt_put(enumeration->container);
        g_free(enumeration);
 }
@@ -3646,6 +3687,7 @@ void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type *type)
        g_ptr_array_free(variant->fields, TRUE);
        g_hash_table_destroy(variant->field_name_to_index);
        g_string_free(variant->tag_name, TRUE);
+       BT_LOGD_STR("Putting tag field type.");
        bt_put(&variant->tag->parent);
        BT_PUT(variant->tag_field_path);
        g_free(variant);
@@ -3662,6 +3704,7 @@ void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type *type)
        }
 
        BT_LOGD("Destroying array field type object: addr=%p", type);
+       BT_LOGD_STR("Putting element field type.");
        bt_put(array->element_type);
        g_free(array);
 }
@@ -3677,8 +3720,10 @@ void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type *type)
        }
 
        BT_LOGD("Destroying sequence field type object: addr=%p", type);
+       BT_LOGD_STR("Putting element field type.");
        bt_put(sequence->element_type);
        g_string_free(sequence->length_field_name, TRUE);
+       BT_LOGD_STR("Putting length field path.");
        BT_PUT(sequence->length_field_path);
        g_free(sequence);
 }
@@ -3712,6 +3757,7 @@ void bt_ctf_field_type_integer_freeze(struct bt_ctf_field_type *type)
        BT_LOGD("Freezing integer field type object: addr=%p", type);
 
        if (integer_type->mapped_clock) {
+               BT_LOGD_STR("Freezing integer field type's mapped clock class.");
                bt_ctf_clock_class_freeze(integer_type->mapped_clock);
        }
 
@@ -3727,13 +3773,17 @@ void bt_ctf_field_type_enumeration_freeze(struct bt_ctf_field_type *type)
        BT_LOGD("Freezing enumeration field type object: addr=%p", type);
        set_enumeration_range_overlap(type);
        generic_field_type_freeze(type);
+       BT_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p",
+               enumeration_type->container);
        bt_ctf_field_type_freeze(enumeration_type->container);
 }
 
 static
 void freeze_structure_field(struct structure_field *field)
 {
-       BT_LOGD("Freezing structure field type field: addr=%p", field);
+       BT_LOGD("Freezing structure/variant field type field: field-addr=%p, "
+               "field-ft-addr=%p, field-name=\"%s\"", field,
+               field->type, g_quark_to_string(field->name));
        bt_ctf_field_type_freeze(field->type);
 }
 
@@ -3773,6 +3823,8 @@ void bt_ctf_field_type_array_freeze(struct bt_ctf_field_type *type)
        BT_LOGD("Freezing array field type object: addr=%p", type);
        type->alignment = bt_ctf_field_type_get_alignment(type);
        generic_field_type_freeze(type);
+       BT_LOGD("Freezing array field type object's element field type: element-ft-addr=%p",
+               array_type->element_type);
        bt_ctf_field_type_freeze(array_type->element_type);
 }
 
@@ -3786,6 +3838,8 @@ void bt_ctf_field_type_sequence_freeze(struct bt_ctf_field_type *type)
        BT_LOGD("Freezing sequence field type object: addr=%p", type);
        type->alignment = bt_ctf_field_type_get_alignment(type);
        generic_field_type_freeze(type);
+       BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
+               sequence_type->element_type);
        bt_ctf_field_type_freeze(sequence_type->element_type);
 }
 
@@ -3886,6 +3940,7 @@ int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type *type,
        container_signed = bt_ctf_field_type_integer_get_signed(container_type);
        assert(container_signed >= 0);
        g_string_append(context->string, "enum : ");
+       BT_LOGD_STR("Serializing enumeration field type's container field type's metadata.");
        ret = bt_ctf_field_type_serialize(enumeration->container, context);
        if (ret) {
                BT_LOGW("Cannot serialize enumeration field type's container field type's metadata: "
@@ -3982,7 +4037,7 @@ int bt_ctf_field_type_structure_serialize(struct bt_ctf_field_type *type,
        for (i = 0; i < structure->fields->len; i++) {
                struct structure_field *field = structure->fields->pdata[i];
 
-               BT_LOGV("Serializing structure field type's field metadata: "
+               BT_LOGD("Serializing structure field type's field metadata: "
                        "index=%" PRId64 ", "
                        "field-ft-addr=%p, field-name=\"%s\"",
                        i, field, g_quark_to_string(field->name));
@@ -4050,7 +4105,7 @@ int bt_ctf_field_type_variant_serialize(struct bt_ctf_field_type *type,
        for (i = 0; i < variant->fields->len; i++) {
                struct structure_field *field = variant->fields->pdata[i];
 
-               BT_LOGV("Serializing variant field type's field metadata: "
+               BT_LOGD("Serializing variant field type's field metadata: "
                        "index=%" PRId64 ", "
                        "field-ft-addr=%p, field-name=\"%s\"",
                        i, field, g_quark_to_string(field->name));
@@ -4105,6 +4160,7 @@ int bt_ctf_field_type_array_serialize(struct bt_ctf_field_type *type,
 
        BT_LOGD("Serializing array field type's metadata: "
                "ft-addr=%p, metadata-context-addr=%p", type, context);
+       BT_LOGD_STR("Serializing array field type's element field type's metadata.");
        ret = bt_ctf_field_type_serialize(array->element_type, context);
        if (ret) {
                BT_LOGW("Cannot serialize array field type's element field type's metadata: "
@@ -4133,6 +4189,7 @@ int bt_ctf_field_type_sequence_serialize(struct bt_ctf_field_type *type,
 
        BT_LOGD("Serializing sequence field type's metadata: "
                "ft-addr=%p, metadata-context-addr=%p", type, context);
+       BT_LOGD_STR("Serializing sequence field type's element field type's metadata.");
        ret = bt_ctf_field_type_serialize(sequence->element_type, context);
        if (ret) {
                BT_LOGW("Cannot serialize sequence field type's element field type's metadata: "
@@ -4316,6 +4373,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_enumeration_copy(
                parent);
 
        /* Copy the source enumeration's container */
+       BT_LOGD_STR("Copying enumeration field type's container field type.");
        copy_container = bt_ctf_field_type_copy(enumeration->container);
        if (!copy_container) {
                BT_LOGE_STR("Cannot copy enumeration field type's container field type.");
@@ -4419,7 +4477,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_structure_copy(
                struct bt_ctf_field_type *copy_field;
 
                entry = g_ptr_array_index(structure->fields, i);
-               BT_LOGV("Copying structure field type's field: "
+               BT_LOGD("Copying structure field type's field: "
                        "index=%" PRId64 ", "
                        "field-ft-addr=%p, field-name=\"%s\"",
                        i, entry, g_quark_to_string(entry->name));
@@ -4468,6 +4526,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_copy(
        variant = container_of(type, struct bt_ctf_field_type_variant,
                parent);
        if (variant->tag) {
+               BT_LOGD_STR("Copying variant field type's tag field type.");
                copy_tag = bt_ctf_field_type_copy(&variant->tag->parent);
                if (!copy_tag) {
                        BT_LOGE_STR("Cannot copy variant field type's tag field type.");
@@ -4497,7 +4556,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_copy(
                struct bt_ctf_field_type *copy_field;
 
                entry = g_ptr_array_index(variant->fields, i);
-               BT_LOGV("Copying variant field type's field: "
+               BT_LOGD("Copying variant field type's field: "
                        "index=%" PRId64 ", "
                        "field-ft-addr=%p, field-name=\"%s\"",
                        i, entry, g_quark_to_string(entry->name));
@@ -4523,7 +4582,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_copy(
        }
 
        if (variant->tag_field_path) {
-               BT_LOGV_STR("Copying variant field type's tag field path.");
+               BT_LOGD_STR("Copying variant field type's tag field path.");
                copy_variant->tag_field_path = bt_ctf_field_path_copy(
                        variant->tag_field_path);
                if (!copy_variant->tag_field_path) {
@@ -4554,6 +4613,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_array_copy(
        BT_LOGD("Copying array field type's: addr=%p", type);
        array = container_of(type, struct bt_ctf_field_type_array,
                parent);
+       BT_LOGD_STR("Copying array field type's element field type.");
        copy_element = bt_ctf_field_type_copy(array->element_type);
        if (!copy_element) {
                BT_LOGE_STR("Cannot copy array field type's element field type.");
@@ -4584,6 +4644,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_sequence_copy(
        BT_LOGD("Copying sequence field type's: addr=%p", type);
        sequence = container_of(type, struct bt_ctf_field_type_sequence,
                parent);
+       BT_LOGD_STR("Copying sequence field type's element field type.");
        copy_element = bt_ctf_field_type_copy(sequence->element_type);
        if (!copy_element) {
                BT_LOGE_STR("Cannot copy sequence field type's element field type.");
@@ -4601,7 +4662,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_sequence_copy(
        copy_sequence = container_of(copy, struct bt_ctf_field_type_sequence,
                parent);
        if (sequence->length_field_path) {
-               BT_LOGV_STR("Copying sequence field type's length field path.");
+               BT_LOGD_STR("Copying sequence field type's length field path.");
                copy_sequence->length_field_path = bt_ctf_field_path_copy(
                        sequence->length_field_path);
                if (!copy_sequence->length_field_path) {
This page took 0.0308 seconds and 4 git commands to generate.