lib: make trace IR API const-correct
[babeltrace.git] / plugins / libctfcopytrace / clock-fields.c
index 4e465827c4378d8a2fa6f625daa03553dfd1b64a..1e28c899327d457d2cbf6a69c1125baaf5927953 100644 (file)
 #include "logging.h"
 
 #include <babeltrace/babeltrace.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
 #include <stdio.h>
 
 #include "clock-fields.h"
 
 static
 int find_update_struct_clock_fields(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class);
+               const struct bt_clock_class *writer_clock_class);
 static
 int find_update_array_clock_fields(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class);
+               const struct bt_clock_class *writer_clock_class);
 static
 int find_update_enum_clock_fields(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class);
+               const struct bt_clock_class *writer_clock_class);
 static
 int find_update_sequence_clock_fields(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class);
+               const struct bt_clock_class *writer_clock_class);
 static
 int find_update_variant_clock_fields(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class);
+               const struct bt_clock_class *writer_clock_class);
 
 static
 int copy_find_clock_int_field(FILE *err,
-               struct bt_event *event, struct bt_event *writer_event,
-               struct bt_field *field, struct bt_field_type *type,
-               struct bt_field *copy_field);
+               const struct bt_event *event, const struct bt_event *writer_event,
+               const struct bt_field *field, struct bt_field_type *type,
+               const struct bt_field *copy_field);
 static
 int copy_find_clock_struct_field(FILE *err,
-               struct bt_event *event, struct bt_event *writer_event,
-               struct bt_field *field, struct bt_field_type *type,
-               struct bt_field *copy_field);
+               const struct bt_event *event, const struct bt_event *writer_event,
+               const struct bt_field *field, struct bt_field_type *type,
+               const struct bt_field *copy_field);
 static
 int copy_find_clock_array_field(FILE *err,
-               struct bt_event *event, struct bt_event *writer_event,
-               struct bt_field *field, struct bt_field_type *type,
-               struct bt_field *copy_field);
+               const struct bt_event *event, const struct bt_event *writer_event,
+               const struct bt_field *field, struct bt_field_type *type,
+               const struct bt_field *copy_field);
 static
 int copy_find_clock_sequence_field(FILE *err,
-               struct bt_event *event, struct bt_event *writer_event,
-               struct bt_field *field, struct bt_field_type *type,
-               struct bt_field *copy_field);
+               const struct bt_event *event, const struct bt_event *writer_event,
+               const struct bt_field *field, struct bt_field_type *type,
+               const struct bt_field *copy_field);
 static
-int copy_find_clock_variant_field(FILE *err, struct bt_event *event,
-               struct bt_event *writer_event, struct bt_field *field,
-               struct bt_field_type *type, struct bt_field *copy_field);
+int copy_find_clock_variant_field(FILE *err, const struct bt_event *event,
+               const struct bt_event *writer_event, const struct bt_field *field,
+               struct bt_field_type *type, const struct bt_field *copy_field);
 static
-int copy_find_clock_enum_field(FILE *err, struct bt_event *event,
-               struct bt_event *writer_event, struct bt_field *field,
-               struct bt_field_type *type, struct bt_field *copy_field);
+int copy_find_clock_enum_field(FILE *err, const struct bt_event *event,
+               const struct bt_event *writer_event, const struct bt_field *field,
+               struct bt_field_type *type, const struct bt_field *copy_field);
 
 static
 int update_header_clock_int_field_type(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class)
