ir: rename ctf_type_id -> bt_ctf_type_id
[babeltrace.git] / formats / ctf / ir / event-fields.c
index 2fb783c31ccbd51dacd0ff027f365501c5a3acf2..91e7e9c4a7cc7ded48e031243b0a8ab1d5bc4b39 100644 (file)
 #include <babeltrace/ctf-writer/event-fields.h>
 #include <babeltrace/ctf-ir/event-fields-internal.h>
 #include <babeltrace/ctf-ir/event-types-internal.h>
-#include <babeltrace/ctf-ir/common-internal.h>
-#include <babeltrace/ctf-ir/ref.h>
+#include <babeltrace/object-internal.h>
+#include <babeltrace/ref.h>
 #include <babeltrace/compiler.h>
+#include <babeltrace/compat/fcntl.h>
 
 #define PACKET_LEN_INCREMENT   (getpagesize() * 8 * CHAR_BIT)
 
@@ -59,7 +60,7 @@ static
 struct bt_ctf_field *bt_ctf_field_string_create(struct bt_ctf_field_type *);
 
 static
-void bt_ctf_field_destroy(struct bt_ref *);
+void bt_ctf_field_destroy(struct bt_object *);
 static
 void bt_ctf_field_integer_destroy(struct bt_ctf_field *);
 static
