Replace assert() -> BT_ASSERT() and some preconditions with BT_ASSERT_PRE()
[babeltrace.git] / lib / ctf-ir / fields.c
index 0fe5630e232d400b8efed96fd5c54a38d0650a91..5faaaec82cfce9470a49162aa4aa32dbcb599139 100644 (file)
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/compat/fcntl-internal.h>
 #include <babeltrace/align-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
 #include <inttypes.h>
 
 static
 struct bt_field *bt_field_integer_create(struct bt_field_type *);
 static
-struct bt_field *bt_field_enumeration_create(
-               struct bt_field_type *);
+struct bt_field *bt_field_enumeration_create(struct bt_field_type *);
 static
-struct bt_field *bt_field_floating_point_create(
-               struct bt_field_type *);
+struct bt_field *bt_field_floating_point_create(struct bt_field_type *);
 static
-struct bt_field *bt_field_structure_create(
-               struct bt_field_type *);
+struct bt_field *bt_field_structure_create(struct bt_field_type *);
 static
-struct bt_field *bt_field_variant_create(
-               struct bt_field_type *);
+struct bt_field *bt_field_variant_create(struct bt_field_type *);
 static
-struct bt_field *bt_field_array_create(
-               struct bt_field_type *);
+struct bt_field *bt_field_array_create(struct bt_field_type *);
 static
-struct bt_field *bt_field_sequence_create(
-               struct bt_field_type *);
+struct bt_field *bt_field_sequence_create(struct bt_field_type *);
 static
 struct bt_field *bt_field_string_create(struct bt_field_type *);
 
@@ -67,68 +63,68 @@ void bt_field_destroy(struct bt_object *);
 static
 void bt_field_integer_destroy(struct bt_field *);
 static
-void bt_field_enumeration_destroy(struct bt_field *);
+void bt_field_enumeration_destroy_recursive(struct bt_field *);
 static
 void bt_field_floating_point_destroy(struct bt_field *);
 static
-void bt_field_structure_destroy(struct bt_field *);
+void bt_field_structure_destroy_recursive(struct bt_field *);
 static
-void bt_field_variant_destroy(struct bt_field *);
+void bt_field_variant_destroy_recursive(struct bt_field *);
 static
-void bt_field_array_destroy(struct bt_field *);
+void bt_field_array_destroy_recursive(struct bt_field *);
 static
-void bt_field_sequence_destroy(struct bt_field *);
+void bt_field_sequence_destroy_recursive(struct bt_field *);
 static
 void bt_field_string_destroy(struct bt_field *);
 
 static
 int bt_field_generic_validate(struct bt_field *);
 static
-int bt_field_structure_validate(struct bt_field *);
+int bt_field_structure_validate_recursive(struct bt_field *);
 static
-int bt_field_variant_validate(struct bt_field *);
+int bt_field_variant_validate_recursive(struct bt_field *);
 static
-int bt_field_enumeration_validate(struct bt_field *);
+int bt_field_enumeration_validate_recursive(struct bt_field *);
 static
-int bt_field_array_validate(struct bt_field *);
+int bt_field_array_validate_recursive(struct bt_field *);
 static
-int bt_field_sequence_validate(struct bt_field *);
+int bt_field_sequence_validate_recursive(struct bt_field *);
 
 static
-int bt_field_generic_reset(struct bt_field *);
+void bt_field_generic_reset(struct bt_field *);
 static
-int bt_field_structure_reset(struct bt_field *);
+void bt_field_structure_reset_recursive(struct bt_field *);
 static
-int bt_field_variant_reset(struct bt_field *);
+void bt_field_variant_reset_recursive(struct bt_field *);
 static
-int bt_field_enumeration_reset(struct bt_field *);
+void bt_field_enumeration_reset_recursive(struct bt_field *);
 static
-int bt_field_array_reset(struct bt_field *);
+void bt_field_array_reset_recursive(struct bt_field *);
 static
-int bt_field_sequence_reset(struct bt_field *);
+void bt_field_sequence_reset_recursive(struct bt_field *);
 static
-int bt_field_string_reset(struct bt_field *);
+void bt_field_string_reset_recursive(struct bt_field *);
 
 static
 int bt_field_integer_serialize(struct bt_field *,
                struct bt_stream_pos *, enum bt_byte_order);
 static
