Always evaluate BT_ASSERT(); add BT_ASSERT_DBG() for debug mode only
[babeltrace.git] / src / ctf-writer / trace.c
index 82eb35b3501c4de01c4a3f93e98e1640a1877b7f..c31042fec58d48587d0f3b30f4a4fd3a9384eac3 100644 (file)
@@ -29,9 +29,9 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <babeltrace2/ctf-writer/event.h>
-#include <babeltrace2/ctf-writer/object.h>
-#include <babeltrace2/ctf-writer/utils.h>
+#include <babeltrace2-ctf-writer/event.h>
+#include <babeltrace2-ctf-writer/object.h>
+#include <babeltrace2-ctf-writer/utils.h>
 #include <babeltrace2/types.h>
 
 #include "common/assert.h"
@@ -180,7 +180,7 @@ end:
 
 BT_HIDDEN
 int bt_ctf_trace_common_set_uuid(struct bt_ctf_trace_common *trace,
-               const unsigned char *uuid)
+               const uint8_t *uuid)
 {
        int ret = 0;
 
@@ -204,27 +204,12 @@ int bt_ctf_trace_common_set_uuid(struct bt_ctf_trace_common *trace,
                goto end;
        }
 
-       memcpy(trace->uuid, uuid, BABELTRACE_UUID_LEN);
-       trace->uuid_set = BT_TRUE;
+       bt_uuid_copy(trace->uuid, uuid);
+       trace->uuid_set = BT_CTF_TRUE;
        BT_LOGT("Set trace's UUID: addr=%p, name=\"%s\", "
-               "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
+               "uuid=\"" BT_UUID_FMT "\"",
                trace, bt_ctf_trace_common_get_name(trace),
-               (unsigned int) uuid[0],
-               (unsigned int) uuid[1],
-               (unsigned int) uuid[2],
-               (unsigned int) uuid[3],
-               (unsigned int) uuid[4],
-               (unsigned int) uuid[5],
-               (unsigned int) uuid[6],
-               (unsigned int) uuid[7],
-               (unsigned int) uuid[8],
-               (unsigned int) uuid[9],
-               (unsigned int) uuid[10],
-               (unsigned int) uuid[11],
-               (unsigned int) uuid[12],
-               (unsigned int) uuid[13],
-               (unsigned int) uuid[14],
-               (unsigned int) uuid[15]);
+               BT_UUID_FMT_VALUES(uuid));
 
 end:
        return ret;