@@ -154,93 +155,102 @@ int increase_packet_size(struct ctf_stream_pos *pos);
 static
 struct bt_ctf_field *(* const field_create_funcs[])(
                struct bt_ctf_field_type *) = {
-       [CTF_TYPE_INTEGER] = bt_ctf_field_integer_create,
-       [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_create,
-       [CTF_TYPE_FLOAT] =
+       [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_integer_create,
+       [BT_CTF_TYPE_ID_ENUM] = bt_ctf_field_enumeration_create,
+       [BT_CTF_TYPE_ID_FLOAT] =
                bt_ctf_field_floating_point_create,
-       [CTF_TYPE_STRUCT] = bt_ctf_field_structure_create,
-       [CTF_TYPE_VARIANT] = bt_ctf_field_variant_create,
-       [CTF_TYPE_ARRAY] = bt_ctf_field_array_create,
-       [CTF_TYPE_SEQUENCE] = bt_ctf_field_sequence_create,
-       [CTF_TYPE_STRING] = bt_ctf_field_string_create,
+       [BT_CTF_TYPE_ID_STRUCT] = bt_ctf_field_structure_create,
+       [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_variant_create,
+       [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_array_create,
+       [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_sequence_create,
+       [BT_CTF_TYPE_ID_STRING] = bt_ctf_field_string_create,
 };
 
 static
 void (* const field_destroy_funcs[])(struct bt_ctf_field *) = {
-       [CTF_TYPE_INTEGER] = bt_ctf_field_integer_destroy,
-       [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_destroy,
-       [CTF_TYPE_FLOAT] =
+       [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_integer_destroy,
+       [BT_CTF_TYPE_ID_ENUM] = bt_ctf_field_enumeration_destroy,
+       [BT_CTF_TYPE_ID_FLOAT] =
                bt_ctf_field_floating_point_destroy,
-       [CTF_TYPE_STRUCT] = bt_ctf_field_structure_destroy,
-       [CTF_TYPE_VARIANT] = bt_ctf_field_variant_destroy,
-       [CTF_TYPE_ARRAY] = bt_ctf_field_array_destroy,
-       [CTF_TYPE_SEQUENCE] = bt_ctf_field_sequence_destroy,
-       [CTF_TYPE_STRING] = bt_ctf_field_string_destroy,
+       [BT_CTF_TYPE_ID_STRUCT] = bt_ctf_field_structure_destroy,
+       [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_variant_destroy,
+       [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_array_destroy,
+       [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_sequence_destroy,
+       [BT_CTF_TYPE_ID_STRING] = bt_ctf_field_string_destroy,
 };
 
 static
 int (* const field_validate_funcs[])(struct bt_ctf_field *) = {
-       [CTF_TYPE_INTEGER] = bt_ctf_field_generic_validate,
-       [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_validate,
-       [CTF_TYPE_FLOAT] = bt_ctf_field_generic_validate,
-       [CTF_TYPE_STRUCT] = bt_ctf_field_structure_validate,
-       [CTF_TYPE_VARIANT] = bt_ctf_field_variant_validate,
-       [CTF_TYPE_ARRAY] = bt_ctf_field_array_validate,
-       [CTF_TYPE_SEQUENCE] = bt_ctf_field_sequence_validate,
-       [CTF_TYPE_STRING] = bt_ctf_field_generic_validate,
+       [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_generic_validate,
+       [BT_CTF_TYPE_ID_ENUM] = bt_ctf_field_enumeration_validate,
+       [BT_CTF_TYPE_ID_FLOAT] = bt_ctf_field_generic_validate,
+       [BT_CTF_TYPE_ID_STRUCT] = bt_ctf_field_structure_validate,
+       [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_variant_validate,
+       [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_array_validate,
+       [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_sequence_validate,
+       [BT_CTF_TYPE_ID_STRING] = bt_ctf_field_generic_validate,
 };
 
 static
 int (* const field_reset_funcs[])(struct bt_ctf_field *) = {
-       [CTF_TYPE_INTEGER] = bt_ctf_field_generic_reset,
-       [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_reset,
-       [CTF_TYPE_FLOAT] = bt_ctf_field_generic_reset,
-       [CTF_TYPE_STRUCT] = bt_ctf_field_structure_reset,
-       [CTF_TYPE_VARIANT] = bt_ctf_field_variant_reset,
-       [CTF_TYPE_ARRAY] = bt_ctf_field_array_reset,
-       [CTF_TYPE_SEQUENCE] = bt_ctf_field_sequence_reset,
-       [CTF_TYPE_STRING] = bt_ctf_field_string_reset,
+       [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_generic_reset,
+       [BT_CTF_TYPE_ID_ENUM] = bt_ctf_field_enumeration_reset,
+       [BT_CTF_TYPE_ID_FLOAT] = bt_ctf_field_generic_reset,
+       [BT_CTF_TYPE_ID_STRUCT] = bt_ctf_field_structure_reset,
+       [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_variant_reset,
+       [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_array_reset,
+       [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_sequence_reset,
+       [BT_CTF_TYPE_ID_STRING] = bt_ctf_field_string_reset,
 };
 
 static
 int (* const field_serialize_funcs[])(struct bt_ctf_field *,
                struct ctf_stream_pos *) = {
-       [CTF_TYPE_INTEGER] = bt_ctf_field_integer_serialize,
-       [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_serialize,
-       [CTF_TYPE_FLOAT] =
+       [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_integer_serialize,
+       [BT_CTF_TYPE_ID_ENUM] = bt_ctf_field_enumeration_serialize,
+       [BT_CTF_TYPE_ID_FLOAT] =
                bt_ctf_field_floating_point_serialize,
-       [CTF_TYPE_STRUCT] = bt_ctf_field_structure_serialize,
-       [CTF_TYPE_VARIANT] = bt_ctf_field_variant_serialize,
-       [CTF_TYPE_ARRAY] = bt_ctf_field_array_serialize,
-       [CTF_TYPE_SEQUENCE] = bt_ctf_field_sequence_serialize,
-       [CTF_TYPE_STRING] = bt_ctf_field_string_serialize,
+       [BT_CTF_TYPE_ID_STRUCT] = bt_ctf_field_structure_serialize,
+       [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_variant_serialize,
+       [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_array_serialize,
+       [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_sequence_serialize,
+       [BT_CTF_TYPE_ID_STRING] = bt_ctf_field_string_serialize,
 };
 
 static
 int (* const field_copy_funcs[])(struct bt_ctf_field *,
                struct bt_ctf_field *) = {
-       [CTF_TYPE_INTEGER] = bt_ctf_field_integer_copy,
-       [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_copy,
-       [CTF_TYPE_FLOAT] = bt_ctf_field_floating_point_copy,
-       [CTF_TYPE_STRUCT] = bt_ctf_field_structure_copy,
-       [CTF_TYPE_VARIANT] = bt_ctf_field_variant_copy,
-       [CTF_TYPE_ARRAY] = bt_ctf_field_array_copy,
-       [CTF_TYPE_SEQUENCE] = bt_ctf_field_sequence_copy,
-       [CTF_TYPE_STRING] = bt_ctf_field_string_copy,
+       [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_integer_copy,
+       [BT_CTF_TYPE_ID_ENUM] = bt_ctf_field_enumeration_copy,
+       [BT_CTF_TYPE_ID_FLOAT] = bt_ctf_field_floating_point_copy,
+       [BT_CTF_TYPE_ID_STRUCT] = bt_ctf_field_structure_copy,
+       [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_variant_copy,
+       [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_array_copy,
+       [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_sequence_copy,
+       [BT_CTF_TYPE_ID_STRING] = bt_ctf_field_string_copy,
 };
 
 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type)
 {
        struct bt_ctf_field *field = NULL;
-       enum ctf_type_id type_id;
+       enum bt_ctf_type_id type_id;
+       int ret;
 
        if (!type) {
                goto error;
        }
 
        type_id = bt_ctf_field_type_get_type_id(type);
-       if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES ||
-               bt_ctf_field_type_validate(type)) {
+       if (type_id <= BT_CTF_TYPE_ID_UNKNOWN ||
+                       type_id >= BT_CTF_NR_TYPE_IDS) {
+               goto error;
+       }
+
+       /* Field class MUST be valid */
+       ret = bt_ctf_field_type_validate(type);
+
+       if (ret) {
+               /* Invalid */
                goto error;
        }
 
@@ -251,8 +261,8 @@ struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type)
 
        /* The type's declaration can't change after this point */
        bt_ctf_field_type_freeze(type);
-       bt_ctf_field_type_get(type);
-       bt_ctf_base_init(field, bt_ctf_field_destroy);
+       bt_get(type);
+       bt_object_init(field, bt_ctf_field_destroy);
        field->type = type;
 error:
        return field;
@@ -260,12 +270,12 @@ error:
 
 void bt_ctf_field_get(struct bt_ctf_field *field)
 {
-       bt_ctf_get(field);
+       bt_get(field);
 }
 
 void bt_ctf_field_put(struct bt_ctf_field *field)
 {
-       bt_ctf_put(field);
+       bt_put(field);
 }
 
 struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field)
@@ -277,11 +287,64 @@ struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field)
        }
 
        ret = field->type;
-       bt_ctf_field_type_get(ret);
+       bt_get(ret);
 end:
        return ret;
 }
 
+enum bt_ctf_type_id bt_ctf_field_get_type_id(struct bt_ctf_field *field)
+{
+       enum bt_ctf_type_id ret = BT_CTF_TYPE_ID_UNKNOWN;
+
+       if (!field) {
+               goto end;
+       }
+
+       ret = bt_ctf_field_type_get_type_id(field->type);
+end:
+       return ret;
+}
+
+int bt_ctf_field_is_integer(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == BT_CTF_TYPE_ID_INTEGER;
+}
+
+int bt_ctf_field_is_floating_point(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == BT_CTF_TYPE_ID_FLOAT;
+}
+
+int bt_ctf_field_is_enumeration(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == BT_CTF_TYPE_ID_ENUM;
+}
+
+int bt_ctf_field_is_string(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == BT_CTF_TYPE_ID_STRING;
+}
+
+int bt_ctf_field_is_structure(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == BT_CTF_TYPE_ID_STRUCT;
+}
+
+int bt_ctf_field_is_array(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == BT_CTF_TYPE_ID_ARRAY;
+}
+
+int bt_ctf_field_is_sequence(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == BT_CTF_TYPE_ID_SEQUENCE;
+}
+
+int bt_ctf_field_is_variant(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == BT_CTF_TYPE_ID_VARIANT;
+}
+
 struct bt_ctf_field *bt_ctf_field_sequence_get_length(
                struct bt_ctf_field *field)
 {
@@ -293,13 +356,13 @@ struct bt_ctf_field *bt_ctf_field_sequence_get_length(
        }
 
        if (bt_ctf_field_type_get_type_id(field->type) !=
-               CTF_TYPE_SEQUENCE) {
+               BT_CTF_TYPE_ID_SEQUENCE) {
                goto end;
        }
 
        sequence = container_of(field, struct bt_ctf_field_sequence, parent);
        ret = sequence->length;
-       bt_ctf_field_get(ret);
+       bt_get(ret);
 end:
        return ret;
 }
@@ -318,7 +381,7 @@ int bt_ctf_field_sequence_set_length(struct bt_ctf_field *field,
                goto end;
        }
        if (bt_ctf_field_type_get_type_id(length_field->type) !=
-               CTF_TYPE_INTEGER) {
+               BT_CTF_TYPE_ID_INTEGER) {
                ret = -1;
                goto end;
        }
@@ -337,7 +400,7 @@ int bt_ctf_field_sequence_set_length(struct bt_ctf_field *field,
        sequence = container_of(field, struct bt_ctf_field_sequence, parent);
        if (sequence->elements) {
                g_ptr_array_free(sequence->elements, TRUE);
-               bt_ctf_field_put(sequence->length);
+               bt_put(sequence->length);
        }
 
        sequence->elements = g_ptr_array_sized_new((size_t)sequence_length);
@@ -347,9 +410,9 @@ int bt_ctf_field_sequence_set_length(struct bt_ctf_field *field,
        }
 
        g_ptr_array_set_free_func(sequence->elements,
-               (GDestroyNotify)bt_ctf_field_put);
-       g_ptr_array_set_size(sequence->elements, (size_t)sequence_length);
-       bt_ctf_field_get(length_field);
+               (GDestroyNotify) bt_put);
+       g_ptr_array_set_size(sequence->elements, (size_t) sequence_length);
+       bt_get(length_field);
        sequence->length = length_field;
 end:
        return ret;
@@ -366,7 +429,7 @@ struct bt_ctf_field *bt_ctf_field_structure_get_field(
 
        if (!field || !name ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_STRUCT) {
+                       BT_CTF_TYPE_ID_STRUCT) {
                goto error;
        }
 
@@ -392,10 +455,10 @@ struct bt_ctf_field *bt_ctf_field_structure_get_field(
 
        structure->fields->pdata[index] = new_field;
 end:
-       bt_ctf_field_get(new_field);
+       bt_get(new_field);
 error:
        if (field_type) {
-               bt_ctf_field_type_put(field_type);
+               bt_put(field_type);
        }
        return new_field;
 }
@@ -411,7 +474,8 @@ struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index(
        struct bt_ctf_field *ret_field = NULL;
 
        if (!field ||
-               bt_ctf_field_type_get_type_id(field->type) != CTF_TYPE_STRUCT) {
+               bt_ctf_field_type_get_type_id(field->type) !=
+               BT_CTF_TYPE_ID_STRUCT) {
                goto end;
        }
 
@@ -433,7 +497,7 @@ struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index(
 
        ret = bt_ctf_field_type_structure_get_field(structure_type,
                &field_name, &field_type, index);
-       bt_ctf_field_type_put(structure_type);
+       bt_put(structure_type);
        if (ret) {
                goto error;
        }
@@ -445,11 +509,9 @@ struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index(
 
        structure->fields->pdata[index] = ret_field;
 end:
-       bt_ctf_field_get(ret_field);
+       bt_get(ret_field);
 error:
-       if (field_type) {
-               bt_ctf_field_type_put(field_type);
-       }
+       bt_put(field_type);
        return ret_field;
 }
 
@@ -465,7 +527,7 @@ int bt_ctf_field_structure_set_field(struct bt_ctf_field *field,
 
        if (!field || !name || !value ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_STRUCT) {
+                       BT_CTF_TYPE_ID_STRUCT) {
                ret = -1;
                goto end;
        }
@@ -475,7 +537,8 @@ int bt_ctf_field_structure_set_field(struct bt_ctf_field *field,
        expected_field_type =
                bt_ctf_field_type_structure_get_field_type_by_name(field->type,
                name);
-       if (expected_field_type != value->type) {
+
+       if (bt_ctf_field_type_compare(expected_field_type, value->type)) {
                ret = -1;
                goto end;
        }
@@ -486,14 +549,14 @@ int bt_ctf_field_structure_set_field(struct bt_ctf_field *field,
        }
 
        if (structure->fields->pdata[index]) {
-               bt_ctf_field_put(structure->fields->pdata[index]);
+               bt_put(structure->fields->pdata[index]);
        }
 
        structure->fields->pdata[index] = value;
-       bt_ctf_field_get(value);
+       bt_get(value);
 end:
        if (expected_field_type) {
-               bt_ctf_field_type_put(expected_field_type);
+               bt_put(expected_field_type);
        }
        return ret;
 }
@@ -506,7 +569,7 @@ struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *field,
        struct bt_ctf_field_array *array;
 
        if (!field || bt_ctf_field_type_get_type_id(field->type) !=
-               CTF_TYPE_ARRAY) {
+               BT_CTF_TYPE_ID_ARRAY) {
                goto end;
        }
 
@@ -525,10 +588,10 @@ struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *field,
        array->elements->pdata[(size_t)index] = new_field;
 end:
        if (field_type) {
-               bt_ctf_field_type_put(field_type);
+               bt_put(field_type);
        }
        if (new_field) {
-               bt_ctf_field_get(new_field);
+               bt_get(new_field);
        }
        return new_field;
 }
@@ -541,7 +604,7 @@ struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *field,
        struct bt_ctf_field_sequence *sequence;
 
        if (!field || bt_ctf_field_type_get_type_id(field->type) !=
-               CTF_TYPE_SEQUENCE) {
+               BT_CTF_TYPE_ID_SEQUENCE) {
                goto end;
        }
 
@@ -551,19 +614,19 @@ struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *field,
        }
 
        field_type = bt_ctf_field_type_sequence_get_element_type(field->type);
-       if (sequence->elements->pdata[(size_t)index]) {
-               new_field = sequence->elements->pdata[(size_t)index];
+       if (sequence->elements->pdata[(size_t) index]) {
+               new_field = sequence->elements->pdata[(size_t) index];
                goto end;
        }
 
        new_field = bt_ctf_field_create(field_type);
-       sequence->elements->pdata[(size_t)index] = new_field;
+       sequence->elements->pdata[(size_t) index] = new_field;
 end:
        if (field_type) {
-               bt_ctf_field_type_put(field_type);
+               bt_put(field_type);
        }
        if (new_field) {
-               bt_ctf_field_get(new_field);
+               bt_get(new_field);
        }
        return new_field;
 }
@@ -581,9 +644,9 @@ struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *field,
 
        if (!field || !tag_field ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_VARIANT ||
+                       BT_CTF_TYPE_ID_VARIANT ||
                bt_ctf_field_type_get_type_id(tag_field->type) !=
-                       CTF_TYPE_ENUM) {
+                       BT_CTF_TYPE_ID_ENUM) {
                goto end;
        }
 
@@ -616,14 +679,15 @@ struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *field,
 
                cur_tag_container =
                        bt_ctf_field_enumeration_get_container(variant->tag);
+               assert(cur_tag_container);
                cur_tag_enum_integer = container_of(cur_tag_container,
                        struct bt_ctf_field_integer, parent);
-               bt_ctf_field_put(cur_tag_container);
+               bt_put(cur_tag_container);
                cur_tag_value = cur_tag_enum_integer->definition.value._signed;
 
                if (cur_tag_value == tag_enum_value) {
                        new_field = variant->payload;
-                       bt_ctf_field_get(new_field);
+                       bt_get(new_field);
                        goto end;
                }
        }
@@ -639,14 +703,14 @@ struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *field,
                goto end;
        }
 
-       bt_ctf_field_put(variant->tag);
-       bt_ctf_field_put(variant->payload);
-       bt_ctf_field_get(new_field);
-       bt_ctf_field_get(tag_field);
+       bt_put(variant->tag);
+       bt_put(variant->payload);
+       bt_get(new_field);
+       bt_get(tag_field);
        variant->tag = tag_field;
        variant->payload = new_field;
 end:
-       bt_ctf_field_put(tag_enum);
+       bt_put(tag_enum);
        return new_field;
 }
 
@@ -658,7 +722,7 @@ struct bt_ctf_field *bt_ctf_field_variant_get_current_field(
 
        if (!variant_field ||
                bt_ctf_field_type_get_type_id(variant_field->type) !=
-                       CTF_TYPE_VARIANT) {
+                       BT_CTF_TYPE_ID_VARIANT) {
                goto end;
        }
 
@@ -667,7 +731,7 @@ struct bt_ctf_field *bt_ctf_field_variant_get_current_field(
 
        if (variant->payload) {
                current_field = variant->payload;
-               bt_ctf_field_get(current_field);
+               bt_get(current_field);
                goto end;
        }
 
@@ -682,7 +746,7 @@ struct bt_ctf_field *bt_ctf_field_enumeration_get_container(
        struct bt_ctf_field_enumeration *enumeration;
 
        if (!field || bt_ctf_field_type_get_type_id(field->type) !=
-               CTF_TYPE_ENUM) {
+               BT_CTF_TYPE_ID_ENUM) {
                goto end;
        }
 
@@ -697,7 +761,7 @@ struct bt_ctf_field *bt_ctf_field_enumeration_get_container(
        }
 
        container = enumeration->payload;
-       bt_ctf_field_get(container);
+       bt_get(container);
 end:
        return container;
 }
@@ -750,9 +814,9 @@ const char *bt_ctf_field_enumeration_get_mapping_name(
        }
 
 error_put_container_type:
-       bt_ctf_field_type_put(container_type);
+       bt_put(container_type);
 error_put_container:
-       bt_ctf_field_put(container);
+       bt_put(container);
 end:
        return name;
 }
@@ -766,7 +830,7 @@ int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *field,
 
        if (!field || !value || !field->payload_set ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_INTEGER) {
+                       BT_CTF_TYPE_ID_INTEGER) {
                ret = -1;
                goto end;
        }
@@ -796,7 +860,7 @@ int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *field,
 
        if (!field ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_INTEGER) {
+                       BT_CTF_TYPE_ID_INTEGER) {
                ret = -1;
                goto end;
        }
@@ -832,7 +896,7 @@ int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *field,
 
        if (!field || !value || !field->payload_set ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_INTEGER) {
+                       BT_CTF_TYPE_ID_INTEGER) {
                ret = -1;
                goto end;
        }
@@ -862,7 +926,7 @@ int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *field,
 
        if (!field ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_INTEGER) {
+                       BT_CTF_TYPE_ID_INTEGER) {
                ret = -1;
                goto end;
        }
@@ -896,7 +960,7 @@ int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *field,
 
        if (!field || !value || !field->payload_set ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_FLOAT) {
+                       BT_CTF_TYPE_ID_FLOAT) {
                ret = -1;
                goto end;
        }
@@ -916,7 +980,7 @@ int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *field,
 
        if (!field ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_FLOAT) {
+                       BT_CTF_TYPE_ID_FLOAT) {
                ret = -1;
                goto end;
        }
@@ -935,7 +999,7 @@ const char *bt_ctf_field_string_get_value(struct bt_ctf_field *field)
 
        if (!field || !field->payload_set ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_STRING) {
+                       BT_CTF_TYPE_ID_STRING) {
                goto end;
        }
 
@@ -954,7 +1018,7 @@ int bt_ctf_field_string_set_value(struct bt_ctf_field *field,
 
        if (!field || !value ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_STRING) {
+                       BT_CTF_TYPE_ID_STRING) {
                ret = -1;
                goto end;
        }
@@ -979,7 +1043,7 @@ int bt_ctf_field_string_append(struct bt_ctf_field *field,
 
        if (!field || !value ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_STRING) {
+                       BT_CTF_TYPE_ID_STRING) {
                ret = -1;
                goto end;
        }
@@ -1008,7 +1072,7 @@ int bt_ctf_field_string_append_len(struct bt_ctf_field *field,
 
        if (!field || !value ||
                bt_ctf_field_type_get_type_id(field->type) !=
-                       CTF_TYPE_STRING) {
+                       BT_CTF_TYPE_ID_STRING) {
                ret = -1;
                goto end;
        }
@@ -1041,7 +1105,7 @@ BT_HIDDEN
 int bt_ctf_field_validate(struct bt_ctf_field *field)
 {
        int ret = 0;
-       enum ctf_type_id type_id;
+       enum bt_ctf_type_id type_id;
 
        if (!field) {
                ret = -1;
@@ -1049,7 +1113,7 @@ int bt_ctf_field_validate(struct bt_ctf_field *field)
        }
 
        type_id = bt_ctf_field_type_get_type_id(field->type);
-       if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES) {
+       if (type_id <= BT_CTF_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
                ret = -1;
                goto end;
        }
@@ -1063,7 +1127,7 @@ BT_HIDDEN
 int bt_ctf_field_reset(struct bt_ctf_field *field)
 {
        int ret = 0;
-       enum ctf_type_id type_id;
+       enum bt_ctf_type_id type_id;
 
        if (!field) {
                ret = -1;
@@ -1071,7 +1135,7 @@ int bt_ctf_field_reset(struct bt_ctf_field *field)
        }
 
        type_id = bt_ctf_field_type_get_type_id(field->type);
-       if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES) {
+       if (type_id <= BT_CTF_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
                ret = -1;
                goto end;
        }
@@ -1086,7 +1150,7 @@ int bt_ctf_field_serialize(struct bt_ctf_field *field,
                struct ctf_stream_pos *pos)
 {
        int ret = 0;
-       enum ctf_type_id type_id;
+       enum bt_ctf_type_id type_id;
 
        if (!field || !pos) {
                ret = -1;
@@ -1094,7 +1158,7 @@ int bt_ctf_field_serialize(struct bt_ctf_field *field,
        }
 
        type_id = bt_ctf_field_type_get_type_id(field->type);
-       if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES) {
+       if (type_id <= BT_CTF_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
                ret = -1;
                goto end;
        }
@@ -1108,14 +1172,14 @@ struct bt_ctf_field *bt_ctf_field_copy(struct bt_ctf_field *field)
 {
        int ret;
        struct bt_ctf_field *copy = NULL;
-       enum ctf_type_id type_id;
+       enum bt_ctf_type_id type_id;
 
        if (!field) {
                goto end;
        }
 
        type_id = bt_ctf_field_type_get_type_id(field->type);
-       if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES) {
+       if (type_id <= BT_CTF_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
                goto end;
        }
 
@@ -1127,7 +1191,7 @@ struct bt_ctf_field *bt_ctf_field_copy(struct bt_ctf_field *field)
        copy->payload_set = field->payload_set;
        ret = field_copy_funcs[type_id](field, copy);
        if (ret) {
-               bt_ctf_field_put(copy);
+               bt_put(copy);
                copy = NULL;
        }
 end:
@@ -1206,7 +1270,7 @@ struct bt_ctf_field *bt_ctf_field_structure_create(
                struct bt_ctf_field_structure, 1);
        struct bt_ctf_field *field = NULL;
 
-       if (!structure || !structure_type->fields->len) {
+       if (!structure) {
                goto end;
        }
 
@@ -1273,30 +1337,22 @@ struct bt_ctf_field *bt_ctf_field_string_create(struct bt_ctf_field_type *type)
 }
 
 static
-void bt_ctf_field_destroy(struct bt_ref *ref)
+void bt_ctf_field_destroy(struct bt_object *obj)
 {
        struct bt_ctf_field *field;
-       struct bt_ctf_base *base;
        struct bt_ctf_field_type *type;
-       enum ctf_type_id type_id;
-
-       if (!ref) {
-               return;
-       }
+       enum bt_ctf_type_id type_id;
 
-       base = container_of(ref, struct bt_ctf_base, ref_count);
-       field = container_of(base, struct bt_ctf_field, base);
+       field = container_of(obj, struct bt_ctf_field, base);
        type = field->type;
        type_id = bt_ctf_field_type_get_type_id(type);
-       if (type_id <= CTF_TYPE_UNKNOWN ||
-               type_id >= NR_CTF_TYPES) {
+       if (type_id <= BT_CTF_TYPE_ID_UNKNOWN ||
+               type_id >= BT_CTF_NR_TYPE_IDS) {
                return;
        }
 
        field_destroy_funcs[type_id](field);
-       if (type) {
-               bt_ctf_field_type_put(type);
-       }
+       bt_put(type);
 }
 
 static
@@ -1323,7 +1379,7 @@ void bt_ctf_field_enumeration_destroy(struct bt_ctf_field *field)
 
        enumeration = container_of(field, struct bt_ctf_field_enumeration,
                parent);
-       bt_ctf_field_put(enumeration->payload);
+       bt_put(enumeration->payload);
        g_free(enumeration);
 }
 
@@ -1365,8 +1421,8 @@ void bt_ctf_field_variant_destroy(struct bt_ctf_field *field)
        }
 
        variant = container_of(field, struct bt_ctf_field_variant, parent);
-       bt_ctf_field_put(variant->tag);
-       bt_ctf_field_put(variant->payload);
+       bt_put(variant->tag);
+       bt_put(variant->payload);
        g_free(variant);
 }
 
@@ -1397,7 +1453,7 @@ void bt_ctf_field_sequence_destroy(struct bt_ctf_field *field)
        if (sequence->elements) {
                g_ptr_array_free(sequence->elements, TRUE);
        }
-       bt_ctf_field_put(sequence->length);
+       bt_put(sequence->length);
        g_free(sequence);
 }
 
@@ -1881,8 +1937,8 @@ int bt_ctf_field_string_serialize(struct bt_ctf_field *field,
                }
        }
 end:
-       bt_ctf_field_put(character);
-       bt_ctf_field_type_put(character_type);
+       bt_put(character);
+       bt_put(character_type);
        return ret;
 }
 
@@ -2057,7 +2113,7 @@ int bt_ctf_field_sequence_copy(struct bt_ctf_field *src,
 
        /* copy source length */
        dst_length = bt_ctf_field_copy(src_length);
-       bt_ctf_field_put(src_length);
+       bt_put(src_length);
 
        if (!dst_length) {
                ret = -1;
@@ -2066,7 +2122,7 @@ int bt_ctf_field_sequence_copy(struct bt_ctf_field *src,
 
        /* this will initialize the destination sequence's internal array */
        ret = bt_ctf_field_sequence_set_length(dst, dst_length);
-       bt_ctf_field_put(dst_length);
+       bt_put(dst_length);
 
        if (ret) {
                goto end;
@@ -2127,9 +2183,13 @@ int increase_packet_size(struct ctf_stream_pos *pos)
        }
 
        pos->packet_size += PACKET_LEN_INCREMENT;
-       ret = posix_fallocate(pos->fd, pos->mmap_offset,
-               pos->packet_size / CHAR_BIT);
+       do {
+               ret = bt_posix_fallocate(pos->fd, pos->mmap_offset,
+                       pos->packet_size / CHAR_BIT);
+       } while (ret == EINTR);
        if (ret) {
+               errno = EINTR;
+               ret = -1;
                goto end;
        }
 
This page took 0.037668 seconds and 4 git commands to generate.