lib: rename functions to clearly indicate API inheritance
[babeltrace.git] / src / lib / trace-ir / field.c
index 31d9803e77e1f1517bd6d366b3a28180282ccfd9..e200c153fa6b7757514e355cdaa9df3991450278 100644 (file)
@@ -21,8 +21,8 @@
  * SOFTWARE.
  */
 
-#define BT_LOG_TAG "FIELDS"
-#include "lib/lib-logging.h"
+#define BT_LOG_TAG "LIB/FIELD"
+#include "lib/logging.h"
 
 #include "lib/assert-pre.h"
 #include <babeltrace2/trace-ir/field.h>
@@ -36,6 +36,7 @@
 
 #include "field.h"
 #include "field-class.h"
+#include "lib/func-status.h"
 
 static
 void reset_single_field(struct bt_field *field);
@@ -138,16 +139,18 @@ struct bt_field *create_variant_field(struct bt_field_class *);
 
 static
 struct bt_field *(* const field_create_funcs[])(struct bt_field_class *) = {
-       [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER]  = create_integer_field,
-       [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER]    = create_integer_field,
-       [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION] = create_integer_field,
-       [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION]        = create_integer_field,
-       [BT_FIELD_CLASS_TYPE_REAL]                      = create_real_field,
-       [BT_FIELD_CLASS_TYPE_STRING]            = create_string_field,
-       [BT_FIELD_CLASS_TYPE_STRUCTURE]         = create_structure_field,
-       [BT_FIELD_CLASS_TYPE_STATIC_ARRAY]              = create_static_array_field,
-       [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY]     = create_dynamic_array_field,
-       [BT_FIELD_CLASS_TYPE_VARIANT]           = create_variant_field,
+       [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER]                  = create_integer_field,
+       [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER]                    = create_integer_field,
+       [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION]              = create_integer_field,
+       [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION]                = create_integer_field,
+       [BT_FIELD_CLASS_TYPE_REAL]                              = create_real_field,
+       [BT_FIELD_CLASS_TYPE_STRING]                            = create_string_field,
+       [BT_FIELD_CLASS_TYPE_STRUCTURE]                         = create_structure_field,
+       [BT_FIELD_CLASS_TYPE_STATIC_ARRAY]                      = create_static_array_field,
+       [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY]                     = create_dynamic_array_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR]          = create_variant_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR]    = create_variant_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR]      = create_variant_field,
 };
 
 static
@@ -170,34 +173,36 @@ void destroy_variant_field(struct bt_field *field);
 
 static
 void (* const field_destroy_funcs[])(struct bt_field *) = {
-       [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER]  = destroy_integer_field,
-       [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER]    = destroy_integer_field,
-       [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION] = destroy_integer_field,
-       [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION]        = destroy_integer_field,
-       [BT_FIELD_CLASS_TYPE_REAL]                      = destroy_real_field,
-       [BT_FIELD_CLASS_TYPE_STRING]            = destroy_string_field,
-       [BT_FIELD_CLASS_TYPE_STRUCTURE]         = destroy_structure_field,
-       [BT_FIELD_CLASS_TYPE_STATIC_ARRAY]              = destroy_array_field,
-       [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY]     = destroy_array_field,
-       [BT_FIELD_CLASS_TYPE_VARIANT]           = destroy_variant_field,
+       [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER]                  = destroy_integer_field,
+       [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER]                    = destroy_integer_field,
+       [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION]              = destroy_integer_field,
+       [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION]                = destroy_integer_field,
+       [BT_FIELD_CLASS_TYPE_REAL]                              = destroy_real_field,
+       [BT_FIELD_CLASS_TYPE_STRING]                            = destroy_string_field,
+       [BT_FIELD_CLASS_TYPE_STRUCTURE]                         = destroy_structure_field,
+       [BT_FIELD_CLASS_TYPE_STATIC_ARRAY]                      = destroy_array_field,
+       [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY]                     = destroy_array_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR]          = destroy_variant_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR]    = destroy_variant_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR]      = destroy_variant_field,
 };
 
 struct bt_field_class *bt_field_borrow_class(const struct bt_field *field)
 {
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
        return field->class;
 }
 
 const struct bt_field_class *bt_field_borrow_class_const(
                const struct bt_field *field)
 {
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
        return field->class;
 }
 
 enum bt_field_class_type bt_field_get_class_type(const struct bt_field *field)
 {
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
        return field->class->type;
 }
 
