Fix: use of wrong enumeration_mapping_ranges type
[babeltrace.git] / lib / trace-ir / field-class.c
index 2361c5d5b805240a72e183b91803d5b89616ebc0..02a59d94301105f079917f0930f77f036b4a946e 100644 (file)
@@ -81,10 +81,12 @@ void destroy_integer_field_class(struct bt_object *obj)
 }
 
 static inline
-struct bt_field_class *create_integer_field_class(enum bt_field_class_type type)
+struct bt_field_class *create_integer_field_class(bt_trace_class *trace_class,
+               enum bt_field_class_type type)
 {
        struct bt_field_class_integer *int_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD("Creating default integer field class object: type=%s",
                bt_common_field_class_type_string(type));
        int_fc = g_new0(struct bt_field_class_integer, 1);
@@ -104,16 +106,17 @@ end:
        return (void *) int_fc;
 }
 
-struct bt_field_class *
-bt_field_class_unsigned_integer_create(void)
+struct bt_field_class *bt_field_class_unsigned_integer_create(
+               bt_trace_class *trace_class)
 {
-       return create_integer_field_class(
+       return create_integer_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER);
 }
 
-struct bt_field_class *bt_field_class_signed_integer_create(void)
+struct bt_field_class *bt_field_class_signed_integer_create(
+               bt_trace_class *trace_class)
 {
-       return create_integer_field_class(
+       return create_integer_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
 }
 
@@ -226,10 +229,11 @@ void destroy_enumeration_field_class(struct bt_object *obj)
 
 static
 struct bt_field_class *create_enumeration_field_class(
-               enum bt_field_class_type type)
+               bt_trace_class *trace_class, enum bt_field_class_type type)
 {
        struct bt_field_class_enumeration *enum_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD("Creating default enumeration field class object: type=%s",
                bt_common_field_class_type_string(type));
        enum_fc = g_new0(struct bt_field_class_enumeration, 1);
@@ -263,15 +267,17 @@ end:
        return (void *) enum_fc;
 }
 
-struct bt_field_class *bt_field_class_unsigned_enumeration_create(void)
+struct bt_field_class *bt_field_class_unsigned_enumeration_create(
+               bt_trace_class *trace_class)
 {
-       return create_enumeration_field_class(
+       return create_enumeration_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION);
 }
 
-struct bt_field_class *bt_field_class_signed_enumeration_create(void)
+struct bt_field_class *bt_field_class_signed_enumeration_create(
+               bt_trace_class *trace_class)
 {
-       return create_enumeration_field_class(
+       return create_enumeration_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION);
 }
 
