Fix: lib: pass down API function name to some helpers
[babeltrace.git] / src / lib / trace-ir / field.c
index 6e513d4158d7756b413fc7f1582e2e1608816c88..4d6db1337eda5679ba05fd9f5a025745c5e89a26 100644 (file)
@@ -22,9 +22,9 @@
 #include "field-class.h"
 #include "lib/func-status.h"
 
-#define BT_ASSERT_PRE_DEV_FIELD_HOT(_field, _name)                     \
-       BT_ASSERT_PRE_DEV_HOT((const struct bt_field *) (_field), (_name), \
-               ": %!+f", (_field))
+#define BT_ASSERT_PRE_DEV_FIELD_HOT(_field)                            \
+       BT_ASSERT_PRE_DEV_HOT("field",                                  \
+               (const struct bt_field *) (_field), "Field", ": %!+f", (_field))
 
 static
 void reset_single_field(struct bt_field *field);
@@ -193,20 +193,20 @@ void destroy_variant_field(struct bt_field *field);
 
 struct bt_field_class *bt_field_borrow_class(struct bt_field *field)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
        return field->class;
 }
 
 const struct bt_field_class *bt_field_borrow_class_const(
                const struct bt_field *field)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
        return field->class;
 }
 
 enum bt_field_class_type bt_field_get_class_type(const struct bt_field *field)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
        return field->class->type;
 }
 
@@ -624,10 +624,10 @@ bt_bool bt_field_bool_get_value(const struct bt_field *field)
 {
        const struct bt_field_bool *bool_field = (const void *) 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_BOOL,
-               "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "boolean-field", BT_FIELD_CLASS_TYPE_BOOL, "Field");
        return (bt_bool) bool_field->value;
 }
 
@@ -635,10 +635,10 @@ void bt_field_bool_set_value(struct bt_field *field, bt_bool value)
 {
        struct bt_field_bool *bool_field = (void *) field;
 
-       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_BOOL,
-               "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "boolean-field", BT_FIELD_CLASS_TYPE_BOOL, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field);
        bool_field->value = (bool) value;
        bt_field_set_single(field, true);
 }
@@ -647,10 +647,10 @@ uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field *field)
 {
        const struct bt_field_bit_array *ba_field = (const void *) 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_BIT_ARRAY, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "bit-array-field", BT_FIELD_CLASS_TYPE_BIT_ARRAY, "Field");
        return ba_field->value_as_int;
 }
 
@@ -660,10 +660,10 @@ void bt_field_bit_array_set_value_as_integer(struct bt_field *field,
        struct bt_field_bit_array *ba_field = (void *) field;
        struct bt_field_class_bit_array *ba_fc;
 
-       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
-               BT_FIELD_CLASS_TYPE_BIT_ARRAY, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "bit-array-field", BT_FIELD_CLASS_TYPE_BIT_ARRAY, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field);
        ba_fc = (void *) field->class;
        ba_field->value_as_int = value;
 
@@ -679,9 +679,9 @@ 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_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT("field", field, "Field");
        return int_field->value.i;
 }
 
@@ -689,11 +689,13 @@ 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_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),
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT("field", field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field);
+       BT_ASSERT_PRE_DEV("valid-value-for-field-class-field-value-range",
+               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);
        int_field->value.i = value;
@@ -704,9 +706,9 @@ 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_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT("field", field, "Field");
        return int_field->value.u;
 }
 
@@ -714,11 +716,13 @@ 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_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),
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT("field", field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field);
+       BT_ASSERT_PRE_DEV("valid-value-for-field-class-field-value-range",
+               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);
        int_field->value.u = value;
@@ -729,9 +733,10 @@ float bt_field_real_single_precision_get_value(const struct bt_field *field)
 {
        const struct bt_field_real *real_field = (const void *) 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_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "single-precision-real-field",
                BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, "Field");
        return (float) real_field->value;
 }
@@ -740,11 +745,11 @@ double bt_field_real_double_precision_get_value(const struct bt_field *field)
 {
        const struct bt_field_real *real_field = (const void *) 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_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "double-precision-real-field",
                BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, "Field");
-
        return real_field->value;
 }
 