@@ -488,7 +473,7 @@ bool packet_header_field_type_is_valid(struct bt_ctf_trace_common *trace,
 
                ret = bt_ctf_field_type_common_structure_borrow_field_by_index(
                        packet_header_type, &field_name, NULL, 0);
-               BT_ASSERT(ret == 0);
+               BT_ASSERT_DBG(ret == 0);
 
                if (strcmp(field_name, "magic") != 0) {
                        BT_LOGW("Invalid packet header field type: `magic` field must be the first field: "
@@ -524,7 +509,7 @@ bool packet_header_field_type_is_valid(struct bt_ctf_trace_common *trace,
                }
 
                elem_ft = bt_ctf_field_type_common_array_borrow_element_field_type(field_type);
-               BT_ASSERT(elem_ft);
+               BT_ASSERT_DBG(elem_ft);
 
                if (elem_ft->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
                        BT_LOGW("Invalid packet header field type: `uuid` field's element field type must be an integer field type: "
@@ -844,7 +829,7 @@ bool event_header_field_type_is_valid(struct bt_ctf_trace_common *trace,
                        goto invalid;
                }
 
-               BT_ASSERT(int_ft);
+               BT_ASSERT_DBG(int_ft);
                if (bt_ctf_field_type_common_integer_is_signed(int_ft)) {
                        BT_LOGW("Invalid event header field type: `id` field must be an unsigned integer or enumeration field type: "
                                "id-ft-addr=%p", int_ft);
@@ -914,12 +899,12 @@ int bt_ctf_trace_common_add_stream_class(struct bt_ctf_trace_common *trace,
        struct bt_ctf_field_type_common *packet_context_type = NULL;
        struct bt_ctf_field_type_common *event_header_type = NULL;
        struct bt_ctf_field_type_common *stream_event_ctx_type = NULL;
-       int64_t event_class_count;
+       int64_t event_class_count = 0;
        struct bt_ctf_trace_common *current_parent_trace = NULL;
        struct bt_ctf_clock_class *expected_clock_class =
                bt_ctf_object_get_ref(init_expected_clock_class);
 
-       BT_ASSERT(copy_field_type_func);
+       BT_ASSERT_DBG(copy_field_type_func);
 
        if (!trace) {
                BT_LOGW_STR("Invalid parameter: trace is NULL.");
@@ -955,7 +940,7 @@ int bt_ctf_trace_common_add_stream_class(struct bt_ctf_trace_common *trace,
 
        event_class_count =
                bt_ctf_stream_class_common_get_event_class_count(stream_class);
-       BT_ASSERT(event_class_count >= 0);
+       BT_ASSERT_DBG(event_class_count >= 0);
 
        if (!stream_class->frozen) {
                /*
@@ -1271,13 +1256,13 @@ end:
 }
 
 BT_HIDDEN
-bt_bool bt_ctf_trace_common_has_clock_class(struct bt_ctf_trace_common *trace,
+bt_ctf_bool bt_ctf_trace_common_has_clock_class(struct bt_ctf_trace_common *trace,
                struct bt_ctf_clock_class *clock_class)
 {
        struct bt_ctf_search_query query = { .value = clock_class, .found = 0 };
 
-       BT_ASSERT(trace);
-       BT_ASSERT(clock_class);
+       BT_ASSERT_DBG(trace);
+       BT_ASSERT_DBG(clock_class);
 
        g_ptr_array_foreach(trace->clock_classes, value_exists, &query);
        return query.found;
@@ -1461,13 +1446,13 @@ error:
        return trace;
 }
 
-const unsigned char *bt_ctf_trace_get_uuid(struct bt_ctf_trace *trace)
+const uint8_t *bt_ctf_trace_get_uuid(struct bt_ctf_trace *trace)
 {
        return bt_ctf_trace_common_get_uuid(BT_CTF_TO_COMMON(trace));
 }
 
 int bt_ctf_trace_set_uuid(struct bt_ctf_trace *trace,
-               const unsigned char *uuid)
+               const uint8_t *uuid)
 {
        return bt_ctf_trace_common_set_uuid(BT_CTF_TO_COMMON(trace), uuid);
 }
@@ -1684,7 +1669,7 @@ static
 int append_trace_metadata(struct bt_ctf_trace *trace,
                struct metadata_context *context)
 {
-       unsigned char *uuid = trace->common.uuid;
+       uint8_t *uuid = trace->common.uuid;
        int ret = 0;
 
        if (trace->common.native_byte_order == BT_CTF_BYTE_ORDER_NATIVE ||
@@ -1700,17 +1685,14 @@ int append_trace_metadata(struct bt_ctf_trace *trace,
        g_string_append(context->string, "trace {\n");
        g_string_append(context->string, "\tmajor = 1;\n");
        g_string_append(context->string, "\tminor = 8;\n");
-       BT_ASSERT(trace->common.native_byte_order == BT_CTF_BYTE_ORDER_LITTLE_ENDIAN ||
+       BT_ASSERT_DBG(trace->common.native_byte_order == BT_CTF_BYTE_ORDER_LITTLE_ENDIAN ||
                trace->common.native_byte_order == BT_CTF_BYTE_ORDER_BIG_ENDIAN ||
                trace->common.native_byte_order == BT_CTF_BYTE_ORDER_NETWORK);
 
        if (trace->common.uuid_set) {
                g_string_append_printf(context->string,
-                       "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
-                       uuid[0], uuid[1], uuid[2], uuid[3],
-                       uuid[4], uuid[5], uuid[6], uuid[7],
-                       uuid[8], uuid[9], uuid[10], uuid[11],
-                       uuid[12], uuid[13], uuid[14], uuid[15]);
+                       "\tuuid = \"" BT_UUID_FMT "\";\n",
+                       BT_UUID_FMT_VALUES(uuid));
        }
 
        g_string_append_printf(context->string, "\tbyte_order = %s;\n",
@@ -1758,8 +1740,8 @@ void append_env_metadata(struct bt_ctf_trace *trace,
                env_field_value_obj = bt_ctf_attributes_borrow_field_value(
                        trace->common.environment, i);
 
-               BT_ASSERT(entry_name);
-               BT_ASSERT(env_field_value_obj);
+               BT_ASSERT_DBG(entry_name);
+               BT_ASSERT_DBG(env_field_value_obj);
 
                switch (bt_ctf_value_get_type(
                        bt_ctf_private_value_as_value(env_field_value_obj))) {
This page took 0.026131 seconds and 4 git commands to generate.