@@ -206,11 +211,10 @@ struct bt_field *bt_field_create(struct bt_field_class *fc)
 {
        struct bt_field *field = NULL;
 
-       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT(bt_field_class_has_known_type(fc));
+       BT_ASSERT(fc);
        field = field_create_funcs[fc->type](fc);
        if (!field) {
-               BT_LIB_LOGE("Cannot create field object from field class: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
                        "%![fc-]+F", fc);
                goto end;
        }
@@ -239,7 +243,8 @@ struct bt_field *create_integer_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc);
        int_field = g_new0(struct bt_field_integer, 1);
        if (!int_field) {
-               BT_LOGE_STR("Failed to allocate one integer field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one integer field.");
                goto end;
        }
 
@@ -258,7 +263,7 @@ struct bt_field *create_real_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc);
        real_field = g_new0(struct bt_field_real, 1);
        if (!real_field) {
-               BT_LOGE_STR("Failed to allocate one real field.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field.");
                goto end;
        }
 
@@ -277,7 +282,8 @@ struct bt_field *create_string_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc);
        string_field = g_new0(struct bt_field_string, 1);
        if (!string_field) {
-               BT_LOGE_STR("Failed to allocate one string field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one string field.");
                goto end;
        }
 
@@ -285,7 +291,7 @@ struct bt_field *create_string_field(struct bt_field_class *fc)
        string_field->buf = g_array_sized_new(FALSE, FALSE,
                sizeof(char), 1);
        if (!string_field->buf) {
-               BT_LOGE_STR("Failed to allocate a GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
                BT_OBJECT_PUT_REF_AND_RESET(string_field);
                goto end;
        }
@@ -308,7 +314,7 @@ int create_fields_from_named_field_classes(
        *fields = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_field_destroy);
        if (!*fields) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                ret = -1;
                goto end;
        }