-int bt_field_enumeration_serialize(struct bt_field *,
+int bt_field_enumeration_serialize_recursive(struct bt_field *,
                struct bt_stream_pos *, enum bt_byte_order);
 static
 int bt_field_floating_point_serialize(struct bt_field *,
                struct bt_stream_pos *, enum bt_byte_order);
 static
-int bt_field_structure_serialize(struct bt_field *,
+int bt_field_structure_serialize_recursive(struct bt_field *,
                struct bt_stream_pos *, enum bt_byte_order);
 static
-int bt_field_variant_serialize(struct bt_field *,
+int bt_field_variant_serialize_recursive(struct bt_field *,
                struct bt_stream_pos *, enum bt_byte_order);
 static
-int bt_field_array_serialize(struct bt_field *,
+int bt_field_array_serialize_recursive(struct bt_field *,
                struct bt_stream_pos *, enum bt_byte_order);
 static
-int bt_field_sequence_serialize(struct bt_field *,
+int bt_field_sequence_serialize_recursive(struct bt_field *,
                struct bt_stream_pos *, enum bt_byte_order);
 static
 int bt_field_string_serialize(struct bt_field *,
@@ -137,57 +133,54 @@ int bt_field_string_serialize(struct bt_field *,
 static
 int bt_field_integer_copy(struct bt_field *, struct bt_field *);
 static
-int bt_field_enumeration_copy(struct bt_field *, struct bt_field *);
+int bt_field_enumeration_copy_recursive(struct bt_field *, struct bt_field *);
 static
-int bt_field_floating_point_copy(struct bt_field *,
-               struct bt_field *);
+int bt_field_floating_point_copy(struct bt_field *, struct bt_field *);
 static
-int bt_field_structure_copy(struct bt_field *, struct bt_field *);
+int bt_field_structure_copy_recursive(struct bt_field *, struct bt_field *);
 static
-int bt_field_variant_copy(struct bt_field *, struct bt_field *);
+int bt_field_variant_copy_recursive(struct bt_field *, struct bt_field *);
 static
-int bt_field_array_copy(struct bt_field *, struct bt_field *);
+int bt_field_array_copy_recursive(struct bt_field *, struct bt_field *);
 static
-int bt_field_sequence_copy(struct bt_field *, struct bt_field *);
+int bt_field_sequence_copy_recursive(struct bt_field *, struct bt_field *);
 static
-int bt_field_string_copy(struct bt_field *, struct bt_field *);
+int bt_field_string_copy_recursive(struct bt_field *, struct bt_field *);
 
 static
 void generic_field_freeze(struct bt_field *);
 static
-void bt_field_enumeration_freeze(struct bt_field *);
+void bt_field_enumeration_freeze_recursive(struct bt_field *);
 static
-void bt_field_structure_freeze(struct bt_field *);
+void bt_field_structure_freeze_recursive(struct bt_field *);
 static
-void bt_field_variant_freeze(struct bt_field *);
+void bt_field_variant_freeze_recursive(struct bt_field *);
 static
-void bt_field_array_freeze(struct bt_field *);
+void bt_field_array_freeze_recursive(struct bt_field *);
 static
-void bt_field_sequence_freeze(struct bt_field *);
+void bt_field_sequence_freeze_recursive(struct bt_field *);
 
 static
 bt_bool bt_field_generic_is_set(struct bt_field *);
 static
-bt_bool bt_field_structure_is_set(struct bt_field *);
+bt_bool bt_field_structure_is_set_recursive(struct bt_field *);
 static
-bt_bool bt_field_variant_is_set(struct bt_field *);
+bt_bool bt_field_variant_is_set_recursive(struct bt_field *);
 static
-bt_bool bt_field_enumeration_is_set(struct bt_field *);
+bt_bool bt_field_enumeration_is_set_recursive(struct bt_field *);
 static
-bt_bool bt_field_array_is_set(struct bt_field *);
+bt_bool bt_field_array_is_set_recursive(struct bt_field *);
 static
-bt_bool bt_field_sequence_is_set(struct bt_field *);
+bt_bool bt_field_sequence_is_set_recursive(struct bt_field *);
 
 static
 int increase_packet_size(struct bt_stream_pos *pos);
 
 static
-struct bt_field *(* const field_create_funcs[])(
-               struct bt_field_type *) = {
+struct bt_field *(* const field_create_funcs[])(struct bt_field_type *) = {
        [BT_FIELD_TYPE_ID_INTEGER] = bt_field_integer_create,
        [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_create,
-       [BT_FIELD_TYPE_ID_FLOAT] =
-               bt_field_floating_point_create,
+       [BT_FIELD_TYPE_ID_FLOAT] = bt_field_floating_point_create,
        [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_create,
        [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_create,
        [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_create,
@@ -198,51 +191,49 @@ struct bt_field *(* const field_create_funcs[])(
 static
 void (* const field_destroy_funcs[])(struct bt_field *) = {
        [BT_FIELD_TYPE_ID_INTEGER] = bt_field_integer_destroy,
-       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_destroy,
-       [BT_FIELD_TYPE_ID_FLOAT] =
-               bt_field_floating_point_destroy,
-       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_destroy,
-       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_destroy,
-       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_destroy,
-       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_destroy,
+       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_destroy_recursive,
+       [BT_FIELD_TYPE_ID_FLOAT] = bt_field_floating_point_destroy,
+       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_destroy_recursive,
+       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_destroy_recursive,
+       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_destroy_recursive,
+       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_destroy_recursive,
        [BT_FIELD_TYPE_ID_STRING] = bt_field_string_destroy,
 };
 
 static
 int (* const field_validate_funcs[])(struct bt_field *) = {
        [BT_FIELD_TYPE_ID_INTEGER] = bt_field_generic_validate,
-       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_validate,
+       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_validate_recursive,
        [BT_FIELD_TYPE_ID_FLOAT] = bt_field_generic_validate,
-       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_validate,
-       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_validate,
-       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_validate,
-       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_validate,
+       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_validate_recursive,
+       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_validate_recursive,
+       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_validate_recursive,
+       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_validate_recursive,
        [BT_FIELD_TYPE_ID_STRING] = bt_field_generic_validate,
 };
 
 static
-int (* const field_reset_funcs[])(struct bt_field *) = {
+void (* const field_reset_funcs[])(struct bt_field *) = {
        [BT_FIELD_TYPE_ID_INTEGER] = bt_field_generic_reset,
-       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_reset,
+       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_reset_recursive,
        [BT_FIELD_TYPE_ID_FLOAT] = bt_field_generic_reset,
-       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_reset,
-       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_reset,
-       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_reset,
-       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_reset,
-       [BT_FIELD_TYPE_ID_STRING] = bt_field_string_reset,
+       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_reset_recursive,
+       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_reset_recursive,
+       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_reset_recursive,
+       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_reset_recursive,
+       [BT_FIELD_TYPE_ID_STRING] = bt_field_string_reset_recursive,
 };
 
 static
 int (* const field_serialize_funcs[])(struct bt_field *,
                struct bt_stream_pos *, enum bt_byte_order) = {
        [BT_FIELD_TYPE_ID_INTEGER] = bt_field_integer_serialize,
-       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_serialize,
-       [BT_FIELD_TYPE_ID_FLOAT] =
-               bt_field_floating_point_serialize,
-       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_serialize,
-       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_serialize,
-       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_serialize,
-       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_serialize,
+       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_serialize_recursive,
+       [BT_FIELD_TYPE_ID_FLOAT] = bt_field_floating_point_serialize,
+       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_serialize_recursive,
+       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_serialize_recursive,
+       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_serialize_recursive,
+       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_serialize_recursive,
        [BT_FIELD_TYPE_ID_STRING] = bt_field_string_serialize,
 };
 
@@ -250,13 +241,13 @@ static
 int (* const field_copy_funcs[])(struct bt_field *,
                struct bt_field *) = {
        [BT_FIELD_TYPE_ID_INTEGER] = bt_field_integer_copy,
-       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_copy,
+       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_copy_recursive,
        [BT_FIELD_TYPE_ID_FLOAT] = bt_field_floating_point_copy,
-       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_copy,
-       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_copy,
-       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_copy,
-       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_copy,
-       [BT_FIELD_TYPE_ID_STRING] = bt_field_string_copy,
+       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_copy_recursive,
+       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_copy_recursive,
+       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_copy_recursive,
+       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_copy_recursive,
+       [BT_FIELD_TYPE_ID_STRING] = bt_field_string_copy_recursive,
 };
 
 static
@@ -264,53 +255,56 @@ void (* const field_freeze_funcs[])(struct bt_field *) = {
        [BT_FIELD_TYPE_ID_INTEGER] = generic_field_freeze,
        [BT_FIELD_TYPE_ID_FLOAT] = generic_field_freeze,
        [BT_FIELD_TYPE_ID_STRING] = generic_field_freeze,
-       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_freeze,
-       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_freeze,
-       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_freeze,
-       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_freeze,
-       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_freeze,
+       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_freeze_recursive,
+       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_freeze_recursive,
+       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_freeze_recursive,
+       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_freeze_recursive,
+       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_freeze_recursive,
 };
 
 static
 bt_bool (* const field_is_set_funcs[])(struct bt_field *) = {
        [BT_FIELD_TYPE_ID_INTEGER] = bt_field_generic_is_set,
-       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_is_set,
+       [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_is_set_recursive,
        [BT_FIELD_TYPE_ID_FLOAT] = bt_field_generic_is_set,
-       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_is_set,
-       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_is_set,
-       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_is_set,
-       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_is_set,
+       [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_is_set_recursive,
+       [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_is_set_recursive,
+       [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_is_set_recursive,
+       [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_is_set_recursive,
        [BT_FIELD_TYPE_ID_STRING] = bt_field_generic_is_set,
 };
 
+BT_ASSERT_FUNC
+static inline bool field_type_has_known_id(struct bt_field_type *ft)
+{
+       return ft->id > BT_FIELD_TYPE_ID_UNKNOWN ||
+               ft->id < BT_FIELD_TYPE_ID_NR;
+}
+
+#define BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(_field, _type_id, _name)               \
+       BT_ASSERT_PRE((_field)->type->id == (_type_id),                 \
+               _name " has the wrong type ID: expected-type-id=%s, "   \
+               "%![field-]+f", bt_field_type_id_string(_type_id),      \
+               (_field))
+
+#define BT_ASSERT_PRE_FIELD_IS_SET(_field, _name)                      \
+       BT_ASSERT_PRE(bt_field_is_set_recursive(_field),                \
+               _name " is not set: %!+f", (_field))
+
+#define BT_ASSERT_PRE_FIELD_HOT(_field, _name)                         \
+       BT_ASSERT_PRE_HOT((_field), (_name), ": +%!+f", (_field))
+
 struct bt_field *bt_field_create(struct bt_field_type *type)
 {
        struct bt_field *field = NULL;
        enum bt_field_type_id type_id;
-       int ret;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto error;
-       }
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT(field_type_has_known_id(type));
+       BT_ASSERT_PRE(bt_field_type_validate(type) == 0,
+               "Field type is invalid: %!+F", type);
 
        type_id = bt_field_type_get_type_id(type);
-       if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN ||
-                       type_id >= BT_FIELD_TYPE_ID_NR) {
-               BT_LOGW("Invalid parameter: unknown field type ID: "
-                       "ft-addr=%p, ft-id=%d", type, type_id);
-               goto error;
-       }
-
-       /* Field class MUST be valid */
-       ret = bt_field_type_validate(type);
-       if (ret) {
-               /* Invalid */
-               BT_LOGW("Invalid parameter: field type is invalid: "
-                       "ft-addr=%p", type);
-               goto error;
-       }
-
        field = field_create_funcs[type_id](type);
        if (!field) {
                goto error;
@@ -341,29 +335,16 @@ struct bt_field_type *bt_field_get_type(struct bt_field *field)
 {
        struct bt_field_type *ret = NULL;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Field");
        ret = field->type;
        bt_get(ret);
-end:
        return ret;
 }
 
 enum bt_field_type_id bt_field_get_type_id(struct bt_field *field)
 {
-       enum bt_field_type_id ret = BT_FIELD_TYPE_ID_UNKNOWN;
-
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
-
-       ret = bt_field_type_get_type_id(field->type);
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(field, "Field");
+       return bt_field_type_get_type_id(field->type);
 }
 
 bt_bool bt_field_is_integer(struct bt_field *field)
@@ -412,8 +393,8 @@ int64_t bt_field_sequence_get_int_length(struct bt_field *field)
        struct bt_field_sequence *sequence;
        int64_t ret;
 
-       assert(field);
-       assert(bt_field_type_get_type_id(field->type) ==
+       BT_ASSERT(field);
+       BT_ASSERT(bt_field_type_get_type_id(field->type) ==
                BT_FIELD_TYPE_ID_SEQUENCE);
        sequence = container_of(field, struct bt_field_sequence, parent);
        if (!sequence->length) {
@@ -433,24 +414,12 @@ struct bt_field *bt_field_sequence_get_length(
        struct bt_field *ret = NULL;
        struct bt_field_sequence *sequence;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_SEQUENCE) {
-               BT_LOGW("Invalid parameter: field's type is not a sequence field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Sequence field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_SEQUENCE,
+               "Field");
        sequence = container_of(field, struct bt_field_sequence, parent);
        ret = sequence->length;
        bt_get(ret);
-end:
        return ret;
 }
 
@@ -458,60 +427,18 @@ int bt_field_sequence_set_length(struct bt_field *field,
                struct bt_field *length_field)
 {
        int ret = 0;
-       struct bt_field_type_integer *length_type;
        struct bt_field_integer *length;
        struct bt_field_sequence *sequence;
        uint64_t sequence_length;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!length_field) {
-               BT_LOGW_STR("Invalid parameter: length field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (field->frozen) {
-               BT_LOGW("Invalid parameter: field is frozen: addr=%p",
-                       field);
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(length_field->type) !=
-                       BT_FIELD_TYPE_ID_INTEGER) {
-               BT_LOGW("Invalid parameter: length field's type is not an integer field type: "
-                       "field-addr=%p, length-field-addr=%p, length-ft-addr=%p, length-ft-id=%s",
-                       field, length_field, length_field->type,
-                       bt_field_type_id_string(length_field->type->id));
-               ret = -1;
-               goto end;
-       }
-
-       length_type = container_of(length_field->type,
-               struct bt_field_type_integer, parent);
-       /* The length field must be unsigned */
-       if (length_type->is_signed) {
-               BT_LOGW("Invalid parameter: length field's type is signed: "
-                       "field-addr=%p, length-field-addr=%p, "
-                       "length-field-ft-addr=%p", field, length_field,
-                       length_field->type);
-               ret = -1;
-               goto end;
-       }
-
-       if (!bt_field_is_set(length_field)) {
-               BT_LOGW("Invalid parameter: length field's value is not set: "
-                       "field-addr=%p, length-field-addr=%p, "
-                       "length-field-ft-addr=%p", field, length_field,
-                       length_field->type);
-               ret = -1;
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(field, "Sequence field");
+       BT_ASSERT_PRE_NON_NULL(length_field, "Length field");
+       BT_ASSERT_PRE_FIELD_HOT(field, "Sequence field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(length_field, BT_FIELD_TYPE_ID_INTEGER,
+               "Length field");
+       BT_ASSERT_PRE(!bt_field_type_integer_is_signed(length_field->type),
+               "Length field's type is signed: %!+f", length_field);
+       BT_ASSERT_PRE_FIELD_IS_SET(length_field, "Length field");
 
        length = container_of(length_field, struct bt_field_integer,
                parent);
@@ -534,7 +461,8 @@ int bt_field_sequence_set_length(struct bt_field *field,
        g_ptr_array_set_size(sequence->elements, (size_t) sequence_length);
        bt_get(length_field);
        sequence->length = length_field;
-       bt_field_freeze(length_field);
+       bt_field_freeze_recursive(length_field);
+
 end:
        return ret;
 }
@@ -548,25 +476,9 @@ struct bt_field *bt_field_structure_get_field_by_name(
        size_t index;
        GHashTable *field_name_to_index;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto error;
-       }
-
-       if (!name) {
-               BT_LOGW_STR("Invalid parameter: field name is NULL.");
-               goto error;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_STRUCT) {
-               BT_LOGW("Invalid parameter: field's type is not a structure field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               goto error;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Structure field");
+       BT_ASSERT_PRE_NON_NULL(name, "Field name");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRUCT, "Field");
        field_name_to_index =
                container_of(field->type, struct bt_field_type_structure,
                        parent)->field_name_to_index;
@@ -582,7 +494,8 @@ struct bt_field *bt_field_structure_get_field_by_name(
        }
 
        ret = bt_get(structure->fields->pdata[index]);
-       assert(ret);
+       BT_ASSERT(ret);
+
 error:
        return ret;
 }
@@ -593,30 +506,38 @@ struct bt_field *bt_field_structure_get_field_by_index(
        struct bt_field_structure *structure;
        struct bt_field *ret = NULL;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(field, "Structure field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRUCT, "Field");
+       structure = container_of(field, struct bt_field_structure, parent);
+       BT_ASSERT_PRE(index < structure->fields->len,
+               "Index is out of bound: %![struct-field-]+f, "
+               "index=%" PRIu64 ", count=%u", field, index,
+               structure->fields->len);
+       ret = bt_get(structure->fields->pdata[index]);
+       return ret;
+}
 
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_STRUCT) {
-               BT_LOGW("Invalid parameter: field's type is not a structure field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               goto end;
-       }
+BT_ASSERT_PRE_FUNC
+static inline bool field_to_set_has_expected_type(struct bt_field *struct_field,
+               const char *name, struct bt_field *value)
+{
+       bool ret = true;
+       struct bt_field_type *expected_field_type = NULL;
 
-       structure = container_of(field, struct bt_field_structure, parent);
-       if (index >= structure->fields->len) {
-               BT_LOGW("Invalid parameter: index is out of bounds: "
-                       "addr=%p, index=%" PRIu64 ", count=%u",
-                       field, index, structure->fields->len);
+       expected_field_type =
+               bt_field_type_structure_get_field_type_by_name(
+                       struct_field->type, name);
+
+       if (bt_field_type_compare(expected_field_type, value->type)) {
+               BT_ASSERT_PRE_MSG("Value field's type is different from the expected field type: "
+                       "%![value-ft-]+F, %![expected-ft-]+F", value->type,
+                       expected_field_type);
+               ret = false;
                goto end;
        }
 
-       ret = bt_get(structure->fields->pdata[index]);
 end:
+       bt_put(expected_field_type);
        return ret;
 }
 
@@ -626,53 +547,18 @@ int bt_field_structure_set_field_by_name(struct bt_field *field,
        int ret = 0;
        GQuark field_quark;
        struct bt_field_structure *structure;
-       struct bt_field_type *expected_field_type = NULL;
        size_t index;
        GHashTable *field_name_to_index;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: structure field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!name) {
-               BT_LOGW_STR("Invalid parameter: field name is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!value) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_STRUCT) {
-               BT_LOGW("Invalid parameter: field's type is not a structure field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Structure field");
+       BT_ASSERT_PRE_NON_NULL(name, "Field name");
+       BT_ASSERT_PRE_NON_NULL(value, "Value field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRUCT,
+               "Parent field");
+       BT_ASSERT_PRE(field_to_set_has_expected_type(field, name, value),
+               "Value field's type is different from the expected field type.");
        field_quark = g_quark_from_string(name);
        structure = container_of(field, struct bt_field_structure, parent);
-       expected_field_type =
-               bt_field_type_structure_get_field_type_by_name(field->type,
-               name);
-
-       if (bt_field_type_compare(expected_field_type, value->type)) {
-               BT_LOGW("Invalid parameter: field type of field to set is different from the expected field type: "
-                       "struct-field-addr=%p, field-addr=%p, "
-                       "field-ft-addr=%p, expected-ft-addr=%p",
-                       field, value, value->type, expected_field_type);
-               ret = -1;
-               goto end;
-       }
-
        field_name_to_index =
                container_of(field->type, struct bt_field_type_structure,
                        parent)->field_name_to_index;
@@ -688,10 +574,8 @@ int bt_field_structure_set_field_by_name(struct bt_field *field,
        }
        bt_get(value);
        BT_MOVE(structure->fields->pdata[index], value);
+
 end:
-       if (expected_field_type) {
-               bt_put(expected_field_type);
-       }
        return ret;
 }
 
@@ -702,56 +586,28 @@ struct bt_field *bt_field_array_get_field(struct bt_field *field,
        struct bt_field_type *field_type = NULL;
        struct bt_field_array *array;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_ARRAY) {
-               BT_LOGW("Invalid parameter: field's type is not an array field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Array field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_ARRAY, "Field");
        array = container_of(field, struct bt_field_array, parent);
-       if (index >= array->elements->len) {
-               BT_LOGW("Invalid parameter: index is out of bounds: "
-                       "addr=%p, index=%" PRIu64 ", count=%u",
-                       field, index, array->elements->len);
-               goto end;
-       }
+       BT_ASSERT_PRE(index < array->elements->len,
+               "Index is out of bound: %![array-field-]+f, "
+               "index=%" PRIu64 ", count=%u", field,
+               index, array->elements->len);
 
        field_type = bt_field_type_array_get_element_type(field->type);
-       if (array->elements->pdata[(size_t)index]) {
-               new_field = array->elements->pdata[(size_t)index];
+       if (array->elements->pdata[(size_t) index]) {
+               new_field = array->elements->pdata[(size_t) index];
                goto end;
        }
 
        /* We don't want to modify this field if it's frozen */
-       if (field->frozen) {
-               /*
-                * Not logging a warning here because the user could
-                * legitimately check if a array field is set with
-                * this function: if the preconditions are satisfied,
-                * a NULL return value means this.
-                */
-               BT_LOGV("Not creating a field because array field is frozen: "
-                       "array-field-addr=%p, index=%" PRIu64, field, index);
-               goto end;
-       }
-
+       BT_ASSERT_PRE_FIELD_HOT(field, "Array field");
        new_field = bt_field_create(field_type);
        array->elements->pdata[(size_t)index] = new_field;
+
 end:
-       if (field_type) {
-               bt_put(field_type);
-       }
-       if (new_field) {
-               bt_get(new_field);
-       }
+       bt_put(field_type);
+       bt_get(new_field);
        return new_field;
 }
 
@@ -762,34 +618,15 @@ struct bt_field *bt_field_sequence_get_field(struct bt_field *field,
        struct bt_field_type *field_type = NULL;
        struct bt_field_sequence *sequence;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_SEQUENCE) {
-               BT_LOGW("Invalid parameter: field's type is not a sequence field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Sequence field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_SEQUENCE,
+               "Field");
        sequence = container_of(field, struct bt_field_sequence, parent);
-       if (!sequence->elements) {
-               BT_LOGV("Sequence field's elements do not exist: addr=%p",
-                       field);
-               goto end;
-       }
-
-       if (index >= sequence->elements->len) {
-               BT_LOGW("Invalid parameter: index is out of bounds: "
-                       "addr=%p, index=%" PRIu64 ", count=%u",
-                       field, index, sequence->elements->len);
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(sequence->elements, "Sequence field's element array");
+       BT_ASSERT_PRE(index < sequence->elements->len,
+               "Index is out of bound: %![seq-field-]+f, "
+               "index=%" PRIu64 ", count=%u", field, index,
+               sequence->elements->len);
        field_type = bt_field_type_sequence_get_element_type(field->type);
        if (sequence->elements->pdata[(size_t) index]) {
                new_field = sequence->elements->pdata[(size_t) index];
@@ -797,27 +634,13 @@ struct bt_field *bt_field_sequence_get_field(struct bt_field *field,
        }
 
        /* We don't want to modify this field if it's frozen */
-       if (field->frozen) {
-               /*
-                * Not logging a warning here because the user could
-                * legitimately check if a sequence field is set with
-                * this function: if the preconditions are satisfied,
-                * a NULL return value means this.
-                */
-               BT_LOGV("Not creating a field because sequence field is frozen: "
-                       "sequence-field-addr=%p, index=%" PRIu64, field, index);
-               goto end;
-       }
-
+       BT_ASSERT_PRE_FIELD_HOT(field, "Sequence field");
        new_field = bt_field_create(field_type);
        sequence->elements->pdata[(size_t) index] = new_field;
+
 end:
-       if (field_type) {
-               bt_put(field_type);
-       }
-       if (new_field) {
-               bt_get(new_field);
-       }
+       bt_put(field_type);
+       bt_get(new_field);
        return new_field;
 }
 
@@ -832,52 +655,21 @@ struct bt_field *bt_field_variant_get_field(struct bt_field *field,
        struct bt_field_integer *tag_enum_integer;
        int64_t tag_enum_value;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
-
-       if (!tag_field) {
-               BT_LOGW_STR("Invalid parameter: tag field is NULL.");
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_VARIANT) {
-               BT_LOGW("Invalid parameter: field's type is not a variant field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(tag_field->type) !=
-                       BT_FIELD_TYPE_ID_ENUM) {
-               BT_LOGW("Invalid parameter: tag field's type is not an enumeration field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", tag_field,
-                       tag_field->type,
-                       bt_field_type_id_string(tag_field->type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Variant field");
+       BT_ASSERT_PRE_NON_NULL(tag_field, "Tag field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_VARIANT,
+               "Variant field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(tag_field, BT_FIELD_TYPE_ID_ENUM,
+               "Tag field");
        variant = container_of(field, struct bt_field_variant, parent);
        variant_type = container_of(field->type,
                struct bt_field_type_variant, parent);
        tag_enum = bt_field_enumeration_get_container(tag_field);
-       if (!tag_enum) {
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(tag_enum, "Tag field's container");
        tag_enum_integer = container_of(tag_enum, struct bt_field_integer,
                parent);
-
-       if (bt_field_validate(tag_field) < 0) {
-               BT_LOGW("Invalid parameter: tag field is invalid: "
-                       "variant-field-addr=%p, tag-field-addr=%p",
-                       field, tag_field);
-               goto end;
-       }
-
+       BT_ASSERT_PRE(bt_field_validate_recursive(tag_field) == 0,
+               "Tag field is invalid: %!+f", tag_field);
        tag_enum_value = tag_enum_integer->payload.signd;
 
        /*
@@ -892,7 +684,7 @@ struct bt_field *bt_field_variant_get_field(struct bt_field *field,
 
                cur_tag_container =
                        bt_field_enumeration_get_container(variant->tag);
-               assert(cur_tag_container);
+               BT_ASSERT(cur_tag_container);
                cur_tag_enum_integer = container_of(cur_tag_container,
                        struct bt_field_integer, parent);
                bt_put(cur_tag_container);
@@ -906,28 +698,16 @@ struct bt_field *bt_field_variant_get_field(struct bt_field *field,
        }
 
        /* We don't want to modify this field if it's frozen */
-       if (field->frozen) {
-               /*
-                * Not logging a warning here because the user could
-                * legitimately check if a variant field is set with
-                * this function: if the preconditions are satisfied,
-                * a NULL return value means this.
-                */
-               BT_LOGV("Not creating a field because variant field is frozen: "
-                       "variant-field-addr=%p, tag-field-addr=%p",
-                       field, tag_field);
-               goto end;
-       }
-
+       BT_ASSERT_PRE_FIELD_HOT(field, "Variant field");
        field_type = bt_field_type_variant_get_field_type_signed(
                variant_type, tag_enum_value);
-       if (!field_type) {
-               BT_LOGW("Cannot get variant field type's field: "
-                       "variant-field-addr=%p, variant-ft-addr=%p, "
-                       "tag-value-signed=%" PRId64,
-                       field, variant_type, tag_enum_value);
-               goto end;
-       }
+
+       /* It's the caller's job to make sure the tag's value is valid */
+       BT_ASSERT_PRE(field_type,
+               "Variant field's type does not contain a field type for "
+               "this tag value: tag-value-signed=%" PRId64 ", "
+               "%![var-ft-]+F, %![tag-field-]+f", tag_enum_value,
+               variant_type, tag_field);
 
        new_field = bt_field_create(field_type);
        if (!new_field) {
@@ -943,6 +723,7 @@ struct bt_field *bt_field_variant_get_field(struct bt_field *field,
        bt_get(tag_field);
        variant->tag = tag_field;
        variant->payload = new_field;
+
 end:
        bt_put(tag_enum);
        return new_field;
@@ -951,113 +732,51 @@ end:
 struct bt_field *bt_field_variant_get_current_field(
                struct bt_field *variant_field)
 {
-       struct bt_field *current_field = NULL;
        struct bt_field_variant *variant;
 
-       if (!variant_field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(variant_field->type) !=
-                       BT_FIELD_TYPE_ID_VARIANT) {
-               BT_LOGW("Invalid parameter: field's type is not a variant field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field,
-                       variant_field->type,
-                       bt_field_type_id_string(variant_field->type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(variant_field, "Variant field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(variant_field, BT_FIELD_TYPE_ID_VARIANT,
+               "Field");
        variant = container_of(variant_field, struct bt_field_variant,
                parent);
-
-       if (variant->payload) {
-               current_field = variant->payload;
-               bt_get(current_field);
-               goto end;
-       }
-
-end:
-       return current_field;
+       return bt_get(variant->payload);
 }
 
-struct bt_field *bt_field_variant_get_tag(
-               struct bt_field *variant_field)
+struct bt_field *bt_field_variant_get_tag(struct bt_field *variant_field)
 {
-       struct bt_field *tag = NULL;
        struct bt_field_variant *variant;
 
-       if (!variant_field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(variant_field->type) !=
-                       BT_FIELD_TYPE_ID_VARIANT) {
-               BT_LOGW("Invalid parameter: field's type is not a variant field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field,
-                       variant_field->type,
-                       bt_field_type_id_string(variant_field->type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(variant_field, "Variant field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(variant_field, BT_FIELD_TYPE_ID_VARIANT,
+               "Field");
        variant = container_of(variant_field, struct bt_field_variant,
                        parent);
-       if (variant->tag) {
-               tag = bt_get(variant->tag);
-       }
-end:
-       return tag;
+       return bt_get(variant->tag);
 }
 
-struct bt_field *bt_field_enumeration_get_container(
-       struct bt_field *field)
+struct bt_field *bt_field_enumeration_get_container(struct bt_field *field)
 {
        struct bt_field *container = NULL;
        struct bt_field_enumeration *enumeration;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_ENUM) {
-               BT_LOGW("Invalid parameter: field's type is not an enumeration field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Enumeration field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_ENUM, "Field");
        enumeration = container_of(field, struct bt_field_enumeration,
                parent);
        if (!enumeration->payload) {
+               struct bt_field_type_enumeration *enumeration_type;
+
                /* We don't want to modify this field if it's frozen */
-               if (field->frozen) {
-                       /*
-                        * Not logging a warning here because the user
-                        * could legitimately check if an enumeration's
-                        * container field is set with this function: if
-                        * the preconditions are satisfied, a NULL
-                        * return value means this.
-                        */
-                       BT_LOGV("Not creating a field because enumeration field is frozen: "
-                               "enum-field-addr=%p", field);
-                       goto end;
-               }
+               BT_ASSERT_PRE_FIELD_HOT(field, "Enumeration field");
 
-               struct bt_field_type_enumeration *enumeration_type =
-                       container_of(field->type,
+               enumeration_type = container_of(field->type,
                        struct bt_field_type_enumeration, parent);
                enumeration->payload =
                        bt_field_create(enumeration_type->container);
        }
 
        container = enumeration->payload;
-       bt_get(container);
-end:
-       return container;
+       return bt_get(container);
 }
 
 struct bt_field_type_enumeration_mapping_iterator *
@@ -1065,422 +784,202 @@ bt_field_enumeration_get_mappings(struct bt_field *field)
 {
        int ret;
        struct bt_field *container = NULL;
-       struct bt_field_type *container_type = NULL;
        struct bt_field_type_integer *integer_type = NULL;
        struct bt_field_type_enumeration_mapping_iterator *iter = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(field, "Enumeration field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_ENUM, "Field");
        container = bt_field_enumeration_get_container(field);
-       if (!container) {
-               BT_LOGW("Invalid parameter: enumeration field has no container field: "
-                       "addr=%p", field);
-               goto end;
-       }
-
-       container_type = bt_field_get_type(container);
-       assert(container_type);
-       integer_type = container_of(container_type,
+       BT_ASSERT_PRE(container,
+               "Enumeration field has no container field: %!+f", field);
+       BT_ASSERT(container->type);
+       integer_type = container_of(container->type,
                struct bt_field_type_integer, parent);
+       BT_ASSERT_PRE_FIELD_IS_SET(container,
+               "Enumeration field's payload field");
 
        if (!integer_type->is_signed) {
                uint64_t value;
 
-               ret = bt_field_unsigned_integer_get_value(container,
-                     &value);
-               if (ret) {
-                       BT_LOGW("Cannot get value from signed enumeration field's payload field: "
-                               "enum-field-addr=%p, payload-field-addr=%p",
-                               field, container);
-                       goto error_put_container_type;
-               }
+               ret = bt_field_unsigned_integer_get_value(container, &value);
+               BT_ASSERT(ret == 0);
                iter = bt_field_type_enumeration_find_mappings_by_unsigned_value(
                                field->type, value);
        } else {
                int64_t value;
 
-               ret = bt_field_signed_integer_get_value(container,
-                     &value);
-               if (ret) {
-                       BT_LOGW("Cannot get value from unsigned enumeration field's payload field: "
-                               "enum-field-addr=%p, payload-field-addr=%p",
-                               field, container);
-                       goto error_put_container_type;
-               }
+               ret = bt_field_signed_integer_get_value(container, &value);
+               BT_ASSERT(ret == 0);
                iter = bt_field_type_enumeration_find_mappings_by_signed_value(
                                field->type, value);
        }
 
-error_put_container_type:
-       bt_put(container_type);
        bt_put(container);
-end:
        return iter;
 }
 
-int bt_field_signed_integer_get_value(struct bt_field *field,
-               int64_t *value)
+int bt_field_signed_integer_get_value(struct bt_field *field, int64_t *value)
 {
-       int ret = 0;
        struct bt_field_integer *integer;
        struct bt_field_type_integer *integer_type;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!value) {
-               BT_LOGW_STR("Invalid parameter: value is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!field->payload_set) {
-               BT_LOGV("Field's payload is not set: addr=%p", field);
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_INTEGER) {
-               BT_LOGW("Invalid parameter: field's type is not an integer field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Integer field");
+       BT_ASSERT_PRE_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_FIELD_IS_SET(field, "Integer field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_INTEGER, "Field");
        integer_type = container_of(field->type,
                struct bt_field_type_integer, parent);
-       if (!integer_type->is_signed) {
-               BT_LOGW("Invalid parameter: integer field's type is not signed: "
-                       "field-addr=%p, ft-addr=%p", field, field->type);
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE(bt_field_type_integer_is_signed(field->type),
+               "Field's type is unsigned: %!+f", field);
        integer = container_of(field,
                struct bt_field_integer, parent);
        *value = integer->payload.signd;
-end:
-       return ret;
+       return 0;
 }
 
-int bt_field_signed_integer_set_value(struct bt_field *field,
-               int64_t value)
+BT_ASSERT_PRE_FUNC
+static inline bool value_is_in_range_signed(unsigned int size, int64_t value)
 {
-       int ret = 0;
-       struct bt_field_integer *integer;
-       struct bt_field_type_integer *integer_type;
-       unsigned int size;
+       bool ret = true;
        int64_t min_value, max_value;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (field->frozen) {
-               BT_LOGW("Invalid parameter: field is frozen: addr=%p",
-                       field);
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_INTEGER) {
-               BT_LOGW("Invalid parameter: field's type is not an integer field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               ret = -1;
-               goto end;
-       }
-
-       integer = container_of(field, struct bt_field_integer, parent);
-       integer_type = container_of(field->type,
-               struct bt_field_type_integer, parent);
-       if (!integer_type->is_signed) {
-               BT_LOGW("Invalid parameter: integer field's type is not signed: "
-                       "field-addr=%p, ft-addr=%p", field, field->type);
-               ret = -1;
-               goto end;
-       }
-
-       size = integer_type->size;
        min_value = -(1ULL << (size - 1));
        max_value = (1ULL << (size - 1)) - 1;
        if (value < min_value || value > max_value) {
-               BT_LOGW("Invalid parameter: value is out of bounds: "
-                       "addr=%p, value=%" PRId64 ", "
+               BT_LOGF("Value is out of bounds: value=%" PRId64 ", "
                        "min-value=%" PRId64 ", max-value=%" PRId64,
-                       field, value, min_value, max_value);
-               ret = -1;
-               goto end;
+                       value, min_value, max_value);
+               ret = false;
        }
 
-       integer->payload.signd = value;
-       integer->parent.payload_set = true;
-end:
        return ret;
 }
 
-int bt_field_unsigned_integer_get_value(struct bt_field *field,
-               uint64_t *value)
+int bt_field_signed_integer_set_value(struct bt_field *field, int64_t value)
 {
        int ret = 0;
        struct bt_field_integer *integer;
        struct bt_field_type_integer *integer_type;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!value) {
-               BT_LOGW_STR("Invalid parameter: value is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!field->payload_set) {
-               BT_LOGV("Field's payload is not set: addr=%p", field);
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_INTEGER) {
-               BT_LOGW("Invalid parameter: field's type is not an integer field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Integer field");
+       BT_ASSERT_PRE_FIELD_HOT(field, "Integer field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_INTEGER, "Field");
+       integer = container_of(field, struct bt_field_integer, parent);
        integer_type = container_of(field->type,
                struct bt_field_type_integer, parent);
-       if (integer_type->is_signed) {
-               BT_LOGW("Invalid parameter: integer field's type is signed: "
-                       "field-addr=%p, ft-addr=%p", field, field->type);
-               ret = -1;
-               goto end;
-       }
-
-       integer = container_of(field,
-               struct bt_field_integer, parent);
-       *value = integer->payload.unsignd;
-end:
+       BT_ASSERT_PRE(bt_field_type_integer_is_signed(field->type),
+               "Field's type is unsigned: %!+f", field);
+       BT_ASSERT_PRE(value_is_in_range_signed(integer_type->size, value),
+               "Value is out of bounds: value=%" PRId64 ", %![field-]+f",
+               value, field);
+       integer->payload.signd = value;
+       bt_field_set(field, true);
        return ret;
 }
 
-int bt_field_unsigned_integer_set_value(struct bt_field *field,
-               uint64_t value)
+int bt_field_unsigned_integer_get_value(struct bt_field *field, uint64_t *value)
 {
-       int ret = 0;
        struct bt_field_integer *integer;
        struct bt_field_type_integer *integer_type;
-       unsigned int size;
-       uint64_t max_value;
-
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (field->frozen) {
-               BT_LOGW("Invalid parameter: field is frozen: addr=%p",
-                       field);
-               ret = -1;
-               goto end;
-       }
 
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_INTEGER) {
-               BT_LOGW("Invalid parameter: field's type is not an integer field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               ret = -1;
-               goto end;
-       }
-
-       integer = container_of(field, struct bt_field_integer, parent);
+       BT_ASSERT_PRE_NON_NULL(field, "Integer field");
+       BT_ASSERT_PRE_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_FIELD_IS_SET(field, "Integer field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_INTEGER, "Field");
        integer_type = container_of(field->type,
                struct bt_field_type_integer, parent);
-       if (integer_type->is_signed) {
-               BT_LOGW("Invalid parameter: integer field's type is signed: "
-                       "field-addr=%p, ft-addr=%p", field, field->type);
-               ret = -1;
-               goto end;
-       }
+       BT_ASSERT_PRE(!bt_field_type_integer_is_signed(field->type),
+               "Field's type is signed: %!+f", field);
+       integer = container_of(field, struct bt_field_integer, parent);
+       *value = integer->payload.unsignd;
+       return 0;
+}
+
+BT_ASSERT_PRE_FUNC
+static inline bool value_is_in_range_unsigned(unsigned int size, uint64_t value)
+{
+       bool ret = true;
+       int64_t max_value;
 
-       size = integer_type->size;
        max_value = (size == 64) ? UINT64_MAX : ((uint64_t) 1 << size) - 1;
        if (value > max_value) {
-               BT_LOGW("Invalid parameter: value is out of bounds: "
-                       "addr=%p, value=%" PRIu64 ", "
-                       "min-value=%" PRIu64 ", max-value=%" PRIu64,
-                       field, value, (uint64_t) 0, max_value);
-               ret = -1;
-               goto end;
+               BT_LOGF("Value is out of bounds: value=%" PRIu64 ", "
+                       "max-value=%" PRIu64,
+                       value, max_value);
+               ret = false;
        }
 
-       integer->payload.unsignd = value;
-       integer->parent.payload_set = true;
-end:
        return ret;
 }
 
-int bt_field_floating_point_get_value(struct bt_field *field,
-               double *value)
+int bt_field_unsigned_integer_set_value(struct bt_field *field, uint64_t value)
 {
-       int ret = 0;
-       struct bt_field_floating_point *floating_point;
-
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!value) {
-               BT_LOGW_STR("Invalid parameter: value is NULL.");
-               ret = -1;
-               goto end;
-       }
+       struct bt_field_integer *integer;
+       struct bt_field_type_integer *integer_type;
 
-       if (!field->payload_set) {
-               BT_LOGV("Field's payload is not set: addr=%p", field);
-               ret = -1;
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(field, "Integer field");
+       BT_ASSERT_PRE_FIELD_HOT(field, "Integer field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_INTEGER, "Field");
+       integer = container_of(field, struct bt_field_integer, parent);
+       integer_type = container_of(field->type,
+               struct bt_field_type_integer, parent);
+       BT_ASSERT_PRE(!bt_field_type_integer_is_signed(field->type),
+               "Field's type is signed: %!+f", field);
+       BT_ASSERT_PRE(value_is_in_range_unsigned(integer_type->size, value),
+               "Value is out of bounds: value=%" PRIu64 ", %![field-]+f",
+               value, field);
+       integer->payload.unsignd = value;
+       bt_field_set(field, true);
+       return 0;
+}
 
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_FLOAT) {
-               BT_LOGW("Invalid parameter: field's type is not a floating point number field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               ret = -1;
-               goto end;
-       }
+int bt_field_floating_point_get_value(struct bt_field *field, double *value)
+{
+       struct bt_field_floating_point *floating_point;
 
+       BT_ASSERT_PRE_NON_NULL(field, "Floating point number field");
+       BT_ASSERT_PRE_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_FIELD_IS_SET(field, "Floating point number field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_FLOAT, "Field");
        floating_point = container_of(field,
                struct bt_field_floating_point, parent);
        *value = floating_point->payload;
-end:
-       return ret;
+       return 0;
 }
 
-int bt_field_floating_point_set_value(struct bt_field *field,
-               double value)
+int bt_field_floating_point_set_value(struct bt_field *field, double value)
 {
-       int ret = 0;
        struct bt_field_floating_point *floating_point;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (field->frozen) {
-               BT_LOGW("Invalid parameter: field is frozen: addr=%p",
-                       field);
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_FLOAT) {
-               BT_LOGW("Invalid parameter: field's type is not a floating point number field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Floating point number field");
+       BT_ASSERT_PRE_FIELD_HOT(field, "Floating point number field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_FLOAT, "Field");
        floating_point = container_of(field, struct bt_field_floating_point,
                parent);
        floating_point->payload = value;
-       floating_point->parent.payload_set = true;
-end:
-       return ret;
+       bt_field_set(field, true);
+       return 0;
 }
 
 const char *bt_field_string_get_value(struct bt_field *field)
 {
-       const char *ret = NULL;
        struct bt_field_string *string;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
-
-       if (!field->payload_set) {
-               BT_LOGV("Field's payload is not set: addr=%p", field);
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_STRING) {
-               BT_LOGW("Invalid parameter: field's type is not a string field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               goto end;
-       }
-
-       string = container_of(field,
-               struct bt_field_string, parent);
-       ret = string->payload->str;
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(field, "String field");
+       BT_ASSERT_PRE_FIELD_IS_SET(field, "String field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRING, "Field");
+       string = container_of(field, struct bt_field_string, parent);
+       return string->payload->str;
 }
 
-int bt_field_string_set_value(struct bt_field *field,
-               const char *value)
+int bt_field_string_set_value(struct bt_field *field, const char *value)
 {
-       int ret = 0;
        struct bt_field_string *string;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!value) {
-               BT_LOGW_STR("Invalid parameter: value is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (field->frozen) {
-               BT_LOGW("Invalid parameter: field is frozen: addr=%p",
-                       field);
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_STRING) {
-               BT_LOGW("Invalid parameter: field's type is not a string field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "String field");
+       BT_ASSERT_PRE_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_FIELD_HOT(field, "String field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRING, "Field");
        string = container_of(field, struct bt_field_string, parent);
        if (string->payload) {
                g_string_assign(string->payload, value);
@@ -1488,210 +987,103 @@ int bt_field_string_set_value(struct bt_field *field,
                string->payload = g_string_new(value);
        }
 
-       string->parent.payload_set = true;
-end:
-       return ret;
+       bt_field_set(field, true);
+       return 0;
 }
 
-int bt_field_string_append(struct bt_field *field,
-               const char *value)
+int bt_field_string_append(struct bt_field *field, const char *value)
 {
-       int ret = 0;
        struct bt_field_string *string_field;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!value) {
-               BT_LOGW_STR("Invalid parameter: value is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (field->frozen) {
-               BT_LOGW("Invalid parameter: field is frozen: addr=%p",
-                       field);
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_STRING) {
-               BT_LOGW("Invalid parameter: field's type is not a string field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "String field");
+       BT_ASSERT_PRE_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_FIELD_HOT(field, "String field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRING, "Field");
        string_field = container_of(field, struct bt_field_string, parent);
-
        if (string_field->payload) {
                g_string_append(string_field->payload, value);
        } else {
                string_field->payload = g_string_new(value);
        }
 
-       string_field->parent.payload_set = true;
-
-end:
-       return ret;
+       bt_field_set(field, true);
+       return 0;
 }
 
-int bt_field_string_append_len(struct bt_field *field,
-               const char *value, unsigned int length)
+int bt_field_string_append_len(struct bt_field *field, const char *value,
+               unsigned int length)
 {
-       int i;
-       int ret = 0;
-       unsigned int effective_length = length;
        struct bt_field_string *string_field;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!value) {
-               BT_LOGW_STR("Invalid parameter: value is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (field->frozen) {
-               BT_LOGW("Invalid parameter: field is frozen: addr=%p",
-                       field);
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(field->type) !=
-                       BT_FIELD_TYPE_ID_STRING) {
-               BT_LOGW("Invalid parameter: field's type is not a string field type: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%s", field,
-                       field->type,
-                       bt_field_type_id_string(field->type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "String field");
+       BT_ASSERT_PRE_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_FIELD_HOT(field, "String field");
+       BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRING, "Field");
        string_field = container_of(field, struct bt_field_string, parent);
 
        /* make sure no null bytes are appended */
-       for (i = 0; i < length; ++i) {
-               if (value[i] == '\0') {
-                       effective_length = i;
-                       break;
-               }
-       }
+       BT_ASSERT_PRE(memchr(value, '\0', length) == NULL,
+               "String value to append contains a null character: "
+               "partial-value=\"%.32s\", length=%u", value, length);
 
        if (string_field->payload) {
-               g_string_append_len(string_field->payload, value,
-                       effective_length);
+               g_string_append_len(string_field->payload, value, length);
        } else {
-               string_field->payload = g_string_new_len(value,
-                       effective_length);
+               string_field->payload = g_string_new_len(value, length);
        }
 
-       string_field->parent.payload_set = true;
-
-end:
-       return ret;
+       bt_field_set(field, true);
+       return 0;
 }
 
 BT_HIDDEN
-int bt_field_validate(struct bt_field *field)
+int _bt_field_validate_recursive(struct bt_field *field)
 {
        int ret = 0;
        enum bt_field_type_id type_id;
 
        if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
+               BT_ASSERT_PRE_MSG("%s", "Invalid field: field is NULL.");
                ret = -1;
                goto end;
        }
 
+       BT_ASSERT(field_type_has_known_id(field->type));
        type_id = bt_field_type_get_type_id(field->type);
-       if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_FIELD_TYPE_ID_NR) {
-               BT_LOGW("Invalid parameter: unknown field type ID: "
-                       "addr=%p, ft-addr=%p, ft-id=%d",
-                       field, field->type, type_id);
-               ret = -1;
-               goto end;
-       }
-
        ret = field_validate_funcs[type_id](field);
+
 end:
        return ret;
 }
 
-int bt_field_reset(struct bt_field *field)
-{
-       int ret = 0;
-       enum bt_field_type_id type_id;
-
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (field->frozen) {
-               BT_LOGW("Invalid parameter: field is frozen: addr=%p",
-                       field);
-               ret = -1;
-               goto end;
-       }
-
-       type_id = bt_field_type_get_type_id(field->type);
-       if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_FIELD_TYPE_ID_NR) {
-               BT_LOGW("Invalid parameter: unknown field type ID: "
-                       "addr=%p, ft-addr=%p, ft-id=%d",
-                       field, field->type, type_id);
-               ret = -1;
-               goto end;
-       }
+BT_HIDDEN
+void _bt_field_reset_recursive(struct bt_field *field)
+{      BT_ASSERT(field);
+       field_reset_funcs[field->type->id](field);
+}
 
-       ret = field_reset_funcs[type_id](field);
-end:
-       return ret;
+BT_HIDDEN
+void _bt_field_set(struct bt_field *field, bool value)
+{
+       BT_ASSERT(field);
+       field->payload_set = value;
 }
 
 BT_HIDDEN
-int bt_field_serialize(struct bt_field *field,
-               struct bt_stream_pos *pos,
+int bt_field_serialize_recursive(struct bt_field *field, struct bt_stream_pos *pos,
                enum bt_byte_order native_byte_order)
 {
-       int ret = 0;
        enum bt_field_type_id type_id;
 
-       assert(pos);
-
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(pos);
+       BT_ASSERT_PRE_NON_NULL(field, "Field");
+       BT_ASSERT(field_type_has_known_id(field->type));
        type_id = bt_field_type_get_type_id(field->type);
-       if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_FIELD_TYPE_ID_NR) {
-               BT_LOGW("Invalid parameter: unknown field type ID: "
-                       "addr=%p, ft-addr=%p, ft-id=%d",
-                       field, field->type, type_id);
-               ret = -1;
-               goto end;
-       }
-
-       ret = field_serialize_funcs[type_id](field, pos, native_byte_order);
-end:
-       return ret;
+       return field_serialize_funcs[type_id](field, pos, native_byte_order);
 }
 
-bt_bool bt_field_is_set(struct bt_field *field)
+BT_HIDDEN
+bt_bool _bt_field_is_set_recursive(struct bt_field *field)
 {
        bt_bool is_set = BT_FALSE;
        enum bt_field_type_id type_id;
@@ -1700,15 +1092,10 @@ bt_bool bt_field_is_set(struct bt_field *field)
                goto end;
        }
 
+       BT_ASSERT(field_type_has_known_id(field->type));
        type_id = bt_field_type_get_type_id(field->type);
-       if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_FIELD_TYPE_ID_NR) {
-               BT_LOGW("Invalid parameter: unknown field type ID: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%d",
-                       field, field->type, type_id);
-               goto end;
-       }
-
        is_set = field_is_set_funcs[type_id](field);
+
 end:
        return is_set;
 }
@@ -1719,31 +1106,21 @@ struct bt_field *bt_field_copy(struct bt_field *field)
        struct bt_field *copy = NULL;
        enum bt_field_type_id type_id;
 
-       if (!field) {
-               BT_LOGW_STR("Invalid parameter: field is NULL.");
-               goto end;
-       }
-
-       type_id = bt_field_type_get_type_id(field->type);
-       if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_FIELD_TYPE_ID_NR) {
-               BT_LOGW("Invalid parameter: unknown field type ID: "
-                       "field-addr=%p, ft-addr=%p, ft-id=%d",
-                       field, field->type, type_id);
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(field, "Field");
+       BT_ASSERT(field_type_has_known_id(field->type));
        copy = bt_field_create(field->type);
        if (!copy) {
                BT_LOGW("Cannot create field: ft-addr=%p", field->type);
                goto end;
        }
 
-       copy->payload_set = field->payload_set;
+       bt_field_set(copy, field->payload_set);
+       type_id = bt_field_type_get_type_id(field->type);
        ret = field_copy_funcs[type_id](field, copy);
        if (ret) {
-               bt_put(copy);
-               copy = NULL;
+               BT_PUT(copy);
        }
+
 end:
        return copy;
 }
@@ -1837,7 +1214,7 @@ struct bt_field *bt_field_structure_create(
                if (!field) {
                        BT_LOGE("Failed to create structure field's member: name=\"%s\", index=%zu",
                                g_quark_to_string(field_type->name), i);
-                       bt_field_structure_destroy(&structure->parent);
+                       bt_field_structure_destroy_recursive(&structure->parent);
                        goto end;
                }
 
@@ -1877,7 +1254,7 @@ struct bt_field *bt_field_array_create(struct bt_field_type *type)
        unsigned int array_length;
 
        BT_LOGD("Creating array field object: ft-addr=%p", type);
-       assert(type);
+       BT_ASSERT(type);
 
        if (!array) {
                BT_LOGE_STR("Failed to allocate one array field.");
@@ -1946,11 +1323,11 @@ void bt_field_destroy(struct bt_object *obj)
        struct bt_field_type *type;
        enum bt_field_type_id type_id;
 
+       BT_ASSERT(obj);
        field = container_of(obj, struct bt_field, base);
        type = field->type;
+       BT_ASSERT(field_type_has_known_id(type));
        type_id = bt_field_type_get_type_id(type);
-       assert(type_id > BT_FIELD_TYPE_ID_UNKNOWN &&
-               type_id < BT_FIELD_TYPE_ID_NR);
        field_destroy_funcs[type_id](field);
        BT_LOGD_STR("Putting field's type.");
        bt_put(type);
@@ -1961,24 +1338,18 @@ void bt_field_integer_destroy(struct bt_field *field)
 {
        struct bt_field_integer *integer;
 
-       if (!field) {
-               return;
-       }
-
+       BT_ASSERT(field);
        BT_LOGD("Destroying integer field object: addr=%p", field);
        integer = container_of(field, struct bt_field_integer, parent);
        g_free(integer);
 }
 
 static
-void bt_field_enumeration_destroy(struct bt_field *field)
+void bt_field_enumeration_destroy_recursive(struct bt_field *field)
 {
        struct bt_field_enumeration *enumeration;
 
-       if (!field) {
-               return;
-       }
-
+       BT_ASSERT(field);
        BT_LOGD("Destroying enumeration field object: addr=%p", field);
        enumeration = container_of(field, struct bt_field_enumeration,
                parent);
@@ -1992,10 +1363,7 @@ void bt_field_floating_point_destroy(struct bt_field *field)
 {
        struct bt_field_floating_point *floating_point;
 
-       if (!field) {
-               return;
-       }
-
+       BT_ASSERT(field);
        BT_LOGD("Destroying floating point number field object: addr=%p", field);
        floating_point = container_of(field, struct bt_field_floating_point,
                parent);
@@ -2003,14 +1371,11 @@ void bt_field_floating_point_destroy(struct bt_field *field)
 }
 
 static
-void bt_field_structure_destroy(struct bt_field *field)
+void bt_field_structure_destroy_recursive(struct bt_field *field)
 {
        struct bt_field_structure *structure;
 
-       if (!field) {
-               return;
-       }
-
+       BT_ASSERT(field);
        BT_LOGD("Destroying structure field object: addr=%p", field);
        structure = container_of(field, struct bt_field_structure, parent);
        g_ptr_array_free(structure->fields, TRUE);
@@ -2018,14 +1383,11 @@ void bt_field_structure_destroy(struct bt_field *field)
 }
 
 static
-void bt_field_variant_destroy(struct bt_field *field)
+void bt_field_variant_destroy_recursive(struct bt_field *field)
 {
        struct bt_field_variant *variant;
 
-       if (!field) {
-               return;
-       }
-
+       BT_ASSERT(field);
        BT_LOGD("Destroying variant field object: addr=%p", field);
        variant = container_of(field, struct bt_field_variant, parent);
        BT_LOGD_STR("Putting tag field.");
@@ -2036,14 +1398,11 @@ void bt_field_variant_destroy(struct bt_field *field)
 }
 
 static
-void bt_field_array_destroy(struct bt_field *field)
+void bt_field_array_destroy_recursive(struct bt_field *field)
 {
        struct bt_field_array *array;
 
-       if (!field) {
-               return;
-       }
-
+       BT_ASSERT(field);
        BT_LOGD("Destroying array field object: addr=%p", field);
        array = container_of(field, struct bt_field_array, parent);
        g_ptr_array_free(array->elements, TRUE);
@@ -2051,14 +1410,11 @@ void bt_field_array_destroy(struct bt_field *field)
 }
 
 static
-void bt_field_sequence_destroy(struct bt_field *field)
+void bt_field_sequence_destroy_recursive(struct bt_field *field)
 {
        struct bt_field_sequence *sequence;
 
-       if (!field) {
-               return;
-       }
-
+       BT_ASSERT(field);
        BT_LOGD("Destroying sequence field object: addr=%p", field);
        sequence = container_of(field, struct bt_field_sequence, parent);
        if (sequence->elements) {
@@ -2074,10 +1430,7 @@ void bt_field_string_destroy(struct bt_field *field)
 {
        struct bt_field_string *string;
 
-       if (!field) {
-               return;
-       }
-
+       BT_ASSERT(field);
        BT_LOGD("Destroying string field object: addr=%p", field);
        string = container_of(field, struct bt_field_string, parent);
        if (string->payload) {
@@ -2093,144 +1446,119 @@ int bt_field_generic_validate(struct bt_field *field)
 }
 
 static
-int bt_field_enumeration_validate(struct bt_field *field)
+int bt_field_enumeration_validate_recursive(struct bt_field *field)
 {
        int ret;
        struct bt_field_enumeration *enumeration;
 
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(field);
        enumeration = container_of(field, struct bt_field_enumeration,
                parent);
        if (!enumeration->payload) {
-               BT_LOGW("Invalid enumeration field: payload is not set: "
-                       "addr=%p", field);
+               BT_ASSERT_PRE_MSG("Invalid enumeration field: payload is not set: "
+                       "%!+f", field);
                ret = -1;
                goto end;
        }
 
-       ret = bt_field_validate(enumeration->payload);
+       ret = bt_field_validate_recursive(enumeration->payload);
+
 end:
        return ret;
 }
 
 static
-int bt_field_structure_validate(struct bt_field *field)
+int bt_field_structure_validate_recursive(struct bt_field *field)
 {
        int64_t i;
        int ret = 0;
        struct bt_field_structure *structure;
 
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(field);
        structure = container_of(field, struct bt_field_structure, parent);
+
        for (i = 0; i < structure->fields->len; i++) {
-               struct bt_field *entry_field = structure->fields->pdata[i];
-               ret = bt_field_validate(entry_field);
+               ret = bt_field_validate_recursive(
+                       (void *) structure->fields->pdata[i]);
 
                if (ret) {
                        int this_ret;
                        const char *name;
-                       struct bt_field_type *field_type =
-                                       bt_field_get_type(field);
 
                        this_ret = bt_field_type_structure_get_field_by_index(
-                               field_type, &name, NULL, i);
-                       assert(this_ret == 0);
-                       BT_LOGW("Invalid structure field's field: "
-                               "struct-field-addr=%p, field-addr=%p, "
-                               "field-name=\"%s\", index=%" PRId64,
-                               field, entry_field, name, i);
-                       bt_put(field_type);
+                               field->type, &name, NULL, i);
+                       BT_ASSERT(this_ret == 0);
+                       BT_ASSERT_PRE_MSG("Invalid structure field's field: "
+                               "%![struct-field-]+f, field-name=\"%s\", "
+                               "index=%" PRId64 ", %![field-]+f",
+                               field, name, i, structure->fields->pdata[i]);
                        goto end;
                }
        }
+
 end:
        return ret;
 }
 
 static
-int bt_field_variant_validate(struct bt_field *field)
+int bt_field_variant_validate_recursive(struct bt_field *field)
 {
        int ret = 0;
        struct bt_field_variant *variant;
 
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(field);
        variant = container_of(field, struct bt_field_variant, parent);
-       ret = bt_field_validate(variant->payload);
+       ret = bt_field_validate_recursive(variant->payload);
        if (ret) {
-               BT_LOGW("Invalid variant field's payload field: "
-                       "variant-field-addr=%p, variant-payload-field-addr=%p",
+               BT_ASSERT_PRE_MSG("Invalid variant field's payload field: "
+                       "%![variant-field-]+f, %![payload-field-]+f",
                        field, variant->payload);
        }
-end:
+
        return ret;
 }
 
 static
-int bt_field_array_validate(struct bt_field *field)
+int bt_field_array_validate_recursive(struct bt_field *field)
 {
        int64_t i;
        int ret = 0;
        struct bt_field_array *array;
 
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(field);
        array = container_of(field, struct bt_field_array, parent);
        for (i = 0; i < array->elements->len; i++) {
-               struct bt_field *elem_field = array->elements->pdata[i];
-
-               ret = bt_field_validate(elem_field);
+               ret = bt_field_validate_recursive((void *) array->elements->pdata[i]);
                if (ret) {
-                       BT_LOGW("Invalid array field's element field: "
-                               "array-field-addr=%p, field-addr=%p, "
-                               "index=%" PRId64, field, elem_field, i);
+                       BT_ASSERT_PRE_MSG("Invalid array field's element field: "
+                               "%![array-field-]+f, " PRId64 ", "
+                               "%![elem-field-]+f",
+                               field, i, array->elements->pdata[i]);
                        goto end;
                }
        }
+
 end:
        return ret;
 }
 
 static
-int bt_field_sequence_validate(struct bt_field *field)
+int bt_field_sequence_validate_recursive(struct bt_field *field)
 {
        size_t i;
        int ret = 0;
        struct bt_field_sequence *sequence;
 
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(field);
        sequence = container_of(field, struct bt_field_sequence, parent);
        for (i = 0; i < sequence->elements->len; i++) {
-               struct bt_field *elem_field = sequence->elements->pdata[i];
-
-               ret = bt_field_validate(elem_field);
+               ret = bt_field_validate_recursive(
+                       (void *) sequence->elements->pdata[i]);
                if (ret) {
-                       BT_LOGW("Invalid sequence field's element field: "
-                               "sequence-field-addr=%p, field-addr=%p, "
-                               "index=%zu", field, elem_field, i);
+                       BT_ASSERT_PRE_MSG("Invalid sequence field's element field: "
+                               "%![seq-field-]+f, " PRId64 ", "
+                               "%![elem-field-]+f",
+                               field, i, sequence->elements->pdata[i]);
                        goto end;
                }
        }
@@ -2239,182 +1567,114 @@ end:
 }
 
 static
-int bt_field_generic_reset(struct bt_field *field)
+void bt_field_generic_reset(struct bt_field *field)
 {
-       int ret = 0;
-
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(field);
        field->payload_set = false;
-end:
-       return ret;
 }
 
 static
-int bt_field_enumeration_reset(struct bt_field *field)
+void bt_field_enumeration_reset_recursive(struct bt_field *field)
 {
-       int ret = 0;
        struct bt_field_enumeration *enumeration;
 
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(field);
        enumeration = container_of(field, struct bt_field_enumeration,
                parent);
        if (!enumeration->payload) {
-               goto end;
+               return;
        }
 
-       ret = bt_field_reset(enumeration->payload);
-end:
-       return ret;
+       bt_field_reset_recursive(enumeration->payload);
 }
 
 static
-int bt_field_structure_reset(struct bt_field *field)
+void bt_field_structure_reset_recursive(struct bt_field *field)
 {
        int64_t i;
-       int ret = 0;
        struct bt_field_structure *structure;
 
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(field);
        structure = container_of(field, struct bt_field_structure, parent);
+
        for (i = 0; i < structure->fields->len; i++) {
                struct bt_field *member = structure->fields->pdata[i];
 
                if (!member) {
                        /*
-                        * Structure members are lazily initialized; skip if
-                        * this member has not been allocated yet.
+                        * Structure members are lazily initialized;
+                        * skip if this member has not been allocated
+                        * yet.
                         */
                        continue;
                }
 
-               ret = bt_field_reset(member);
-               if (ret) {
-                       BT_LOGE("Failed to reset structure field's field: "
-                               "struct-field-addr=%p, field-addr=%p, "
-                               "index=%" PRId64, field, member, i);
-                       goto end;
-               }
+               bt_field_reset_recursive(member);
        }
-end:
-       return ret;
 }
 
 static
-int bt_field_variant_reset(struct bt_field *field)
+void bt_field_variant_reset_recursive(struct bt_field *field)
 {
-       int ret = 0;
        struct bt_field_variant *variant;
 
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(field);
        variant = container_of(field, struct bt_field_variant, parent);
        BT_PUT(variant->tag);
        BT_PUT(variant->payload);
-end:
-       return ret;
 }
 
 static
-int bt_field_array_reset(struct bt_field *field)
+void bt_field_array_reset_recursive(struct bt_field *field)
 {
        size_t i;
-       int ret = 0;
        struct bt_field_array *array;
 
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(field);
        array = container_of(field, struct bt_field_array, parent);
+
        for (i = 0; i < array->elements->len; i++) {
                struct bt_field *member = array->elements->pdata[i];
 
                if (!member) {
                        /*
-                        * Array elements are lazily initialized; skip if
-                        * this member has not been allocated yet.
+                        * Array elements are lazily initialized; skip
+                        * if this member has not been allocated yet.
                         */
                        continue;
                }
 
-               ret = bt_field_reset(member);
-               if (ret) {
-                       BT_LOGE("Failed to reset array field's field: "
-                               "array-field-addr=%p, field-addr=%p, "
-                               "index=%zu", field, member, i);
-                       goto end;
-               }
+               bt_field_reset_recursive(member);
        }
-end:
-       return ret;
 }
 
 static
-int bt_field_sequence_reset(struct bt_field *field)
+void bt_field_sequence_reset_recursive(struct bt_field *field)
 {
-       int ret = 0;
        struct bt_field_sequence *sequence;
 
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(field);
        sequence = container_of(field, struct bt_field_sequence, parent);
+
        if (sequence->elements) {
                g_ptr_array_free(sequence->elements, TRUE);
                sequence->elements = NULL;
        }
+
        BT_PUT(sequence->length);
-end:
-       return ret;
 }
 
 static
-int bt_field_string_reset(struct bt_field *field)
+void bt_field_string_reset_recursive(struct bt_field *field)
 {
-       int ret = 0;
        struct bt_field_string *string;
 
-       if (!field) {
-               BT_LOGD_STR("Invalid parameter: field is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       ret = bt_field_generic_reset(field);
-       if (ret) {
-               goto end;
-       }
-
+       BT_ASSERT(field);
+       bt_field_generic_reset(field);
        string = container_of(field, struct bt_field_string, parent);
        if (string->payload) {
                g_string_truncate(string->payload, 0);
        }
-end:
-       return ret;
 }
 
 static
@@ -2426,15 +1686,11 @@ int bt_field_integer_serialize(struct bt_field *field,
        struct bt_field_integer *integer = container_of(field,
                struct bt_field_integer, parent);
 
+       BT_ASSERT_PRE_FIELD_IS_SET(field, "Integer field");
        BT_LOGV("Serializing integer field: addr=%p, pos-offset=%" PRId64 ", "
                "native-bo=%s", field, pos->offset,
                bt_byte_order_string(native_byte_order));
 
-       if (!bt_field_generic_is_set(field)) {
-               BT_LOGW_STR("Field's payload is not set.");
-               ret = -1;
-               goto end;
-       }
 retry:
        ret = bt_field_integer_write(integer, pos, native_byte_order);
        if (ret == -EFAULT) {
@@ -2449,12 +1705,13 @@ retry:
                }
                goto retry;
        }
+
 end:
        return ret;
 }
 
 static
-int bt_field_enumeration_serialize(struct bt_field *field,
+int bt_field_enumeration_serialize_recursive(struct bt_field *field,
                struct bt_stream_pos *pos,
                enum bt_byte_order native_byte_order)
 {
@@ -2465,7 +1722,7 @@ int bt_field_enumeration_serialize(struct bt_field *field,
                "native-bo=%s", field, pos->offset,
                bt_byte_order_string(native_byte_order));
        BT_LOGV_STR("Serializing enumeration field's payload field.");
-       return bt_field_serialize(enumeration->payload, pos,
+       return bt_field_serialize_recursive(enumeration->payload, pos,
                native_byte_order);
 }
 
@@ -2478,15 +1735,11 @@ int bt_field_floating_point_serialize(struct bt_field *field,
        struct bt_field_floating_point *floating_point = container_of(field,
                struct bt_field_floating_point, parent);
 
+       BT_ASSERT_PRE_FIELD_IS_SET(field, "Floating point number field");
        BT_LOGV("Serializing floating point number field: addr=%p, pos-offset=%" PRId64 ", "
                "native-bo=%s", field, pos->offset,
                bt_byte_order_string(native_byte_order));
 
-       if (!bt_field_generic_is_set(field)) {
-               BT_LOGW_STR("Field's payload is not set.");
-               ret = -1;
-               goto end;
-       }
 retry:
        ret = bt_field_floating_point_write(floating_point, pos,
                native_byte_order);
@@ -2502,12 +1755,13 @@ retry:
                }
                goto retry;
        }
+
 end:
        return ret;
 }
 
 static
-int bt_field_structure_serialize(struct bt_field *field,
+int bt_field_structure_serialize_recursive(struct bt_field *field,
                struct bt_stream_pos *pos,
                enum bt_byte_order native_byte_order)
 {
@@ -2541,17 +1795,14 @@ int bt_field_structure_serialize(struct bt_field *field,
                        structure->fields, i);
                const char *field_name = NULL;
 
-               if (BT_LOG_ON_WARN) {
-                       ret = bt_field_type_structure_get_field_by_index(
-                               field->type, &field_name, NULL, i);
-                       assert(ret == 0);
-               }
-
                BT_LOGV("Serializing structure field's field: pos-offset=%" PRId64 ", "
                        "field-addr=%p, index=%" PRId64,
                        pos->offset, member, i);
 
                if (!member) {
+                       ret = bt_field_type_structure_get_field_by_index(
+                               field->type, &field_name, NULL, i);
+                       BT_ASSERT(ret == 0);
                        BT_LOGW("Cannot serialize structure field's field: field is not set: "
                                "struct-field-addr=%p, "
                                "field-name=\"%s\", index=%" PRId64,
@@ -2560,8 +1811,12 @@ int bt_field_structure_serialize(struct bt_field *field,
                        goto end;
                }
 
-               ret = bt_field_serialize(member, pos, native_byte_order);
+               ret = bt_field_serialize_recursive(member, pos,
+                       native_byte_order);
                if (ret) {
+                       ret = bt_field_type_structure_get_field_by_index(
+                               field->type, &field_name, NULL, i);
+                       BT_ASSERT(ret == 0);
                        BT_LOGW("Cannot serialize structure field's field: "
                                "struct-field-addr=%p, field-addr=%p, "
                                "field-name=\"%s\", index=%" PRId64,
@@ -2569,12 +1824,13 @@ int bt_field_structure_serialize(struct bt_field *field,
                        break;
                }
        }
+
 end:
        return ret;
 }
 
 static
-int bt_field_variant_serialize(struct bt_field *field,
+int bt_field_variant_serialize_recursive(struct bt_field *field,
                struct bt_stream_pos *pos,
                enum bt_byte_order native_byte_order)
 {
@@ -2585,12 +1841,12 @@ int bt_field_variant_serialize(struct bt_field *field,
                "native-bo=%s", field, pos->offset,
                bt_byte_order_string(native_byte_order));
        BT_LOGV_STR("Serializing variant field's payload field.");
-       return bt_field_serialize(variant->payload, pos,
+       return bt_field_serialize_recursive(variant->payload, pos,
                native_byte_order);
 }
 
 static
-int bt_field_array_serialize(struct bt_field *field,
+int bt_field_array_serialize_recursive(struct bt_field *field,
                struct bt_stream_pos *pos,
                enum bt_byte_order native_byte_order)
 {
@@ -2610,7 +1866,7 @@ int bt_field_array_serialize(struct bt_field *field,
                BT_LOGV("Serializing array field's element field: "
                        "pos-offset=%" PRId64 ", field-addr=%p, index=%" PRId64,
                        pos->offset, elem_field, i);
-               ret = bt_field_serialize(elem_field, pos,
+               ret = bt_field_serialize_recursive(elem_field, pos,
                        native_byte_order);
                if (ret) {
                        BT_LOGW("Cannot serialize array field's element field: "
@@ -2619,12 +1875,13 @@ int bt_field_array_serialize(struct bt_field *field,
                        goto end;
                }
        }
+
 end:
        return ret;
 }
 
 static
-int bt_field_sequence_serialize(struct bt_field *field,
+int bt_field_sequence_serialize_recursive(struct bt_field *field,
                struct bt_stream_pos *pos,
                enum bt_byte_order native_byte_order)
 {
@@ -2644,7 +1901,7 @@ int bt_field_sequence_serialize(struct bt_field *field,
                BT_LOGV("Serializing sequence field's element field: "
                        "pos-offset=%" PRId64 ", field-addr=%p, index=%" PRId64,
                        pos->offset, elem_field, i);
-               ret = bt_field_serialize(elem_field, pos,
+               ret = bt_field_serialize_recursive(elem_field, pos,
                        native_byte_order);
                if (ret) {
                        BT_LOGW("Cannot serialize sequence field's element field: "
@@ -2653,13 +1910,13 @@ int bt_field_sequence_serialize(struct bt_field *field,
                        goto end;
                }
        }
+
 end:
        return ret;
 }
 
 static
-int bt_field_string_serialize(struct bt_field *field,
-               struct bt_stream_pos *pos,
+int bt_field_string_serialize(struct bt_field *field, struct bt_stream_pos *pos,
                enum bt_byte_order native_byte_order)
 {
        int64_t i;
@@ -2670,6 +1927,7 @@ int bt_field_string_serialize(struct bt_field *field,
                get_field_type(FIELD_TYPE_ALIAS_UINT8_T);
        struct bt_field *character;
 
+       BT_ASSERT_PRE_FIELD_IS_SET(field, "String field");
        BT_LOGV("Serializing string field: addr=%p, pos-offset=%" PRId64 ", "
                "native-bo=%s", field, pos->offset,
                bt_byte_order_string(native_byte_order));
@@ -2681,14 +1939,7 @@ int bt_field_string_serialize(struct bt_field *field,
                const uint64_t chr = (uint64_t) string->payload->str[i];
 
                ret = bt_field_unsigned_integer_set_value(character, chr);
-               if (ret) {
-                       BT_LOGW("Cannot set character field's value: "
-                               "pos-offset=%" PRId64 ", field-addr=%p, "
-                               "index=%" PRId64 ", char-int=%" PRIu64,
-                               pos->offset, character, i, chr);
-                       goto end;
-               }
-
+               BT_ASSERT(ret == 0);
                BT_LOGV("Serializing string field's character field: "
                        "pos-offset=%" PRId64 ", field-addr=%p, "
                        "index=%" PRId64 ", char-int=%" PRIu64,
@@ -2700,6 +1951,7 @@ int bt_field_string_serialize(struct bt_field *field,
                        goto end;
                }
        }
+
 end:
        bt_put(character);
        bt_put(character_type);
@@ -2707,8 +1959,7 @@ end:
 }
 
 static
-int bt_field_integer_copy(struct bt_field *src,
-               struct bt_field *dst)
+int bt_field_integer_copy(struct bt_field *src, struct bt_field *dst)
 {
        struct bt_field_integer *integer_src, *integer_dst;
 
@@ -2722,7 +1973,7 @@ int bt_field_integer_copy(struct bt_field *src,
 }
 
 static
-int bt_field_enumeration_copy(struct bt_field *src,
+int bt_field_enumeration_copy_recursive(struct bt_field *src,
                struct bt_field *dst)
 {
        int ret = 0;
@@ -2749,8 +2000,7 @@ end:
 }
 
 static
-int bt_field_floating_point_copy(
-               struct bt_field *src, struct bt_field *dst)
+int bt_field_floating_point_copy(struct bt_field *src, struct bt_field *dst)
 {
        struct bt_field_floating_point *float_src, *float_dst;
 
@@ -2766,7 +2016,7 @@ int bt_field_floating_point_copy(
 }
 
 static
-int bt_field_structure_copy(struct bt_field *src,
+int bt_field_structure_copy_recursive(struct bt_field *src,
                struct bt_field *dst)
 {
        int ret = 0;
@@ -2808,7 +2058,7 @@ end:
 }
 
 static
-int bt_field_variant_copy(struct bt_field *src,
+int bt_field_variant_copy_recursive(struct bt_field *src,
                struct bt_field *dst)
 {
        int ret = 0;
@@ -2845,7 +2095,7 @@ end:
 }
 
 static
-int bt_field_array_copy(struct bt_field *src,
+int bt_field_array_copy_recursive(struct bt_field *src,
                struct bt_field *dst)
 {
        int ret = 0;
@@ -2886,7 +2136,7 @@ end:
 }
 
 static
-int bt_field_sequence_copy(struct bt_field *src,
+int bt_field_sequence_copy_recursive(struct bt_field *src,
                struct bt_field *dst)
 {
        int ret = 0;
@@ -2926,7 +2176,7 @@ int bt_field_sequence_copy(struct bt_field *src,
                goto end;
        }
 
-       assert(sequence_dst->elements->len == sequence_src->elements->len);
+       BT_ASSERT(sequence_dst->elements->len == sequence_src->elements->len);
 
        for (i = 0; i < sequence_src->elements->len; i++) {
                struct bt_field *field =
@@ -2956,7 +2206,7 @@ end:
 }
 
 static
-int bt_field_string_copy(struct bt_field *src,
+int bt_field_string_copy_recursive(struct bt_field *src,
                struct bt_field *dst)
 {
        int ret = 0;
@@ -2987,7 +2237,7 @@ int increase_packet_size(struct bt_stream_pos *pos)
 {
        int ret;
 
-       assert(pos);
+       BT_ASSERT(pos);
        BT_LOGV("Increasing packet size: pos-offset=%" PRId64 ", "
                "cur-packet-size=%" PRIu64,
                pos->offset, pos->packet_size);
@@ -3022,7 +2272,7 @@ int increase_packet_size(struct bt_stream_pos *pos)
        BT_LOGV("Increased packet size: pos-offset=%" PRId64 ", "
                "new-packet-size=%" PRIu64,
                pos->offset, pos->packet_size);
-       assert(pos->packet_size % 8 == 0);
+       BT_ASSERT(pos->packet_size % 8 == 0);
 
 end:
        return ret;
@@ -3035,19 +2285,19 @@ void generic_field_freeze(struct bt_field *field)
 }
 
 static
-void bt_field_enumeration_freeze(struct bt_field *field)
+void bt_field_enumeration_freeze_recursive(struct bt_field *field)
 {
        struct bt_field_enumeration *enum_field =
                container_of(field, struct bt_field_enumeration, parent);
 
        BT_LOGD("Freezing enumeration field object: addr=%p", field);
        BT_LOGD("Freezing enumeration field object's contained payload field: payload-field-addr=%p", enum_field->payload);
-       bt_field_freeze(enum_field->payload);
+       bt_field_freeze_recursive(enum_field->payload);
        generic_field_freeze(field);
 }
 
 static
-void bt_field_structure_freeze(struct bt_field *field)
+void bt_field_structure_freeze_recursive(struct bt_field *field)
 {
        int64_t i;
        struct bt_field_structure *structure_field =
@@ -3061,28 +2311,28 @@ void bt_field_structure_freeze(struct bt_field *field)
 
                BT_LOGD("Freezing structure field's field: field-addr=%p, index=%" PRId64,
                        field, i);
-               bt_field_freeze(field);
+               bt_field_freeze_recursive(field);
        }
 
        generic_field_freeze(field);
 }
 
 static
-void bt_field_variant_freeze(struct bt_field *field)
+void bt_field_variant_freeze_recursive(struct bt_field *field)
 {
        struct bt_field_variant *variant_field =
                container_of(field, struct bt_field_variant, parent);
 
        BT_LOGD("Freezing variant field object: addr=%p", field);
        BT_LOGD("Freezing variant field object's tag field: tag-field-addr=%p", variant_field->tag);
-       bt_field_freeze(variant_field->tag);
+       bt_field_freeze_recursive(variant_field->tag);
        BT_LOGD("Freezing variant field object's payload field: payload-field-addr=%p", variant_field->payload);
-       bt_field_freeze(variant_field->payload);
+       bt_field_freeze_recursive(variant_field->payload);
        generic_field_freeze(field);
 }
 
 static
-void bt_field_array_freeze(struct bt_field *field)
+void bt_field_array_freeze_recursive(struct bt_field *field)
 {
        int64_t i;
        struct bt_field_array *array_field =
@@ -3097,14 +2347,14 @@ void bt_field_array_freeze(struct bt_field *field)
                BT_LOGD("Freezing array field object's element field: "
                        "element-field-addr=%p, index=%" PRId64,
                        elem_field, i);
-               bt_field_freeze(elem_field);
+               bt_field_freeze_recursive(elem_field);
        }
 
        generic_field_freeze(field);
 }
 
 static
-void bt_field_sequence_freeze(struct bt_field *field)
+void bt_field_sequence_freeze_recursive(struct bt_field *field)
 {
        int64_t i;
        struct bt_field_sequence *sequence_field =
@@ -3113,7 +2363,7 @@ void bt_field_sequence_freeze(struct bt_field *field)
        BT_LOGD("Freezing sequence field object: addr=%p", field);
        BT_LOGD("Freezing sequence field object's length field: length-field-addr=%p",
                sequence_field->length);
-       bt_field_freeze(sequence_field->length);
+       bt_field_freeze_recursive(sequence_field->length);
 
        for (i = 0; i < sequence_field->elements->len; i++) {
                struct bt_field *elem_field =
@@ -3122,14 +2372,14 @@ void bt_field_sequence_freeze(struct bt_field *field)
                BT_LOGD("Freezing sequence field object's element field: "
                        "element-field-addr=%p, index=%" PRId64,
                        elem_field, i);
-               bt_field_freeze(elem_field);
+               bt_field_freeze_recursive(elem_field);
        }
 
        generic_field_freeze(field);
 }
 
 BT_HIDDEN
-void bt_field_freeze(struct bt_field *field)
+void _bt_field_freeze_recursive(struct bt_field *field)
 {
        enum bt_field_type_id type_id;
 
@@ -3142,9 +2392,8 @@ void bt_field_freeze(struct bt_field *field)
        }
 
        BT_LOGD("Freezing field object: addr=%p", field);
+       BT_ASSERT(field_type_has_known_id(field->type));
        type_id = bt_field_get_type_id(field);
-       assert(type_id > BT_FIELD_TYPE_ID_UNKNOWN &&
-                       type_id < BT_FIELD_TYPE_ID_NR);
        field_freeze_funcs[type_id](field);
 end:
        return;
@@ -3157,40 +2406,34 @@ bt_bool bt_field_generic_is_set(struct bt_field *field)
 }
 
 static
-bt_bool bt_field_enumeration_is_set(struct bt_field *field)
+bt_bool bt_field_enumeration_is_set_recursive(struct bt_field *field)
 {
        bt_bool is_set = BT_FALSE;
        struct bt_field_enumeration *enumeration;
 
-       if (!field) {
-               goto end;
-       }
-
+       BT_ASSERT(field);
        enumeration = container_of(field, struct bt_field_enumeration,
                        parent);
        if (!enumeration->payload) {
                goto end;
        }
 
-       is_set = bt_field_is_set(enumeration->payload);
+       is_set = bt_field_is_set_recursive(enumeration->payload);
 end:
        return is_set;
 }
 
 static
-bt_bool bt_field_structure_is_set(struct bt_field *field)
+bt_bool bt_field_structure_is_set_recursive(struct bt_field *field)
 {
        bt_bool is_set = BT_FALSE;
        size_t i;
        struct bt_field_structure *structure;
 
-       if (!field) {
-               goto end;
-       }
-
+       BT_ASSERT(field);
        structure = container_of(field, struct bt_field_structure, parent);
        for (i = 0; i < structure->fields->len; i++) {
-               is_set = bt_field_is_set(
+               is_set = bt_field_is_set_recursive(
                        structure->fields->pdata[i]);
                if (!is_set) {
                        goto end;
@@ -3201,35 +2444,26 @@ end:
 }
 
 static
-bt_bool bt_field_variant_is_set(struct bt_field *field)
+bt_bool bt_field_variant_is_set_recursive(struct bt_field *field)
 {
-       bt_bool is_set = BT_FALSE;
        struct bt_field_variant *variant;
 
-       if (!field) {
-               goto end;
-       }
-
+       BT_ASSERT(field);
        variant = container_of(field, struct bt_field_variant, parent);
-       is_set = bt_field_is_set(variant->payload);
-end:
-       return is_set;
+       return bt_field_is_set_recursive(variant->payload);
 }
 
 static
-bt_bool bt_field_array_is_set(struct bt_field *field)
+bt_bool bt_field_array_is_set_recursive(struct bt_field *field)
 {
        size_t i;
        bt_bool is_set = BT_FALSE;
        struct bt_field_array *array;
 
-       if (!field) {
-               goto end;
-       }
-
+       BT_ASSERT(field);
        array = container_of(field, struct bt_field_array, parent);
        for (i = 0; i < array->elements->len; i++) {
-               is_set = bt_field_is_set(array->elements->pdata[i]);
+               is_set = bt_field_is_set_recursive(array->elements->pdata[i]);
                if (!is_set) {
                        goto end;
                }
@@ -3239,23 +2473,20 @@ end:
 }
 
 static
-bt_bool bt_field_sequence_is_set(struct bt_field *field)
+bt_bool bt_field_sequence_is_set_recursive(struct bt_field *field)
 {
        size_t i;
        bt_bool is_set = BT_FALSE;
        struct bt_field_sequence *sequence;
 
-       if (!field) {
-               goto end;
-       }
-
+       BT_ASSERT(field);
        sequence = container_of(field, struct bt_field_sequence, parent);
        if (!sequence->elements) {
                goto end;
        }
 
        for (i = 0; i < sequence->elements->len; i++) {
-               is_set = bt_field_is_set(sequence->elements->pdata[i]);
+               is_set = bt_field_is_set_recursive(sequence->elements->pdata[i]);
                if (!is_set) {
                        goto end;
                }
This page took 0.061646 seconds and 4 git commands to generate.