+               const struct bt_clock_class *writer_clock_class)
 {
-       struct bt_clock_class *clock = NULL;
+       const struct bt_clock_class *clock = NULL;
        int ret;
 
        clock = bt_field_type_integer_get_mapped_clock_class(type);
        if (!clock) {
                return 0;
        }
-       BT_PUT(clock);
+       BT_OBJECT_PUT_REF_AND_RESET(clock);
 
        ret = bt_field_type_integer_set_size(type, 64);
        if (ret) {
@@ -112,7 +112,7 @@ end:
 
 static
 int find_update_clock_fields(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class)
+               const struct bt_clock_class *writer_clock_class)
 {
        int ret;
 
@@ -147,7 +147,7 @@ int find_update_clock_fields(FILE *err, struct bt_field_type *type,
 
 static
 int find_update_variant_clock_fields(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class)
+               const struct bt_clock_class *writer_clock_class)
 {
        int count, i, ret;
        struct bt_field_type *entry_type = NULL;
@@ -169,7 +169,7 @@ int find_update_variant_clock_fields(FILE *err, struct bt_field_type *type,
                        BT_LOGE_STR("Failed to find clock fields.");
                        goto error;
                }
-               BT_PUT(entry_type);
+               BT_OBJECT_PUT_REF_AND_RESET(entry_type);
        }
 
        ret = 0;
@@ -178,13 +178,13 @@ int find_update_variant_clock_fields(FILE *err, struct bt_field_type *type,
 error:
        ret = -1;
 end:
-       bt_put(entry_type);
+       bt_object_put_ref(entry_type);
        return ret;
 }
 
 static
 int find_update_struct_clock_fields(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class)
+               const struct bt_clock_class *writer_clock_class)
 {
        int count, i, ret;
        struct bt_field_type *entry_type = NULL;
@@ -206,30 +206,30 @@ int find_update_struct_clock_fields(FILE *err, struct bt_field_type *type,
                        BT_LOGE_STR("Failed to find clock fields.");
                        goto error;
                }
-               BT_PUT(entry_type);
+               BT_OBJECT_PUT_REF_AND_RESET(entry_type);
        }
 
        ret = 0;
        goto end;
 
 error:
-       bt_put(entry_type);
+       bt_object_put_ref(entry_type);
 end:
        return ret;
 }
 
 static
 int find_update_sequence_clock_fields(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class)