@@ -753,10 +758,11 @@ void bt_field_real_single_precision_set_value(struct bt_field *field,
 {
        struct bt_field_real *real_field = (void *) field;
 
-       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "single-precision-real-field",
                BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field);
 
        real_field->value = (double) value;
        bt_field_set_single(field, true);
@@ -767,10 +773,11 @@ void bt_field_real_double_precision_set_value(struct bt_field *field,
 {
        struct bt_field_real *real_field = (void *) field;
 
-       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "double-precision-real-field",
                BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field);
 
        real_field->value = value;
        bt_field_set_single(field, true);
@@ -785,11 +792,13 @@ bt_field_enumeration_unsigned_get_mapping_labels(
        const struct bt_field_integer *int_field = (const void *) field;
 
        BT_ASSERT_PRE_DEV_NO_ERROR();
-       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_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array,
+               "Label array (output)");
+       BT_ASSERT_PRE_DEV_NON_NULL("count-output", count, "Count (output)");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "unsigned-enumeration-field",
                BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, "Field");
        return (int)
                bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
@@ -805,11 +814,13 @@ bt_field_enumeration_signed_get_mapping_labels(
        const struct bt_field_integer *int_field = (const void *) field;
 
        BT_ASSERT_PRE_DEV_NO_ERROR();
-       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_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array,
+               "Label array (output)");
+       BT_ASSERT_PRE_DEV_NON_NULL("count-output", count, "Count (output)");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "signed-enumeration-field",
                BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, "Field");
        return (int)
                bt_field_class_enumeration_signed_get_mapping_labels_for_value(
@@ -820,10 +831,10 @@ 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_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");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field, "string-field",
+               BT_FIELD_CLASS_TYPE_STRING, "Field");
        return (const char *) string_field->buf->data;
 }
 
@@ -831,10 +842,10 @@ 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_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");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field, "string-field",
+               BT_FIELD_CLASS_TYPE_STRING, "Field");
        return string_field->length;
 }
 
@@ -845,6 +856,7 @@ void clear_string_field(struct bt_field *field)
 
        BT_ASSERT_DBG(field);
        string_field->length = 0;
+       g_array_index(string_field->buf, char, 0) = '\0';
        bt_field_set_single(field, true);
 }
 
@@ -852,44 +864,42 @@ enum bt_field_string_set_value_status bt_field_string_set_value(
                struct bt_field *field, const char *value)
 {
        BT_ASSERT_PRE_DEV_NO_ERROR();
-       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");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_NON_NULL("value", value, "Value");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field, "string-field",
+               BT_FIELD_CLASS_TYPE_STRING, "Field");
        clear_string_field(field);
        return (int) bt_field_string_append_with_length(field, value,
                (uint64_t) strlen(value));
 }
 
-enum bt_field_string_append_status bt_field_string_append(
-               struct bt_field *field, const char *value)
-{
-       BT_ASSERT_PRE_DEV_NO_ERROR();
-
-       return bt_field_string_append_with_length(field,
-               value, (uint64_t) strlen(value));
-}
-
-enum bt_field_string_append_status bt_field_string_append_with_length(
+#define BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(_field, _value, _length) \
+       do {                                                            \
+               BT_ASSERT_PRE_DEV_NO_ERROR();                           \
+               BT_ASSERT_PRE_DEV_FIELD_NON_NULL(_field);               \
+               BT_ASSERT_PRE_DEV_NON_NULL("value", (_value), "Value"); \
+               BT_ASSERT_PRE_DEV_FIELD_HOT(_field);                    \
+               BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field",         \
+                       (_field), "string-field",                       \
+                       BT_FIELD_CLASS_TYPE_STRING, "Field");           \
+               BT_ASSERT_PRE_DEV("value-has-no-null-byte",             \
+                       !memchr((_value), '\0', (_length)),             \
+                       "String value to append contains a null character: " \
+                       "partial-value=\"%.32s\", length=%" PRIu64,     \
+                       (_value), (_length));                                   \
+       } while (0)
+
+static
+enum bt_field_string_append_status append_to_string_field_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_DEV_NO_ERROR();
-       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_DEV(!memchr(value, '\0', length),
-               "String value to append contains a null character: "
-               "partial-value=\"%.32s\", length=%" PRIu64, value, length);
-
+       BT_ASSERT_DBG(field);
+       BT_ASSERT_DBG(value);
        new_length = length + string_field->length;
 
        if (G_UNLIKELY(new_length + 1 > string_field->buf->len)) {
@@ -904,11 +914,29 @@ enum bt_field_string_append_status bt_field_string_append_with_length(
        return BT_FUNC_STATUS_OK;
 }
 
+enum bt_field_string_append_status bt_field_string_append_with_length(
+               struct bt_field *field, const char *value, uint64_t length)
+{
+       BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(field, value,
+               length);
+       return append_to_string_field_with_length(field, value, length);
+}
+
+enum bt_field_string_append_status bt_field_string_append(
+               struct bt_field *field, const char *value)
+{
+       uint64_t length = (uint64_t) strlen(value);
+
+       BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(field, value,
+               length);
+       return append_to_string_field_with_length(field, value, length);
+}
+
 void bt_field_string_clear(struct bt_field *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_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field, "string-field",
                BT_FIELD_CLASS_TYPE_STRING, "Field");
        clear_string_field(field);
 }