@@ -370,7 +376,7 @@ void bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index(
 }
 
 void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index(
-               const struct bt_field_class_unsigned_enumeration_mapping_ranges *ranges,
+               const struct bt_field_class_signed_enumeration_mapping_ranges *ranges,
                uint64_t index, int64_t *lower, int64_t *upper)
 {
        get_enumeration_field_class_mapping_range_at_index(
@@ -380,7 +386,8 @@ void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index(
 
 
 
-int bt_field_class_unsigned_enumeration_get_mapping_labels_by_value(
+enum bt_field_class_status
+bt_field_class_unsigned_enumeration_get_mapping_labels_by_value(
                const struct bt_field_class *fc, uint64_t value,
                bt_field_class_enumeration_mapping_label_array *label_array,
                uint64_t *count)
@@ -416,10 +423,11 @@ int bt_field_class_unsigned_enumeration_get_mapping_labels_by_value(
 
        *label_array = (void *) enum_fc->label_buf->pdata;
        *count = (uint64_t) enum_fc->label_buf->len;
-       return 0;
+       return BT_FIELD_CLASS_STATUS_OK;
 }
 
-int bt_field_class_signed_enumeration_get_mapping_labels_by_value(
+enum bt_field_class_status
+bt_field_class_signed_enumeration_get_mapping_labels_by_value(
                const struct bt_field_class *fc, int64_t value,
                bt_field_class_enumeration_mapping_label_array *label_array,
                uint64_t *count)
@@ -455,14 +463,15 @@ int bt_field_class_signed_enumeration_get_mapping_labels_by_value(
 
        *label_array = (void *) enum_fc->label_buf->pdata;
        *count = (uint64_t) enum_fc->label_buf->len;
-       return 0;
+       return BT_FIELD_CLASS_STATUS_OK;
 }
 
 static inline
-int add_mapping_to_enumeration_field_class(struct bt_field_class *fc,
+enum bt_field_class_status add_mapping_to_enumeration_field_class(
+               struct bt_field_class *fc,
                const char *label, uint64_t lower, uint64_t upper)
 {
-       int ret = 0;
+       int ret = BT_FIELD_CLASS_STATUS_OK;
        uint64_t i;
        struct bt_field_class_enumeration *enum_fc = (void *) fc;
        struct bt_field_class_enumeration_mapping *mapping = NULL;
@@ -493,7 +502,7 @@ int add_mapping_to_enumeration_field_class(struct bt_field_class *fc,
                        finalize_enumeration_field_class_mapping(mapping);
                        g_array_set_size(enum_fc->mappings,
                                enum_fc->mappings->len - 1);
-                       ret = -1;
+                       ret = BT_FIELD_CLASS_STATUS_NOMEM;
                        goto end;
                }
 
@@ -502,7 +511,7 @@ int add_mapping_to_enumeration_field_class(struct bt_field_class *fc,
                        finalize_enumeration_field_class_mapping(mapping);
                        g_array_set_size(enum_fc->mappings,
                                enum_fc->mappings->len - 1);
-                       ret = -1;
+                       ret = BT_FIELD_CLASS_STATUS_NOMEM;
                        goto end;
                }
        }
@@ -522,7 +531,7 @@ end:
        return ret;
 }
 
-int bt_field_class_unsigned_enumeration_map_range(
+enum bt_field_class_status bt_field_class_unsigned_enumeration_map_range(
                struct bt_field_class *fc, const char *label,
                uint64_t range_lower, uint64_t range_upper)
 {
@@ -547,7 +556,7 @@ int bt_field_class_unsigned_enumeration_map_range(
                range_upper);
 }
 
-int bt_field_class_signed_enumeration_map_range(
+enum bt_field_class_status bt_field_class_signed_enumeration_map_range(
                struct bt_field_class *fc, const char *label,
                int64_t range_lower, int64_t range_upper)
 {
@@ -580,10 +589,11 @@ void destroy_real_field_class(struct bt_object *obj)
        g_free(obj);
 }
 
-struct bt_field_class *bt_field_class_real_create(void)
+struct bt_field_class *bt_field_class_real_create(bt_trace_class *trace_class)
 {
        struct bt_field_class_real *real_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default real field class object.");
        real_fc = g_new0(struct bt_field_class_real, 1);
        if (!real_fc) {
@@ -697,16 +707,18 @@ static
 void destroy_structure_field_class(struct bt_object *obj)
 {
        BT_ASSERT(obj);
-       BT_LIB_LOGD("Destroying string field class object: %!+F", obj);
+       BT_LIB_LOGD("Destroying structure field class object: %!+F", obj);
        finalize_named_field_classes_container((void *) obj);
        g_free(obj);
 }
 
-struct bt_field_class *bt_field_class_structure_create(void)
+struct bt_field_class *bt_field_class_structure_create(
+               bt_trace_class *trace_class)
 {
        int ret;
        struct bt_field_class_structure *struct_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default structure field class object.");
        struct_fc = g_new0(struct bt_field_class_structure, 1);
        if (!struct_fc) {
@@ -731,11 +743,11 @@ end:
 }
 
 static
-int append_named_field_class_to_container_field_class(
+enum bt_field_class_status append_named_field_class_to_container_field_class(
                struct bt_field_class_named_field_class_container *container_fc,
                const char *name, struct bt_field_class *fc)
 {
-       int ret = 0;
+       int ret = BT_FIELD_CLASS_STATUS_OK;
        struct bt_named_field_class *named_fc;
        GString *name_str;
 
@@ -750,7 +762,7 @@ int append_named_field_class_to_container_field_class(
        name_str = g_string_new(name);
        if (!name_str) {
                BT_LOGE_STR("Failed to allocate a GString.");
-               ret = -1;
+               ret = BT_FIELD_CLASS_STATUS_NOMEM;
                goto end;
        }
 
@@ -769,8 +781,9 @@ end:
        return ret;
 }
 
-int bt_field_class_structure_append_member(struct bt_field_class *fc,
-               const char *name, struct bt_field_class *member_fc)
+enum bt_field_class_status bt_field_class_structure_append_member(
+               struct bt_field_class *fc, const char *name,
+               struct bt_field_class *member_fc)
 {
 
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
@@ -843,7 +856,7 @@ end:
 }
 
 const struct bt_field_class *
-bt_field_class_structure_borrow_member_field_class_by_name(
+bt_field_class_structure_borrow_member_field_class_by_name_const(
                const struct bt_field_class *fc, const char *name)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
@@ -867,11 +880,13 @@ void destroy_variant_field_class(struct bt_object *obj)
        g_free(fc);
 }
 
-struct bt_field_class *bt_field_class_variant_create(void)
+struct bt_field_class *bt_field_class_variant_create(
+               bt_trace_class *trace_class)
 {
        int ret;
        struct bt_field_class_variant *var_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default variant field class object.");
        var_fc = g_new0(struct bt_field_class_variant, 1);
        if (!var_fc) {
@@ -895,7 +910,7 @@ end:
        return (void *) var_fc;
 }
 
-int bt_field_class_variant_set_selector_field_class(
+enum bt_field_class_status bt_field_class_variant_set_selector_field_class(
                struct bt_field_class *fc,
                struct bt_field_class *selector_fc)
 {
@@ -909,10 +924,10 @@ int bt_field_class_variant_set_selector_field_class(
        var_fc->selector_fc = selector_fc;
        bt_object_get_no_null_check(selector_fc);
        bt_field_class_freeze(selector_fc);
-       return 0;
+       return BT_FIELD_CLASS_STATUS_OK;
 }
 
-int bt_field_class_variant_append_option(
+enum bt_field_class_status bt_field_class_variant_append_option(
                struct bt_field_class *fc,
                const char *name, struct bt_field_class *option_fc)
 {
@@ -994,11 +1009,12 @@ void destroy_static_array_field_class(struct bt_object *obj)
 }
 
 struct bt_field_class *
-bt_field_class_static_array_create(struct bt_field_class *element_fc,
-               uint64_t length)
+bt_field_class_static_array_create(bt_trace_class *trace_class,
+               struct bt_field_class *element_fc, uint64_t length)
 {
        struct bt_field_class_static_array *array_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class");
        BT_LOGD_STR("Creating default static array field class object.");
        array_fc = g_new0(struct bt_field_class_static_array, 1);
@@ -1057,10 +1073,12 @@ void destroy_dynamic_array_field_class(struct bt_object *obj)
 }
 
 struct bt_field_class *bt_field_class_dynamic_array_create(
+               bt_trace_class *trace_class,
                struct bt_field_class *element_fc)
 {
        struct bt_field_class_dynamic_array *array_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class");
        BT_LOGD_STR("Creating default dynamic array field class object.");
        array_fc = g_new0(struct bt_field_class_dynamic_array, 1);
@@ -1082,7 +1100,7 @@ end:
        return (void *) array_fc;
 }
 
-int bt_field_class_dynamic_array_set_length_field_class(
+enum bt_field_class_status bt_field_class_dynamic_array_set_length_field_class(
                struct bt_field_class *fc,
                struct bt_field_class *length_fc)
 {
@@ -1097,7 +1115,7 @@ int bt_field_class_dynamic_array_set_length_field_class(
        array_fc->length_fc = length_fc;
        bt_object_get_no_null_check(length_fc);
        bt_field_class_freeze(length_fc);
-       return 0;
+       return BT_FIELD_CLASS_STATUS_OK;
 }
 
 const struct bt_field_path *
@@ -1120,10 +1138,11 @@ void destroy_string_field_class(struct bt_object *obj)
        g_free(obj);
 }
 
-struct bt_field_class *bt_field_class_string_create(void)
+struct bt_field_class *bt_field_class_string_create(bt_trace_class *trace_class)
 {
        struct bt_field_class_string *string_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default string field class object.");
        string_fc = g_new0(struct bt_field_class_string, 1);
        if (!string_fc) {
This page took 0.029135 seconds and 4 git commands to generate.