+               const struct bt_clock_class *writer_clock_class)
 {
        int ret;
        struct bt_field_type *entry_type = NULL;
 
        entry_type = bt_field_type_sequence_get_element_type(type);
-       assert(entry_type);
+       BT_ASSERT(entry_type);
 
        ret = find_update_clock_fields(err, entry_type, writer_clock_class);
-       BT_PUT(entry_type);
+       BT_OBJECT_PUT_REF_AND_RESET(entry_type);
        if (ret) {
                BT_LOGE_STR("Failed to find clock fields.");
                goto error;
@@ -246,16 +246,16 @@ end:
 
 static
 int find_update_array_clock_fields(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class)
+               const struct bt_clock_class *writer_clock_class)
 {
        int ret = 0;
        struct bt_field_type *entry_type = NULL;
 
        entry_type = bt_field_type_array_get_element_type(type);
-       assert(entry_type);
+       BT_ASSERT(entry_type);
 
        ret = find_update_clock_fields(err, entry_type, writer_clock_class);
-       BT_PUT(entry_type);
+       BT_OBJECT_PUT_REF_AND_RESET(entry_type);
        if (ret) {
                BT_LOGE_STR("Failed to find clock fields.");
                ret = -1;
@@ -268,16 +268,16 @@ end:
 
 static
 int find_update_enum_clock_fields(FILE *err, struct bt_field_type *type,
-               struct bt_clock_class *writer_clock_class)
+               const struct bt_clock_class *writer_clock_class)
 {
        int ret;
        struct bt_field_type *entry_type = NULL;
 
        entry_type = bt_field_type_enumeration_get_container_type(type);
-       assert(entry_type);
+       BT_ASSERT(entry_type);
 
        ret = find_update_clock_fields(err, entry_type, writer_clock_class);
-       BT_PUT(entry_type);
+       BT_OBJECT_PUT_REF_AND_RESET(entry_type);
        if (ret) {
                BT_LOGE_STR("Failed to find clock fields.");
                goto error;
@@ -295,15 +295,15 @@ end:
 BT_HIDDEN
 struct bt_field_type *override_header_type(FILE *err,
                struct bt_field_type *type,
-               struct bt_trace *writer_trace)
+               const struct bt_trace *writer_trace)
 {
        struct bt_field_type *new_type = NULL;
-       struct bt_clock_class *writer_clock_class = NULL;
+       const struct bt_clock_class *writer_clock_class = NULL;
        int ret;
 
        /* FIXME multi-clock? */
        writer_clock_class = bt_trace_get_clock_class_by_index(writer_trace, 0);
-       assert(writer_clock_class);
+       BT_ASSERT(writer_clock_class);
 
        new_type = bt_field_type_copy(type);
        if (!new_type) {
@@ -322,21 +322,21 @@ struct bt_field_type *override_header_type(FILE *err,
                BT_LOGE_STR("Failed to find clock fields in struct.");
                goto error;
        }
-       BT_PUT(writer_clock_class);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_clock_class);
 
        goto end;
 
 error:
-       bt_put(writer_clock_class);
-       BT_PUT(new_type);
+       bt_object_put_ref(writer_clock_class);
+       BT_OBJECT_PUT_REF_AND_RESET(new_type);
 end:
        return new_type;
 }
 
 static
-int copy_float_field(FILE *err, struct bt_field *field,
+int copy_float_field(FILE *err, const struct bt_field *field,
                struct bt_field_type *type,
-               struct bt_field *copy_field)
+               const struct bt_field *copy_field)
 {
        double value;
        int ret;
@@ -364,9 +364,9 @@ end:
 }
 
 static
-int copy_string_field(FILE *err, struct bt_field *field,
+int copy_string_field(FILE *err, const struct bt_field *field,
                struct bt_field_type *type,
-               struct bt_field *copy_field)
+               const struct bt_field *copy_field)
 {
        const char *value;
        int ret;
@@ -394,15 +394,15 @@ end:
 }
 
 BT_HIDDEN
-int copy_override_field(FILE *err, struct bt_event *event,
-               struct bt_event *writer_event, struct bt_field *field,
-               struct bt_field *copy_field)
+int copy_override_field(FILE *err, const struct bt_event *event,
+               const struct bt_event *writer_event, const struct bt_field *field,
+               const struct bt_field *copy_field)
 {
        struct bt_field_type *type = NULL;
        int ret = 0;
 
        type = bt_field_get_type(field);
-       assert(type);
+       BT_ASSERT(type);
 
        switch (bt_field_type_get_type_id(type)) {
        case BT_FIELD_TYPE_ID_INTEGER:
@@ -441,24 +441,24 @@ int copy_override_field(FILE *err, struct bt_event *event,
                break;
        }
 
-       BT_PUT(type);
+       BT_OBJECT_PUT_REF_AND_RESET(type);
 
        return ret;
 }
 
 static
-int copy_find_clock_enum_field(FILE *err, struct bt_event *event,
-               struct bt_event *writer_event, struct bt_field *field,
-               struct bt_field_type *type, struct bt_field *copy_field)
+int copy_find_clock_enum_field(FILE *err, const struct bt_event *event,
+               const struct bt_event *writer_event, const struct bt_field *field,
+               struct bt_field_type *type, const struct bt_field *copy_field)
 {
        int ret;
-       struct bt_field *container = NULL, *copy_container = NULL;
+       const struct bt_field *container = NULL, *copy_container = NULL;
 
        container = bt_field_enumeration_get_container(field);
-       assert(container);
+       BT_ASSERT(container);
 
        copy_container = bt_field_enumeration_get_container(copy_field);
-       assert(copy_container);
+       BT_ASSERT(copy_container);
 
        ret = copy_override_field(err, event, writer_event, container,
                        copy_container);
@@ -474,22 +474,22 @@ int copy_find_clock_enum_field(FILE *err, struct bt_event *event,
 error:
        ret = -1;
 end:
-       bt_put(copy_container);
-       bt_put(container);
+       bt_object_put_ref(copy_container);
+       bt_object_put_ref(container);
        return ret;
 }
 
 static
-int copy_find_clock_variant_field(FILE *err, struct bt_event *event,
-               struct bt_event *writer_event, struct bt_field *field,
-               struct bt_field_type *type, struct bt_field *copy_field)
+int copy_find_clock_variant_field(FILE *err, const struct bt_event *event,
+               const struct bt_event *writer_event, const struct bt_field *field,
+               struct bt_field_type *type, const struct bt_field *copy_field)
 {
        int ret;
-       struct bt_field *tag = NULL;
-       struct bt_field *variant_field = NULL, *copy_variant_field = NULL;
+       const struct bt_field *tag = NULL;
+       const struct bt_field *variant_field = NULL, *copy_variant_field = NULL;
 
        tag = bt_field_variant_get_tag(field);
-       assert(tag);
+       BT_ASSERT(tag);
 
        variant_field = bt_field_variant_get_field(field, tag);
        if (!variant_field) {
@@ -498,7 +498,7 @@ int copy_find_clock_variant_field(FILE *err, struct bt_event *event,
        }
 
        copy_variant_field = bt_field_variant_get_field(copy_field, tag);
-       assert(copy_variant_field);
+       BT_ASSERT(copy_variant_field);
 
        ret = copy_override_field(err, event, writer_event, variant_field,
                        copy_variant_field);
@@ -513,25 +513,25 @@ int copy_find_clock_variant_field(FILE *err, struct bt_event *event,
 error:
        ret = -1;
 end:
-       bt_put(copy_variant_field);
-       bt_put(variant_field);
-       bt_put(tag);
+       bt_object_put_ref(copy_variant_field);
+       bt_object_put_ref(variant_field);
+       bt_object_put_ref(tag);
        return ret;
 }
 
 static
 int copy_find_clock_sequence_field(FILE *err,
-               struct bt_event *event, struct bt_event *writer_event,
-               struct bt_field *field, struct bt_field_type *type,
-               struct bt_field *copy_field)
+               const struct bt_event *event, const struct bt_event *writer_event,
+               const struct bt_field *field, struct bt_field_type *type,
+               const struct bt_field *copy_field)
 {
        int ret;
        uint64_t i, count;
-       struct bt_field *length_field = NULL;
-       struct bt_field *entry_field = NULL, *entry_copy = NULL;
+       const struct bt_field *length_field = NULL;
+       const struct bt_field *entry_field = NULL, *entry_copy = NULL;
 
        length_field = bt_field_sequence_get_length(field);
-       assert(length_field);
+       BT_ASSERT(length_field);
 
        ret = bt_field_unsigned_integer_get_value(length_field, &count);
        if (ret) {
@@ -544,7 +544,7 @@ int copy_find_clock_sequence_field(FILE *err,
                BT_LOGE_STR("Failed to set sequence length.");
                goto error;
        }
-       BT_PUT(length_field);
+       BT_OBJECT_PUT_REF_AND_RESET(length_field);
 
        for (i = 0; i < count; i++) {
                entry_field = bt_field_sequence_get_field(field, i);
@@ -554,7 +554,7 @@ int copy_find_clock_sequence_field(FILE *err,
                }
 
                entry_copy = bt_field_sequence_get_field(copy_field, i);
-               assert(entry_copy);
+               BT_ASSERT(entry_copy);
 
                ret = copy_override_field(err, event, writer_event, entry_field,
                                entry_copy);
@@ -562,17 +562,17 @@ int copy_find_clock_sequence_field(FILE *err,
                        BT_LOGE_STR("Faield to override field in sequence.");
                        goto error;
                }
-               BT_PUT(entry_field);
-               BT_PUT(entry_copy);
+               BT_OBJECT_PUT_REF_AND_RESET(entry_field);
+               BT_OBJECT_PUT_REF_AND_RESET(entry_copy);
        }
 
        ret = 0;
        goto end;
 
 error:
-       bt_put(length_field);
-       bt_put(entry_field);
-       bt_put(entry_copy);
+       bt_object_put_ref(length_field);
+       bt_object_put_ref(entry_field);
+       bt_object_put_ref(entry_copy);
        ret = -1;
 end:
        return ret;
@@ -580,12 +580,12 @@ end:
 
 static
 int copy_find_clock_array_field(FILE *err,
-               struct bt_event *event, struct bt_event *writer_event,
-               struct bt_field *field, struct bt_field_type *type,
-               struct bt_field *copy_field)
+               const struct bt_event *event, const struct bt_event *writer_event,
+               const struct bt_field *field, struct bt_field_type *type,
+               const struct bt_field *copy_field)
 {
        int ret, count, i;
-       struct bt_field *entry_field = NULL, *entry_copy = NULL;
+       const struct bt_field *entry_field = NULL, *entry_copy = NULL;
 
        count = bt_field_type_array_get_length(type);
        for (i = 0; i < count; i++) {
@@ -597,7 +597,7 @@ int copy_find_clock_array_field(FILE *err,
                }
 
                entry_copy = bt_field_array_get_field(copy_field, i);
-               assert(entry_copy);
+               BT_ASSERT(entry_copy);
 
                ret = copy_override_field(err, event, writer_event, entry_field,
                                entry_copy);
@@ -606,16 +606,16 @@ int copy_find_clock_array_field(FILE *err,
                        BT_LOGE_STR("Failed to override field in array.");
                        goto error;
                }
-               BT_PUT(entry_field);
-               BT_PUT(entry_copy);
+               BT_OBJECT_PUT_REF_AND_RESET(entry_field);
+               BT_OBJECT_PUT_REF_AND_RESET(entry_copy);
        }
 
        ret = 0;
        goto end;
 
 error:
-       bt_put(entry_field);
-       bt_put(entry_copy);
+       bt_object_put_ref(entry_field);
+       bt_object_put_ref(entry_copy);
 
 end:
        return ret;
@@ -623,13 +623,13 @@ end:
 
 static
 int copy_find_clock_struct_field(FILE *err,
-               struct bt_event *event, struct bt_event *writer_event,
-               struct bt_field *field, struct bt_field_type *type,
-               struct bt_field *copy_field)
+               const struct bt_event *event, const struct bt_event *writer_event,
+               const struct bt_field *field, struct bt_field_type *type,
+               const struct bt_field *copy_field)
 {
        int count, i, ret;
        struct bt_field_type *entry_type = NULL;
-       struct bt_field *entry_field = NULL, *entry_copy = NULL;
+       const struct bt_field *entry_field = NULL, *entry_copy = NULL;
 
        count = bt_field_type_structure_get_field_count(type);
        for (i = 0; i < count; i++) {
@@ -649,7 +649,7 @@ int copy_find_clock_struct_field(FILE *err,
                }
 
                entry_copy = bt_field_structure_get_field_by_index(copy_field, i);
-               assert(entry_copy);
+               BT_ASSERT(entry_copy);
 
                ret = copy_override_field(err, event, writer_event, entry_field,
                                entry_copy);
@@ -657,26 +657,26 @@ int copy_find_clock_struct_field(FILE *err,
                        BT_LOGE_STR("Failed to override field in struct.");
                        goto error;
                }
-               BT_PUT(entry_copy);
-               BT_PUT(entry_field);
-               BT_PUT(entry_type);
+               BT_OBJECT_PUT_REF_AND_RESET(entry_copy);
+               BT_OBJECT_PUT_REF_AND_RESET(entry_field);
+               BT_OBJECT_PUT_REF_AND_RESET(entry_type);
        }
 
        ret = 0;
        goto end;
 
 error:
-       bt_put(entry_type);
-       bt_put(entry_field);
-       bt_put(entry_copy);
+       bt_object_put_ref(entry_type);
+       bt_object_put_ref(entry_field);
+       bt_object_put_ref(entry_copy);
        ret = -1;
 end:
        return ret;
 }
 
 static
-int set_int_value(FILE *err, struct bt_field *field,
-               struct bt_field *copy_field,
+int set_int_value(FILE *err, const struct bt_field *field,
+               const struct bt_field *copy_field,
                struct bt_field_type *type)
 {
        uint64_t uvalue;
@@ -720,49 +720,49 @@ end:
        return ret;
 }
 
-struct bt_clock_class *stream_class_get_clock_class(FILE *err,
-               struct bt_stream_class *stream_class)
+const struct bt_clock_class *stream_class_get_clock_class(FILE *err,
+               const struct bt_stream_class *stream_class)
 {
-       struct bt_trace *trace = NULL;
-       struct bt_clock_class *clock_class = NULL;
+       const struct bt_trace *trace = NULL;
+       const struct bt_clock_class *clock_class = NULL;
 
        trace = bt_stream_class_get_trace(stream_class);
-       assert(trace);
+       BT_ASSERT(trace);
 
        /* FIXME multi-clock? */
        clock_class = bt_trace_get_clock_class_by_index(trace, 0);
 
-       bt_put(trace);
+       bt_object_put_ref(trace);
 
        return clock_class;
 }
 
-struct bt_clock_class *event_get_clock_class(FILE *err, struct bt_event *event)
+const struct bt_clock_class *event_get_clock_class(FILE *err, const struct bt_event *event)
 {
-       struct bt_event_class *event_class = NULL;
-       struct bt_stream_class *stream_class = NULL;
-       struct bt_clock_class *clock_class = NULL;
+       const struct bt_event_class *event_class = NULL;
+       const struct bt_stream_class *stream_class = NULL;
+       const struct bt_clock_class *clock_class = NULL;
 
        event_class = bt_event_get_class(event);
-       assert(event_class);
+       BT_ASSERT(event_class);
 
        stream_class = bt_event_class_get_stream_class(event_class);
-       BT_PUT(event_class);
-       assert(stream_class);
+       BT_OBJECT_PUT_REF_AND_RESET(event_class);
+       BT_ASSERT(stream_class);
 
        clock_class = stream_class_get_clock_class(err, stream_class);
-       bt_put(stream_class);
+       bt_object_put_ref(stream_class);
 
        return clock_class;
 }
 
 static
 int copy_find_clock_int_field(FILE *err,
-               struct bt_event *event, struct bt_event *writer_event,
-               struct bt_field *field, struct bt_field_type *type,
-               struct bt_field *copy_field)
+               const struct bt_event *event, const struct bt_event *writer_event,
+               const struct bt_field *field, struct bt_field_type *type,
+               const struct bt_field *copy_field)
 {
-       struct bt_clock_class *clock_class = NULL, *writer_clock_class = NULL;
+       const struct bt_clock_class *clock_class = NULL, *writer_clock_class = NULL;
        struct bt_clock_value *clock_value = NULL, *writer_clock_value = NULL;
        uint64_t value;
        int ret;
@@ -773,11 +773,11 @@ int copy_find_clock_int_field(FILE *err,
        }
 
        clock_value = bt_event_get_clock_value(event, clock_class);
-       BT_PUT(clock_class);
-       assert(clock_value);
+       BT_OBJECT_PUT_REF_AND_RESET(clock_class);
+       BT_ASSERT(clock_value);
 
        ret = bt_clock_value_get_value(clock_value, &value);
-       BT_PUT(clock_value);
+       BT_OBJECT_PUT_REF_AND_RESET(clock_value);
        if (ret) {
                BT_LOGE("Failed to get clock value.");
                goto error;
@@ -790,17 +790,17 @@ int copy_find_clock_int_field(FILE *err,
        }
 
        writer_clock_class = event_get_clock_class(err, writer_event);
-       assert(writer_clock_class);
+       BT_ASSERT(writer_clock_class);
 
        writer_clock_value = bt_clock_value_create(writer_clock_class, value);
-       BT_PUT(writer_clock_class);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_clock_class);
        if (!writer_clock_value) {
                BT_LOGE_STR("Failed to create clock value.");
                goto error;
        }
 
        ret = bt_event_set_clock_value(writer_event, writer_clock_value);
-       BT_PUT(writer_clock_value);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_clock_value);
        if (ret) {
                BT_LOGE_STR("Failed to set clock value.");
                goto error;
This page took 0.035218 seconds and 4 git commands to generate.