@@ -917,8 +945,8 @@ 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_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY("field", field, "Field");
        return array_field->length;
 }
 
@@ -929,9 +957,9 @@ enum bt_field_array_dynamic_set_length_status bt_field_array_dynamic_set_length(
        struct bt_field_array *array_field = (void *) field;
 
        BT_ASSERT_PRE_DEV_NO_ERROR();
-       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY("field", field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field);
 
        if (G_UNLIKELY(length > array_field->fields->len)) {
                /* Make more room */
@@ -969,39 +997,45 @@ end:
 
 static inline
 struct bt_field *borrow_array_field_element_field_by_index(
-               struct bt_field *field, uint64_t index)
+               struct bt_field *field, uint64_t index, const char *api_func)
 {
        struct bt_field_array *array_field = (void *) field;
 
-       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);
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func, field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY_FROM_FUNC(api_func, "field", field,
+               "Field");
+       BT_ASSERT_PRE_DEV_VALID_INDEX_FROM_FUNC(api_func, index,
+               array_field->length);
        return array_field->fields->pdata[index];
 }
 
 struct bt_field *bt_field_array_borrow_element_field_by_index(
                struct bt_field *field, uint64_t index)
 {
-       return borrow_array_field_element_field_by_index(field, index);
+       return borrow_array_field_element_field_by_index(field, index,
+               __func__);
 }
 
 const struct bt_field *
 bt_field_array_borrow_element_field_by_index_const(
                const struct bt_field *field, uint64_t index)
 {
-       return borrow_array_field_element_field_by_index((void *) field, index);
+       return borrow_array_field_element_field_by_index((void *) field, index,
+               __func__);
 }
 
 static inline
 struct bt_field *borrow_structure_field_member_field_by_index(
-               struct bt_field *field, uint64_t index)
+               struct bt_field *field, uint64_t index, const char *api_func)
 {
        struct bt_field_structure *struct_field = (void *) 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_DEV_VALID_INDEX(index, struct_field->fields->len);
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func, field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE_FROM_FUNC(api_func, "field",
+               field, "structure-field", BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field");
+       BT_ASSERT_PRE_DEV_VALID_INDEX_FROM_FUNC(api_func, index,
+               struct_field->fields->len);
        return struct_field->fields->pdata[index];
 }
 
@@ -1009,7 +1043,7 @@ struct bt_field *bt_field_structure_borrow_member_field_by_index(
                struct bt_field *field, uint64_t index)
 {
        return borrow_structure_field_member_field_by_index(field,
-               index);
+               index, __func__);
 }
 
 const struct bt_field *
