lib: metadata: transform fast path precond. checks to BT_ASSERT_PRE()
[babeltrace.git] / lib / ctf-ir / event-class.c
index 8e685eb70763f9e7d77d6411dee865c00e599c30..5ff9d0d481c06feea7c9df1ef6ee6dd46509461d 100644 (file)
@@ -45,6 +45,8 @@
 #include <babeltrace/endian-internal.h>
 #include <babeltrace/types.h>
 #include <babeltrace/values-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
 #include <inttypes.h>
 #include <stdlib.h>
 
@@ -104,33 +106,15 @@ error:
 
 const char *bt_event_class_get_name(struct bt_event_class *event_class)
 {
-       const char *name = NULL;
-
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               goto end;
-       }
-
-       name = event_class->name->str;
-
-end:
-       return name;
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
+       BT_ASSERT(event_class->name);
+       return event_class->name->str;
 }
 
 int64_t bt_event_class_get_id(struct bt_event_class *event_class)
 {
-       int64_t ret = 0;
-
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               ret = (int64_t) -1;
-               goto end;
-       }
-
-       ret = event_class->id;
-
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
+       return event_class->id;
 }
 
 int bt_event_class_set_id(struct bt_event_class *event_class,
@@ -175,18 +159,8 @@ end:
 enum bt_event_class_log_level bt_event_class_get_log_level(
                struct bt_event_class *event_class)
 {
-       enum bt_event_class_log_level log_level;
-
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               log_level = BT_EVENT_CLASS_LOG_LEVEL_UNKNOWN;
-               goto end;
-       }
-
-       log_level = event_class->log_level;
-
-end:
-       return log_level;
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
+       return event_class->log_level;
 }
 
 int bt_event_class_set_log_level(struct bt_event_class *event_class,
@@ -252,16 +226,12 @@ const char *bt_event_class_get_emf_uri(
 {
        const char *emf_uri = NULL;
 
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
 
        if (event_class->emf_uri->len > 0) {
                emf_uri = event_class->emf_uri->str;
        }
 
-end:
        return emf_uri;
 }
 
@@ -312,25 +282,15 @@ end:
 struct bt_stream_class *bt_event_class_get_stream_class(
                struct bt_event_class *event_class)
 {
-       return event_class ?
-               bt_get(bt_event_class_borrow_stream_class(event_class)) :
-               NULL;
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
+       return bt_get(bt_event_class_borrow_stream_class(event_class));
 }
 
 struct bt_field_type *bt_event_class_get_payload_type(
                struct bt_event_class *event_class)
 {
-       struct bt_field_type *payload = NULL;
-
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               goto end;
-       }
-
-       bt_get(event_class->fields);
-       payload = event_class->fields;
-end:
-       return payload;
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
+       return bt_get(event_class->fields);
 }
 
 int bt_event_class_set_payload_type(struct bt_event_class *event_class,
@@ -410,7 +370,7 @@ int bt_event_class_add_field(struct bt_event_class *event_class,
                goto end;
        }
 
-       assert(bt_field_type_get_type_id(event_class->fields) ==
+       BT_ASSERT(bt_field_type_get_type_id(event_class->fields) ==
                BT_FIELD_TYPE_ID_STRUCT);
        ret = bt_field_type_structure_add_field(event_class->fields,
                type, name);
@@ -443,7 +403,7 @@ int64_t bt_event_class_get_payload_type_field_count(
                goto end;
        }
 
-       assert(bt_field_type_get_type_id(event_class->fields) ==
+       BT_ASSERT(bt_field_type_get_type_id(event_class->fields) ==
                BT_FIELD_TYPE_ID_STRUCT);
        ret = bt_field_type_structure_get_field_count(event_class->fields);
 end:
@@ -472,7 +432,7 @@ int bt_event_class_get_payload_type_field_by_index(
                goto end;
        }
 
-       assert(bt_field_type_get_type_id(event_class->fields) ==
+       BT_ASSERT(bt_field_type_get_type_id(event_class->fields) ==
                BT_FIELD_TYPE_ID_STRUCT);
        ret = bt_field_type_structure_get_field_by_index(event_class->fields,
                field_name, field_type, index);
@@ -502,7 +462,7 @@ bt_event_class_get_payload_type_field_type_by_name(
                goto end;
        }
 
-       assert(bt_field_type_get_type_id(event_class->fields) ==
+       BT_ASSERT(bt_field_type_get_type_id(event_class->fields) ==
                BT_FIELD_TYPE_ID_STRUCT);
        name_quark = g_quark_try_string(name);
        if (!name_quark) {
@@ -525,10 +485,7 @@ struct bt_field_type *bt_event_class_get_context_type(
 {
        struct bt_field_type *context_type = NULL;
 
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
 
        if (!event_class->context) {
                BT_LOGV("Event class has no context field type: "
@@ -538,8 +495,8 @@ struct bt_field_type *bt_event_class_get_context_type(
                goto end;
        }
 
-       bt_get(event_class->context);
-       context_type = event_class->context;
+       context_type = bt_get(event_class->context);
+
 end:
        return context_type;
 }
@@ -623,7 +580,7 @@ void bt_event_class_destroy(struct bt_object *obj)
 BT_HIDDEN
 void bt_event_class_freeze(struct bt_event_class *event_class)
 {
-       assert(event_class);
+       BT_ASSERT(event_class);
 
        if (event_class->frozen) {
                return;
@@ -646,8 +603,8 @@ int bt_event_class_serialize(struct bt_event_class *event_class,
        int ret = 0;
        struct bt_value *attr_value = NULL;
 
-       assert(event_class);
-       assert(context);
+       BT_ASSERT(event_class);
+       BT_ASSERT(context);
        BT_LOGD("Serializing event class's metadata: "
                "event-class-addr=%p, event-class-name=\"%s\", "
                "event-class-id=%" PRId64 ", metadata-context-addr=%p",
@@ -660,7 +617,7 @@ int bt_event_class_serialize(struct bt_event_class *event_class,
        /* Serialize attributes */
        g_string_append_printf(context->string, "\tname = \"%s\";\n",
                event_class->name->str);
-       assert(event_class->id >= 0);
+       BT_ASSERT(event_class->id >= 0);
        g_string_append_printf(context->string, "\tid = %" PRId64 ";\n",
                event_class->id);
        g_string_append_printf(context->string, "\tstream_id = %" PRId64 ";\n",
@@ -718,8 +675,8 @@ int bt_event_class_validate_single_clock_class(
 {
        int ret = 0;
 
-       assert(event_class);
-       assert(expected_clock_class);
+       BT_ASSERT(event_class);
+       BT_ASSERT(expected_clock_class);
        ret = bt_validate_single_clock_class(event_class->context,
                expected_clock_class);
        if (ret) {
This page took 0.027021 seconds and 4 git commands to generate.