@@ -317,12 +323,12 @@ int create_fields_from_named_field_classes(
 
        for (i = 0; i < fc->named_fcs->len; i++) {
                struct bt_field *field;
-               struct bt_named_field_class *named_fc =
-                       BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, i);
+               struct bt_named_field_class *named_fc = fc->named_fcs->pdata[i];
 
                field = bt_field_create(named_fc->fc);
                if (!field) {
-                       BT_LIB_LOGE("Failed to create structure member or variant option field: "
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Failed to create structure member or variant option field: "
                                "name=\"%s\", %![fc-]+F",
                                named_fc->name->str, named_fc->fc);
                        ret = -1;
@@ -344,7 +350,8 @@ struct bt_field *create_structure_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc);
        struct_field = g_new0(struct bt_field_structure, 1);
        if (!struct_field) {
-               BT_LOGE_STR("Failed to allocate one structure field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one structure field.");
                goto end;
        }
 
@@ -352,8 +359,8 @@ struct bt_field *create_structure_field(struct bt_field_class *fc)
 
        if (create_fields_from_named_field_classes((void *) fc,
                        &struct_field->fields)) {
-               BT_LIB_LOGE("Cannot create structure member fields: "
-                       "%![fc-]+F", fc);
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create structure member fields: %![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(struct_field);
                goto end;
        }
@@ -372,7 +379,8 @@ struct bt_field *create_variant_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc);
        var_field = g_new0(struct bt_field_variant, 1);
        if (!var_field) {
-               BT_LOGE_STR("Failed to allocate one variant field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one variant field.");
                goto end;
        }
 
@@ -380,7 +388,7 @@ struct bt_field *create_variant_field(struct bt_field_class *fc)
 
        if (create_fields_from_named_field_classes((void *) fc,
                        &var_field->fields)) {
-               BT_LIB_LOGE("Cannot create variant member fields: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
                        "%![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(var_field);
                goto end;
@@ -403,7 +411,7 @@ int init_array_field_fields(struct bt_field_array *array_field)
        array_fc = (void *) array_field->common.class;
        array_field->fields = g_ptr_array_sized_new(array_field->length);
        if (!array_field->fields) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                ret = -1;
                goto end;
        }
@@ -416,7 +424,8 @@ int init_array_field_fields(struct bt_field_array *array_field)
                array_field->fields->pdata[i] = bt_field_create(
                        array_fc->element_fc);
                if (!array_field->fields->pdata[i]) {
-                       BT_LIB_LOGE("Cannot create array field's element field: "
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot create array field's element field: "
                                "index=%" PRIu64 ", %![fc-]+F", i, array_fc);
                        ret = -1;
                        goto end;
@@ -430,13 +439,14 @@ end:
 static
 struct bt_field *create_static_array_field(struct bt_field_class *fc)
 {
-       struct bt_field_class_static_array *array_fc = (void *) fc;
+       struct bt_field_class_array_static *array_fc = (void *) fc;
        struct bt_field_array *array_field;
 
        BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc);
        array_field = g_new0(struct bt_field_array, 1);
        if (!array_field) {
-               BT_LOGE_STR("Failed to allocate one static array field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one static array field.");
                goto end;
        }
 
@@ -444,7 +454,7 @@ struct bt_field *create_static_array_field(struct bt_field_class *fc)
        array_field->length = array_fc->length;
 
        if (init_array_field_fields(array_field)) {
-               BT_LIB_LOGE("Cannot create static array fields: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
                        "%![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(array_field);
                goto end;
@@ -464,14 +474,15 @@ struct bt_field *create_dynamic_array_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc);
        array_field = g_new0(struct bt_field_array, 1);
        if (!array_field) {
-               BT_LOGE_STR("Failed to allocate one dynamic array field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one dynamic array field.");
                goto end;
        }
 
        init_field((void *) array_field, fc, &array_field_methods);
 
        if (init_array_field_fields(array_field)) {
-               BT_LIB_LOGE("Cannot create dynamic array fields: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
                        "%![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(array_field);
                goto end;
@@ -483,24 +494,24 @@ end:
        return (void *) array_field;
 }
 
-int64_t bt_field_signed_integer_get_value(const struct bt_field *field)
+int64_t bt_field_integer_signed_get_value(const struct bt_field *field)
 {
        const struct bt_field_integer *int_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SIGNED_INT(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field, "Field");
        return int_field->value.i;
 }
 
-void bt_field_signed_integer_set_value(struct bt_field *field, int64_t value)
+void bt_field_integer_signed_set_value(struct bt_field *field, int64_t value)
 {
        struct bt_field_integer *int_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SIGNED_INT(field, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE(bt_util_value_is_in_range_signed(
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_signed(
                ((struct bt_field_class_integer *) field->class)->range, value),
                "Value is out of bounds: value=%" PRId64 ", %![field-]+f, "
                "%![fc-]+F", value, field, field->class);
@@ -508,24 +519,24 @@ void bt_field_signed_integer_set_value(struct bt_field *field, int64_t value)
        bt_field_set_single(field, true);
 }
 
-uint64_t bt_field_unsigned_integer_get_value(const struct bt_field *field)
+uint64_t bt_field_integer_unsigned_get_value(const struct bt_field *field)
 {
        const struct bt_field_integer *int_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_UNSIGNED_INT(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field, "Field");
        return int_field->value.u;
 }
 
-void bt_field_unsigned_integer_set_value(struct bt_field *field, uint64_t value)
+void bt_field_integer_unsigned_set_value(struct bt_field *field, uint64_t value)
 {
        struct bt_field_integer *int_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_UNSIGNED_INT(field, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE(bt_util_value_is_in_range_unsigned(
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_unsigned(
                ((struct bt_field_class_integer *) field->class)->range, value),
                "Value is out of bounds: value=%" PRIu64 ", %![field-]+f, "
                "%![fc-]+F", value, field, field->class);
@@ -537,9 +548,9 @@ double bt_field_real_get_value(const struct bt_field *field)
 {
        const struct bt_field_real *real_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
        return real_field->value;
 }
 
@@ -547,10 +558,10 @@ void bt_field_real_set_value(struct bt_field *field, double value)
 {
        struct bt_field_real *real_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE(
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV(
                !((struct bt_field_class_real *) field->class)->is_single_precision ||
                (double) (float) value == value,
                "Invalid value for a single-precision real number: value=%f, "
@@ -559,39 +570,41 @@ void bt_field_real_set_value(struct bt_field *field, double value)
        bt_field_set_single(field, true);
 }
 
-enum bt_field_status bt_field_unsigned_enumeration_get_mapping_labels(
+enum bt_field_enumeration_get_mapping_labels_status
+bt_field_enumeration_unsigned_get_mapping_labels(
                const struct bt_field *field,
                bt_field_class_enumeration_mapping_label_array *label_array,
                uint64_t *count)
 {
        const struct bt_field_integer *int_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_NON_NULL(label_array, "Label array (output)");
-       BT_ASSERT_PRE_NON_NULL(label_array, "Count (output)");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)");
+       BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Count (output)");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, "Field");
        return (int)
-               bt_field_class_unsigned_enumeration_get_mapping_labels_by_value(
+               bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
                        field->class, int_field->value.u, label_array, count);
 }
 
-enum bt_field_status bt_field_signed_enumeration_get_mapping_labels(
+enum bt_field_enumeration_get_mapping_labels_status
+bt_field_enumeration_signed_get_mapping_labels(
                const struct bt_field *field,
                bt_field_class_enumeration_mapping_label_array *label_array,
                uint64_t *count)
 {
        const struct bt_field_integer *int_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_NON_NULL(label_array, "Label array (output)");
-       BT_ASSERT_PRE_NON_NULL(label_array, "Count (output)");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)");
+       BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Count (output)");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, "Field");
        return (int)
-               bt_field_class_signed_enumeration_get_mapping_labels_by_value(
+               bt_field_class_enumeration_signed_get_mapping_labels_for_value(
                        field->class, int_field->value.i, label_array, count);
 }
 
@@ -599,9 +612,9 @@ const char *bt_field_string_get_value(const struct bt_field *field)
 {
        const struct bt_field_string *string_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
                "Field");
        return (const char *) string_field->buf->data;
 }
@@ -610,9 +623,9 @@ uint64_t bt_field_string_get_length(const struct bt_field *field)
 {
        const struct bt_field_string *string_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
                "Field");
        return string_field->length;
 }
@@ -627,40 +640,41 @@ void clear_string_field(struct bt_field *field)
        bt_field_set_single(field, true);
 }
 
-enum bt_field_status bt_field_string_set_value(struct bt_field *field,
-               const char *value)
+enum bt_field_string_set_value_status bt_field_string_set_value(
+               struct bt_field *field, const char *value)
 {
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_NON_NULL(value, "Value");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
                "Field");
        clear_string_field(field);
-       return bt_field_string_append_with_length(field, value,
+       return (int) bt_field_string_append_with_length(field, value,
                (uint64_t) strlen(value));
 }
 
-enum bt_field_status bt_field_string_append(struct bt_field *field, const char *value)
+enum bt_field_string_append_status bt_field_string_append(
+               struct bt_field *field, const char *value)
 {
        return bt_field_string_append_with_length(field,
                value, (uint64_t) strlen(value));
 }
 
-enum bt_field_status bt_field_string_append_with_length(struct bt_field *field,
-               const char *value, uint64_t length)
+enum bt_field_string_append_status bt_field_string_append_with_length(
+               struct bt_field *field, const char *value, uint64_t length)
 {
        struct bt_field_string *string_field = (void *) field;
        char *data;
        uint64_t new_length;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_NON_NULL(value, "Value");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_STRING, "Field");
 
        /* Make sure no null bytes are appended */
-       BT_ASSERT_PRE(memchr(value, '\0', length) == NULL,
+       BT_ASSERT_PRE_DEV(memchr(value, '\0', length) == NULL,
                "String value to append contains a null character: "
                "partial-value=\"%.32s\", length=%" PRIu64, value, length);
 
@@ -675,38 +689,37 @@ enum bt_field_status bt_field_string_append_with_length(struct bt_field *field,
        ((char *) string_field->buf->data)[new_length] = '\0';
        string_field->length = new_length;
        bt_field_set_single(field, true);
-       return BT_FIELD_STATUS_OK;
+       return BT_FUNC_STATUS_OK;
 }
 
-enum bt_field_status bt_field_string_clear(struct bt_field *field)
+void bt_field_string_clear(struct bt_field *field)
 {
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_STRING, "Field");
        clear_string_field(field);
-       return BT_FIELD_STATUS_OK;
 }
 
 uint64_t bt_field_array_get_length(const struct bt_field *field)
 {
        const struct bt_field_array *array_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_ARRAY(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field, "Field");
        return array_field->length;
 }
 
-enum bt_field_status bt_field_dynamic_array_set_length(struct bt_field *field,
-               uint64_t length)
+enum bt_field_array_dynamic_set_length_status bt_field_array_dynamic_set_length(
+               struct bt_field *field, uint64_t length)
 {
-       int ret = BT_FIELD_STATUS_OK;
+       int ret = BT_FUNC_STATUS_OK;
        struct bt_field_array *array_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
 
        if (G_UNLIKELY(length > array_field->fields->len)) {
                /* Make more room */
@@ -722,11 +735,12 @@ enum bt_field_status bt_field_dynamic_array_set_length(struct bt_field *field,
                                array_fc->element_fc);
 
                        if (!elem_field) {
-                               BT_LIB_LOGE("Cannot create element field for "
+                               BT_LIB_LOGE_APPEND_CAUSE(
+                                       "Cannot create element field for "
                                        "dynamic array field: "
                                        "index=%" PRIu64 ", "
                                        "%![array-field-]+f", i, field);
-                               ret = BT_FIELD_STATUS_NOMEM;
+                               ret = BT_FUNC_STATUS_MEMORY_ERROR;
                                goto end;
                        }
 
@@ -747,9 +761,9 @@ struct bt_field *borrow_array_field_element_field_by_index(
 {
        struct bt_field_array *array_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_ARRAY(field, "Field");
-       BT_ASSERT_PRE_VALID_INDEX(index, array_field->length);
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field, "Field");
+       BT_ASSERT_PRE_DEV_VALID_INDEX(index, array_field->length);
        return array_field->fields->pdata[index];
 }
 
@@ -772,10 +786,10 @@ struct bt_field *borrow_structure_field_member_field_by_index(
 {
        struct bt_field_structure *struct_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_STRUCTURE, "Field");
-       BT_ASSERT_PRE_VALID_INDEX(index, struct_field->fields->len);
+       BT_ASSERT_PRE_DEV_VALID_INDEX(index, struct_field->fields->len);
        return struct_field->fields->pdata[index];
 }
 
@@ -804,9 +818,9 @@ struct bt_field *borrow_structure_field_member_field_by_name(
        gpointer orig_key;
        gpointer index;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_NON_NULL(name, "Field name");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(name, "Field name");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_STRUCTURE, "Field");
        struct_fc = (void *) field->class;
 
@@ -841,10 +855,9 @@ struct bt_field *borrow_variant_field_selected_option_field(
 {
        struct bt_field_variant *var_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
-               BT_FIELD_CLASS_TYPE_VARIANT, "Field");
-       BT_ASSERT_PRE(var_field->selected_field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
+       BT_ASSERT_PRE_DEV(var_field->selected_field,
                "Variant field has no selected field: %!+f", field);
        return var_field->selected_field;
 }
@@ -861,19 +874,62 @@ const struct bt_field *bt_field_variant_borrow_selected_option_field_const(
        return borrow_variant_field_selected_option_field((void *) field);
 }
 
-enum bt_field_status bt_field_variant_select_option_field(
+static
+const struct bt_field_class_variant_option *
+borrow_variant_field_selected_class_option(const struct bt_field *field)
+{
+       const struct bt_field_class_named_field_class_container *container_fc;
+       const struct bt_field_variant *var_field = (const void *) field;
+
+       BT_ASSERT(field);
+       BT_ASSERT_PRE_DEV(var_field->selected_field,
+               "Variant field has no selected field: %!+f", field);
+       container_fc = (const void *) field->class;
+       return container_fc->named_fcs->pdata[var_field->selected_index];
+}
+
+const struct bt_field_class_variant_option *
+bt_field_variant_borrow_selected_class_option_const(
+               const struct bt_field *field)
+{
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
+       return borrow_variant_field_selected_class_option(field);
+}
+
+const struct bt_field_class_variant_with_selector_unsigned_option *
+bt_field_variant_with_unsigned_selector_borrow_selected_class_option_const(
+               const struct bt_field *field)
+{
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR, "Field");
+       return (const void *) borrow_variant_field_selected_class_option(field);
+}
+
+const struct bt_field_class_variant_with_selector_signed_option *
+bt_field_variant_with_signed_selector_borrow_selected_class_option_const(
+               const struct bt_field *field)
+{
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR, "Field");
+       return (const void *) borrow_variant_field_selected_class_option(field);
+}
+
+enum bt_field_variant_select_option_field_by_index_status
+bt_field_variant_select_option_field_by_index(
                struct bt_field *field, uint64_t index)
 {
        struct bt_field_variant *var_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
-               BT_FIELD_CLASS_TYPE_VARIANT, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE_VALID_INDEX(index, var_field->fields->len);
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_VALID_INDEX(index, var_field->fields->len);
        var_field->selected_field = var_field->fields->pdata[index];
        var_field->selected_index = index;
-       return BT_FIELD_STATUS_OK;
+       return BT_FUNC_STATUS_OK;
 }
 
 uint64_t bt_field_variant_get_selected_option_field_index(
@@ -881,10 +937,9 @@ uint64_t bt_field_variant_get_selected_option_field_index(
 {
        const struct bt_field_variant *var_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
-               BT_FIELD_CLASS_TYPE_VARIANT, "Field");
-       BT_ASSERT_PRE(var_field->selected_field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
+       BT_ASSERT_PRE_DEV(var_field->selected_field,
                "Variant field has no selected field: %!+f", field);
        return var_field->selected_index;
 }
@@ -987,7 +1042,6 @@ BT_HIDDEN
 void bt_field_destroy(struct bt_field *field)
 {
        BT_ASSERT(field);
-       BT_ASSERT(bt_field_class_has_known_type(field->class));
        field_destroy_funcs[field->class->type](field);
 }
 
This page took 0.034609 seconds and 4 git commands to generate.