@@ -1017,12 +1051,12 @@ bt_field_structure_borrow_member_field_by_index_const(
                const struct bt_field *field, uint64_t index)
 {
        return borrow_structure_field_member_field_by_index(
-               (void *) field, index);
+               (void *) field, index, __func__);
 }
 
 static inline
 struct bt_field *borrow_structure_field_member_field_by_name(
-               struct bt_field *field, const char *name)
+               struct bt_field *field, const char *name, const char *api_func)
 {
        struct bt_field *ret_field = NULL;
        struct bt_field_class_structure *struct_fc;
@@ -1030,10 +1064,12 @@ struct bt_field *borrow_structure_field_member_field_by_name(
        gpointer orig_key;
        gpointer index;
 
-       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");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func, field);
+       BT_ASSERT_PRE_DEV_NON_NULL_FROM_FUNC(api_func, "member-name", name,
+               "Member name");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE_FROM_FUNC(api_func, "field",
+               field, "structure-field", BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field");
        struct_fc = (void *) field->class;
 
        if (!g_hash_table_lookup_extended(struct_fc->common.name_to_index, name,
@@ -1051,23 +1087,24 @@ end:
 struct bt_field *bt_field_structure_borrow_member_field_by_name(
                struct bt_field *field, const char *name)
 {
-       return borrow_structure_field_member_field_by_name(field, name);
+       return borrow_structure_field_member_field_by_name(field, name,
+               __func__);
 }
 
 const struct bt_field *bt_field_structure_borrow_member_field_by_name_const(
                const struct bt_field *field, const char *name)
 {
        return borrow_structure_field_member_field_by_name(
-               (void *) field, name);
+               (void *) field, name, __func__);
 }
 
 void bt_field_option_set_has_field(struct bt_field *field, bt_bool has_field)
 {
        struct bt_field_option *opt_field = (void *) field;
 
-       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_OPTION("field", field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field);
 
        if (has_field) {
                opt_field->selected_field = opt_field->content_field;
@@ -1080,8 +1117,8 @@ struct bt_field *bt_field_option_borrow_field(struct bt_field *field)
 {
        struct bt_field_option *opt_field = (void *) field;
 
-       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_OPTION("field", field, "Field");
        return opt_field->selected_field;
 }
 
@@ -1091,31 +1128,51 @@ const struct bt_field *bt_field_option_borrow_field_const(
        return (const void *) bt_field_option_borrow_field((void *) field);
 }
 
+#define BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(_field)   \
+       do {                                                            \
+               struct bt_field_variant *_var_field = (void *) field;   \
+               BT_ASSERT_PRE_DEV_FIELD_NON_NULL(_field);               \
+               BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", (_field),   \
+                       "Field");                                       \
+               BT_ASSERT_PRE_DEV("has-selected-field",                 \
+                       _var_field->selected_field,                     \
+                       "Variant field has no selected field: %!+f",    \
+                       field);                                         \
+       } while (0)
+
 static inline
 struct bt_field *borrow_variant_field_selected_option_field(
                struct bt_field *field)
 {
        struct bt_field_variant *var_field = (void *) 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);
+       BT_ASSERT_DBG(field);
        return var_field->selected_field;
 }
 
 struct bt_field *bt_field_variant_borrow_selected_option_field(
                struct bt_field *field)
 {
+       BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(field);
        return borrow_variant_field_selected_option_field(field);
 }
 
 const struct bt_field *bt_field_variant_borrow_selected_option_field_const(
                const struct bt_field *field)
 {
+       BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(field);
        return borrow_variant_field_selected_option_field((void *) field);
 }
 
+#define BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(_field)   \
+       do {                                                            \
+               struct bt_field_variant *_var_field = (void *) field;   \
+               BT_ASSERT_PRE_DEV("has-selected-field",                 \
+                       _var_field->selected_field,                     \
+                       "Variant field has no selected field: %!+f",    \
+                       (_field));                                      \
+       } while (0)
+
 static
 const struct bt_field_class_variant_option *
 borrow_variant_field_selected_class_option(const struct bt_field *field)
@@ -1124,8 +1181,6 @@ borrow_variant_field_selected_class_option(const struct bt_field *field)
        const struct bt_field_variant *var_field = (const void *) field;
 
        BT_ASSERT_DBG(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];
 }
@@ -1134,8 +1189,9 @@ const struct bt_field_class_variant_option *
 bt_field_variant_borrow_selected_option_class_const(
                const struct bt_field *field)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field, "Field");
+       BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field);
        return borrow_variant_field_selected_class_option(field);
 }
 
@@ -1143,9 +1199,12 @@ const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
 bt_field_variant_with_selector_field_integer_unsigned_borrow_selected_option_class_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_INTEGER_SELECTOR_FIELD, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "variant-field-with-unsigned-selector-field",
+               BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD,
+               "Field");
+       BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field);
        return (const void *) borrow_variant_field_selected_class_option(field);
 }
 
@@ -1153,9 +1212,12 @@ const struct bt_field_class_variant_with_selector_field_integer_signed_option *
 bt_field_variant_with_selector_field_integer_signed_borrow_selected_option_class_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_INTEGER_SELECTOR_FIELD, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field,
+               "variant-field-with-signed-selector-field",
+               BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD,
+               "Field");
+       BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field);
        return (const void *) borrow_variant_field_selected_class_option(field);
 }
 
@@ -1166,9 +1228,9 @@ bt_field_variant_select_option_by_index(
        struct bt_field_variant *var_field = (void *) field;
 
        BT_ASSERT_PRE_DEV_NO_ERROR();
-       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_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(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;
@@ -1180,9 +1242,9 @@ uint64_t bt_field_variant_get_selected_option_index(
 {
        const struct bt_field_variant *var_field = (const void *) 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,
+       BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field);
+       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field, "Field");
+       BT_ASSERT_PRE_DEV("has-selected-field", var_field->selected_field,
                "Variant field has no selected field: %!+f", field);
        return var_field->selected_index;
 }
This page took 0.033506 seconds and 4 git commands to generate.