#include <babeltrace/ctf-writer/writer-internal.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/ref.h>
-#include <babeltrace/compiler.h>
-#include <babeltrace/endian.h>
+#include <babeltrace/compiler-internal.h>
+#include <babeltrace/endian-internal.h>
#include <float.h>
#include <inttypes.h>
#include <stdlib.h>
static
void (* const type_destroy_funcs[])(struct bt_ctf_field_type *) = {
- [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_destroy,
- [BT_CTF_TYPE_ID_ENUM] =
+ [BT_CTF_FIELD_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_destroy,
+ [BT_CTF_FIELD_TYPE_ID_ENUM] =
bt_ctf_field_type_enumeration_destroy,
- [BT_CTF_TYPE_ID_FLOAT] =
+ [BT_CTF_FIELD_TYPE_ID_FLOAT] =
bt_ctf_field_type_floating_point_destroy,
- [BT_CTF_TYPE_ID_STRUCT] = bt_ctf_field_type_structure_destroy,
- [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_destroy,
- [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_type_array_destroy,
- [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_destroy,
- [BT_CTF_TYPE_ID_STRING] = bt_ctf_field_type_string_destroy,
+ [BT_CTF_FIELD_TYPE_ID_STRUCT] = bt_ctf_field_type_structure_destroy,
+ [BT_CTF_FIELD_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_destroy,
+ [BT_CTF_FIELD_TYPE_ID_ARRAY] = bt_ctf_field_type_array_destroy,
+ [BT_CTF_FIELD_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_destroy,
+ [BT_CTF_FIELD_TYPE_ID_STRING] = bt_ctf_field_type_string_destroy,
};
static
static
type_freeze_func const type_freeze_funcs[] = {
- [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_freeze,
- [BT_CTF_TYPE_ID_ENUM] = bt_ctf_field_type_enumeration_freeze,
- [BT_CTF_TYPE_ID_FLOAT] = generic_field_type_freeze,
- [BT_CTF_TYPE_ID_STRUCT] = bt_ctf_field_type_structure_freeze,
- [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_freeze,
- [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_type_array_freeze,
- [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_freeze,
- [BT_CTF_TYPE_ID_STRING] = generic_field_type_freeze,
+ [BT_CTF_FIELD_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_freeze,
+ [BT_CTF_FIELD_TYPE_ID_ENUM] = bt_ctf_field_type_enumeration_freeze,
+ [BT_CTF_FIELD_TYPE_ID_FLOAT] = generic_field_type_freeze,
+ [BT_CTF_FIELD_TYPE_ID_STRUCT] = bt_ctf_field_type_structure_freeze,
+ [BT_CTF_FIELD_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_freeze,
+ [BT_CTF_FIELD_TYPE_ID_ARRAY] = bt_ctf_field_type_array_freeze,
+ [BT_CTF_FIELD_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_freeze,
+ [BT_CTF_FIELD_TYPE_ID_STRING] = generic_field_type_freeze,
};
static
static
type_serialize_func const type_serialize_funcs[] = {
- [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_serialize,
- [BT_CTF_TYPE_ID_ENUM] =
+ [BT_CTF_FIELD_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_serialize,
+ [BT_CTF_FIELD_TYPE_ID_ENUM] =
bt_ctf_field_type_enumeration_serialize,
- [BT_CTF_TYPE_ID_FLOAT] =
+ [BT_CTF_FIELD_TYPE_ID_FLOAT] =
bt_ctf_field_type_floating_point_serialize,
- [BT_CTF_TYPE_ID_STRUCT] =
+ [BT_CTF_FIELD_TYPE_ID_STRUCT] =
bt_ctf_field_type_structure_serialize,
- [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_serialize,
- [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_type_array_serialize,
- [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_serialize,
- [BT_CTF_TYPE_ID_STRING] = bt_ctf_field_type_string_serialize,
+ [BT_CTF_FIELD_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_serialize,
+ [BT_CTF_FIELD_TYPE_ID_ARRAY] = bt_ctf_field_type_array_serialize,
+ [BT_CTF_FIELD_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_serialize,
+ [BT_CTF_FIELD_TYPE_ID_STRING] = bt_ctf_field_type_string_serialize,
};
static
static
void (* const set_byte_order_funcs[])(struct bt_ctf_field_type *,
enum bt_ctf_byte_order) = {
- [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_set_byte_order,
- [BT_CTF_TYPE_ID_ENUM] =
+ [BT_CTF_FIELD_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_set_byte_order,
+ [BT_CTF_FIELD_TYPE_ID_ENUM] =
bt_ctf_field_type_enumeration_set_byte_order,
- [BT_CTF_TYPE_ID_FLOAT] =
+ [BT_CTF_FIELD_TYPE_ID_FLOAT] =
bt_ctf_field_type_floating_point_set_byte_order,
- [BT_CTF_TYPE_ID_STRUCT] =
+ [BT_CTF_FIELD_TYPE_ID_STRUCT] =
bt_ctf_field_type_structure_set_byte_order,
- [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_set_byte_order,
- [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_type_array_set_byte_order,
- [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_set_byte_order,
- [BT_CTF_TYPE_ID_STRING] = NULL,
+ [BT_CTF_FIELD_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_set_byte_order,
+ [BT_CTF_FIELD_TYPE_ID_ARRAY] = bt_ctf_field_type_array_set_byte_order,
+ [BT_CTF_FIELD_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_set_byte_order,
+ [BT_CTF_FIELD_TYPE_ID_STRING] = NULL,
};
static
static
struct bt_ctf_field_type *(* const type_copy_funcs[])(
struct bt_ctf_field_type *) = {
- [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_copy,
- [BT_CTF_TYPE_ID_ENUM] = bt_ctf_field_type_enumeration_copy,
- [BT_CTF_TYPE_ID_FLOAT] = bt_ctf_field_type_floating_point_copy,
- [BT_CTF_TYPE_ID_STRUCT] = bt_ctf_field_type_structure_copy,
- [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_copy,
- [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_type_array_copy,
- [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_copy,
- [BT_CTF_TYPE_ID_STRING] = bt_ctf_field_type_string_copy,
+ [BT_CTF_FIELD_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_copy,
+ [BT_CTF_FIELD_TYPE_ID_ENUM] = bt_ctf_field_type_enumeration_copy,
+ [BT_CTF_FIELD_TYPE_ID_FLOAT] = bt_ctf_field_type_floating_point_copy,
+ [BT_CTF_FIELD_TYPE_ID_STRUCT] = bt_ctf_field_type_structure_copy,
+ [BT_CTF_FIELD_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_copy,
+ [BT_CTF_FIELD_TYPE_ID_ARRAY] = bt_ctf_field_type_array_copy,
+ [BT_CTF_FIELD_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_copy,
+ [BT_CTF_FIELD_TYPE_ID_STRING] = bt_ctf_field_type_string_copy,
};
static
static
int (* const type_compare_funcs[])(struct bt_ctf_field_type *,
struct bt_ctf_field_type *) = {
- [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_compare,
- [BT_CTF_TYPE_ID_ENUM] = bt_ctf_field_type_enumeration_compare,
- [BT_CTF_TYPE_ID_FLOAT] = bt_ctf_field_type_floating_point_compare,
- [BT_CTF_TYPE_ID_STRUCT] = bt_ctf_field_type_structure_compare,
- [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_compare,
- [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_type_array_compare,
- [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_compare,
- [BT_CTF_TYPE_ID_STRING] = bt_ctf_field_type_string_compare,
+ [BT_CTF_FIELD_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_compare,
+ [BT_CTF_FIELD_TYPE_ID_ENUM] = bt_ctf_field_type_enumeration_compare,
+ [BT_CTF_FIELD_TYPE_ID_FLOAT] = bt_ctf_field_type_floating_point_compare,
+ [BT_CTF_FIELD_TYPE_ID_STRUCT] = bt_ctf_field_type_structure_compare,
+ [BT_CTF_FIELD_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_compare,
+ [BT_CTF_FIELD_TYPE_ID_ARRAY] = bt_ctf_field_type_array_compare,
+ [BT_CTF_FIELD_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_compare,
+ [BT_CTF_FIELD_TYPE_ID_STRING] = bt_ctf_field_type_string_compare,
};
static
static
int (* const type_validate_funcs[])(struct bt_ctf_field_type *) = {
- [BT_CTF_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_validate,
- [BT_CTF_TYPE_ID_FLOAT] = NULL,
- [BT_CTF_TYPE_ID_STRING] = NULL,
- [BT_CTF_TYPE_ID_ENUM] = bt_ctf_field_type_enumeration_validate,
- [BT_CTF_TYPE_ID_STRUCT] = bt_ctf_field_type_structure_validate,
- [BT_CTF_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_validate,
- [BT_CTF_TYPE_ID_ARRAY] = bt_ctf_field_type_array_validate,
- [BT_CTF_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_validate,
+ [BT_CTF_FIELD_TYPE_ID_INTEGER] = bt_ctf_field_type_integer_validate,
+ [BT_CTF_FIELD_TYPE_ID_FLOAT] = NULL,
+ [BT_CTF_FIELD_TYPE_ID_STRING] = NULL,
+ [BT_CTF_FIELD_TYPE_ID_ENUM] = bt_ctf_field_type_enumeration_validate,
+ [BT_CTF_FIELD_TYPE_ID_STRUCT] = bt_ctf_field_type_structure_validate,
+ [BT_CTF_FIELD_TYPE_ID_VARIANT] = bt_ctf_field_type_variant_validate,
+ [BT_CTF_FIELD_TYPE_ID_ARRAY] = bt_ctf_field_type_array_validate,
+ [BT_CTF_FIELD_TYPE_ID_SEQUENCE] = bt_ctf_field_type_sequence_validate,
};
static
static
void bt_ctf_field_type_init(struct bt_ctf_field_type *type, bool init_bo)
{
- assert(type && (type->id > BT_CTF_TYPE_ID_UNKNOWN) &&
+ assert(type && (type->id > BT_CTF_FIELD_TYPE_ID_UNKNOWN) &&
(type->id < BT_CTF_NR_TYPE_IDS));
bt_object_init(type, bt_ctf_field_type_destroy);
void bt_ctf_field_type_destroy(struct bt_object *obj)
{
struct bt_ctf_field_type *type;
- enum bt_ctf_type_id type_id;
+ enum bt_ctf_field_type_id type_id;
type = container_of(obj, struct bt_ctf_field_type, base);
type_id = type->id;
- if (type_id <= BT_CTF_TYPE_ID_UNKNOWN ||
+ if (type_id <= BT_CTF_FIELD_TYPE_ID_UNKNOWN ||
type_id >= BT_CTF_NR_TYPE_IDS) {
return;
}
{
int ret = 0;
struct bt_ctf_field_type *child_type = NULL;
- int field_count = bt_ctf_field_type_structure_get_field_count(type);
- int i;
+ int64_t field_count = bt_ctf_field_type_structure_get_field_count(type);
+ int64_t i;
if (field_count < 0) {
ret = -1;
}
for (i = 0; i < field_count; ++i) {
- ret = bt_ctf_field_type_structure_get_field(type,
+ ret = bt_ctf_field_type_structure_get_field_by_index(type,
NULL, &child_type, i);
if (ret) {
goto end;
int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type *type)
{
int ret = 0;
- int field_count;
+ int64_t field_count;
struct bt_ctf_field_type *child_type = NULL;
struct bt_ctf_field_type_variant *variant =
container_of(type, struct bt_ctf_field_type_variant,
parent);
- int i;
- int tag_mappings_count;
+ int64_t i;
+ int64_t tag_mappings_count;
if (variant->tag_name->len == 0 || !variant->tag) {
ret = -1;
bt_ctf_field_type_enumeration_get_mapping_count(
(struct bt_ctf_field_type *) variant->tag);
- if (tag_mappings_count != variant->fields->len) {
- ret = -1;
- goto end;
- }
-
+ /*
+ * Validate that each mapping found in the tag has a name which
+ * is also the name of a field in this variant field type.
+ *
+ * The opposite is accepted: variant FT fields which cannot be
+ * selected because the variant FT tag has no mapping named as
+ * such. This scenario, while not ideal, cannot cause any error.
+ */
for (i = 0; i < tag_mappings_count; ++i) {
const char *label;
struct bt_ctf_field_type *ft;
}
for (i = 0; i < field_count; ++i) {
- ret = bt_ctf_field_type_variant_get_field(type,
+ ret = bt_ctf_field_type_variant_get_field_by_index(type,
NULL, &child_type, i);
if (ret) {
goto end;
int bt_ctf_field_type_validate(struct bt_ctf_field_type *type)
{
int ret = 0;
- enum bt_ctf_type_id id = bt_ctf_field_type_get_type_id(type);
+ enum bt_ctf_field_type_id id = bt_ctf_field_type_get_type_id(type);
if (!type) {
ret = -1;
return NULL;
}
- integer->parent.id = BT_CTF_TYPE_ID_INTEGER;
+ integer->parent.id = BT_CTF_FIELD_TYPE_ID_INTEGER;
integer->size = size;
integer->base = BT_CTF_INTEGER_BASE_DECIMAL;
integer->encoding = BT_CTF_STRING_ENCODING_NONE;
int ret = 0;
struct bt_ctf_field_type_integer *integer;
- if (!type || type->id != BT_CTF_TYPE_ID_INTEGER) {
+ if (!type || type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
ret = -1;
goto end;
}
int ret = 0;
struct bt_ctf_field_type_integer *integer;
- if (!type || type->id != BT_CTF_TYPE_ID_INTEGER) {
+ if (!type || type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
ret = -1;
goto end;
}
struct bt_ctf_field_type_integer *integer;
if (!type || type->frozen ||
- type->id != BT_CTF_TYPE_ID_INTEGER) {
+ type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
ret = -1;
goto end;
}
struct bt_ctf_field_type_integer *integer;
if (!type || type->frozen ||
- type->id != BT_CTF_TYPE_ID_INTEGER ||
+ type->id != BT_CTF_FIELD_TYPE_ID_INTEGER ||
!size || size > 64) {
ret = -1;
goto end;
enum bt_ctf_integer_base ret = BT_CTF_INTEGER_BASE_UNKNOWN;
struct bt_ctf_field_type_integer *integer;
- if (!type || type->id != BT_CTF_TYPE_ID_INTEGER) {
+ if (!type || type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
goto end;
}
int ret = 0;
if (!type || type->frozen ||
- type->id != BT_CTF_TYPE_ID_INTEGER) {
+ type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
ret = -1;
goto end;
}
enum bt_ctf_string_encoding ret = BT_CTF_STRING_ENCODING_UNKNOWN;
struct bt_ctf_field_type_integer *integer;
- if (!type || type->id != BT_CTF_TYPE_ID_INTEGER) {
+ if (!type || type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
goto end;
}
struct bt_ctf_field_type_integer *integer;
if (!type || type->frozen ||
- (type->id != BT_CTF_TYPE_ID_INTEGER) ||
+ (type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) ||
(encoding < BT_CTF_STRING_ENCODING_NONE) ||
(encoding >= BT_CTF_STRING_ENCODING_UNKNOWN)) {
ret = -1;
struct bt_ctf_field_type_enumeration *enumeration_type;
struct bt_ctf_field_type_enumeration_mapping_iterator *iter = NULL;
- if (!type || (type->id != BT_CTF_TYPE_ID_ENUM)) {
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_ENUM)) {
goto end;
}
int bt_ctf_field_type_enumeration_get_mapping_signed(
struct bt_ctf_field_type *enum_field_type,
- int index,
- const char **mapping_name, int64_t *range_begin,
+ uint64_t index, const char **mapping_name, int64_t *range_begin,
int64_t *range_end)
{
int ret = 0;
struct enumeration_mapping *mapping;
- if (!enum_field_type || index < 0) {
+ if (!enum_field_type) {
ret = -1;
goto end;
}
int bt_ctf_field_type_enumeration_get_mapping_unsigned(
struct bt_ctf_field_type *enum_field_type,
- int index,
+ uint64_t index,
const char **mapping_name, uint64_t *range_begin,
uint64_t *range_end)
{
int ret = 0;
struct enumeration_mapping *mapping;
- if (!enum_field_type || index < 0) {
+ if (!enum_field_type) {
ret = -1;
goto end;
}
goto error;
}
- if (integer_container_type->id != BT_CTF_TYPE_ID_INTEGER) {
+ if (integer_container_type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
goto error;
}
goto error;
}
- enumeration->parent.id = BT_CTF_TYPE_ID_ENUM;
+ enumeration->parent.id = BT_CTF_FIELD_TYPE_ID_ENUM;
bt_get(integer_container_type);
enumeration->container = integer_container_type;
enumeration->entries = g_ptr_array_new_with_free_func(
goto end;
}
- if (type->id != BT_CTF_TYPE_ID_ENUM) {
+ if (type->id != BT_CTF_FIELD_TYPE_ID_ENUM) {
goto end;
}
struct bt_ctf_field_type_enumeration *enumeration;
char *escaped_string;
- if (!type || (type->id != BT_CTF_TYPE_ID_ENUM) ||
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_ENUM) ||
type->frozen ||
(range_end < range_start)) {
ret = -1;
struct bt_ctf_field_type_enumeration *enumeration;
char *escaped_string;
- if (!type || (type->id != BT_CTF_TYPE_ID_ENUM) ||
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_ENUM) ||
type->frozen ||
(range_end < range_start)) {
ret = -1;
return ret;
}
-int bt_ctf_field_type_enumeration_get_mapping_count(
+int64_t bt_ctf_field_type_enumeration_get_mapping_count(
struct bt_ctf_field_type *type)
{
- int ret = 0;
+ int64_t ret = 0;
struct bt_ctf_field_type_enumeration *enumeration;
- if (!type || (type->id != BT_CTF_TYPE_ID_ENUM)) {
- ret = -1;
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_ENUM)) {
+ ret = (int64_t) -1;
goto end;
}
enumeration = container_of(type, struct bt_ctf_field_type_enumeration,
parent);
- ret = (int) enumeration->entries->len;
+ ret = (int64_t) enumeration->entries->len;
end:
return ret;
}
goto end;
}
- floating_point->parent.id = BT_CTF_TYPE_ID_FLOAT;
+ floating_point->parent.id = BT_CTF_FIELD_TYPE_ID_FLOAT;
floating_point->exp_dig = sizeof(float) * CHAR_BIT - FLT_MANT_DIG;
floating_point->mant_dig = FLT_MANT_DIG;
bt_ctf_field_type_init(&floating_point->parent, TRUE);
int ret = 0;
struct bt_ctf_field_type_floating_point *floating_point;
- if (!type || (type->id != BT_CTF_TYPE_ID_FLOAT)) {
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_FLOAT)) {
ret = -1;
goto end;
}
struct bt_ctf_field_type_floating_point *floating_point;
if (!type || type->frozen ||
- (type->id != BT_CTF_TYPE_ID_FLOAT)) {
+ (type->id != BT_CTF_FIELD_TYPE_ID_FLOAT)) {
ret = -1;
goto end;
}
int ret = 0;
struct bt_ctf_field_type_floating_point *floating_point;
- if (!type || (type->id != BT_CTF_TYPE_ID_FLOAT)) {
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_FLOAT)) {
ret = -1;
goto end;
}
struct bt_ctf_field_type_floating_point *floating_point;
if (!type || type->frozen ||
- (type->id != BT_CTF_TYPE_ID_FLOAT)) {
+ (type->id != BT_CTF_FIELD_TYPE_ID_FLOAT)) {
ret = -1;
goto end;
}
goto error;
}
- structure->parent.id = BT_CTF_TYPE_ID_STRUCT;
+ structure->parent.id = BT_CTF_FIELD_TYPE_ID_STRUCT;
structure->fields = g_ptr_array_new_with_free_func(
(GDestroyNotify)destroy_structure_field);
structure->field_name_to_index = g_hash_table_new(NULL, NULL);
*/
if (!type || !field_type || type->frozen ||
bt_ctf_validate_identifier(field_name) ||
- (type->id != BT_CTF_TYPE_ID_STRUCT) ||
+ (type->id != BT_CTF_FIELD_TYPE_ID_STRUCT) ||
type == field_type) {
ret = -1;
goto end;
return ret;
}
-int bt_ctf_field_type_structure_get_field_count(
+int64_t bt_ctf_field_type_structure_get_field_count(
struct bt_ctf_field_type *type)
{
- int ret = 0;
+ int64_t ret = 0;
struct bt_ctf_field_type_structure *structure;
- if (!type || (type->id != BT_CTF_TYPE_ID_STRUCT)) {
- ret = -1;
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_STRUCT)) {
+ ret = (int64_t) -1;
goto end;
}
structure = container_of(type, struct bt_ctf_field_type_structure,
parent);
- ret = (int) structure->fields->len;
+ ret = (int64_t) structure->fields->len;
end:
return ret;
}
-int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *type,
+int bt_ctf_field_type_structure_get_field_by_index(
+ struct bt_ctf_field_type *type,
const char **field_name, struct bt_ctf_field_type **field_type,
- int index)
+ uint64_t index)
{
struct bt_ctf_field_type_structure *structure;
struct structure_field *field;
int ret = 0;
- if (!type || index < 0 ||
- (type->id != BT_CTF_TYPE_ID_STRUCT)) {
+ if (!type || type->id != BT_CTF_FIELD_TYPE_ID_STRUCT) {
ret = -1;
goto end;
}
goto error;
}
- variant->parent.id = BT_CTF_TYPE_ID_VARIANT;
+ variant->parent.id = BT_CTF_FIELD_TYPE_ID_VARIANT;
variant->tag_name = g_string_new(tag_name);
variant->field_name_to_index = g_hash_table_new(NULL, NULL);
variant->fields = g_ptr_array_new_with_free_func(
struct bt_ctf_field_type_variant *variant;
struct bt_ctf_field_type *tag_type = NULL;
- if (!type || (type->id != BT_CTF_TYPE_ID_VARIANT)) {
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_VARIANT)) {
goto end;
}
struct bt_ctf_field_type_variant *variant;
const char *tag_name = NULL;
- if (!type || (type->id != BT_CTF_TYPE_ID_VARIANT)) {
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_VARIANT)) {
goto end;
}
struct bt_ctf_field_type_variant *variant;
if (!type || type->frozen ||
- (type->id != BT_CTF_TYPE_ID_VARIANT) ||
+ (type->id != BT_CTF_FIELD_TYPE_ID_VARIANT) ||
bt_ctf_validate_identifier(name)) {
ret = -1;
goto end;
*/
if (!type || !field_type || type->frozen ||
bt_ctf_validate_identifier(field_name) ||
- (type->id != BT_CTF_TYPE_ID_VARIANT) ||
+ (type->id != BT_CTF_FIELD_TYPE_ID_VARIANT) ||
type == field_type) {
ret = -1;
goto end;
struct bt_ctf_field_type *field_type = NULL;
struct bt_ctf_field_type_enumeration_mapping_iterator *iter = NULL;
- if (!type || !tag || type->id != BT_CTF_TYPE_ID_VARIANT) {
+ if (!type || !tag || type->id != BT_CTF_FIELD_TYPE_ID_VARIANT) {
goto end;
}
return field_type;
}
-int bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *type)
+int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *type)
{
- int ret = 0;
+ int64_t ret = 0;
struct bt_ctf_field_type_variant *variant;
- if (!type || (type->id != BT_CTF_TYPE_ID_VARIANT)) {
- ret = -1;
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_VARIANT)) {
+ ret = (int64_t) -1;
goto end;
}
variant = container_of(type, struct bt_ctf_field_type_variant,
parent);
- ret = (int) variant->fields->len;
+ ret = (int64_t) variant->fields->len;
end:
return ret;
}
-int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *type,
+int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type *type,
const char **field_name, struct bt_ctf_field_type **field_type,
- int index)
+ uint64_t index)
{
struct bt_ctf_field_type_variant *variant;
struct structure_field *field;
int ret = 0;
- if (!type || index < 0 ||
- (type->id != BT_CTF_TYPE_ID_VARIANT)) {
+ if (!type || type->id != BT_CTF_FIELD_TYPE_ID_VARIANT) {
ret = -1;
goto end;
}
goto error;
}
- array->parent.id = BT_CTF_TYPE_ID_ARRAY;
+ array->parent.id = BT_CTF_FIELD_TYPE_ID_ARRAY;
bt_get(element_type);
array->element_type = element_type;
array->length = length;
struct bt_ctf_field_type *ret = NULL;
struct bt_ctf_field_type_array *array;
- if (!type || (type->id != BT_CTF_TYPE_ID_ARRAY)) {
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_ARRAY)) {
goto end;
}
struct bt_ctf_field_type_array *array;
if (!type || !element_type ||
- (type->id != BT_CTF_TYPE_ID_ARRAY)) {
+ (type->id != BT_CTF_FIELD_TYPE_ID_ARRAY)) {
ret = -1;
goto end;
}
int64_t ret;
struct bt_ctf_field_type_array *array;
- if (!type || (type->id != BT_CTF_TYPE_ID_ARRAY)) {
- ret = -1;
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_ARRAY)) {
+ ret = (int64_t) -1;
goto end;
}
goto error;
}
- sequence->parent.id = BT_CTF_TYPE_ID_SEQUENCE;
+ sequence->parent.id = BT_CTF_FIELD_TYPE_ID_SEQUENCE;
bt_get(element_type);
sequence->element_type = element_type;
sequence->length_field_name = g_string_new(length_field_name);
struct bt_ctf_field_type *ret = NULL;
struct bt_ctf_field_type_sequence *sequence;
- if (!type || (type->id != BT_CTF_TYPE_ID_SEQUENCE)) {
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_SEQUENCE)) {
goto end;
}
struct bt_ctf_field_type_sequence *sequence;
if (!type || !element_type ||
- (type->id != BT_CTF_TYPE_ID_SEQUENCE)) {
+ (type->id != BT_CTF_FIELD_TYPE_ID_SEQUENCE)) {
ret = -1;
goto end;
}
const char *ret = NULL;
struct bt_ctf_field_type_sequence *sequence;
- if (!type || (type->id != BT_CTF_TYPE_ID_SEQUENCE)) {
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_SEQUENCE)) {
goto end;
}
return NULL;
}
- string->parent.id = BT_CTF_TYPE_ID_STRING;
+ string->parent.id = BT_CTF_FIELD_TYPE_ID_STRING;
bt_ctf_field_type_init(&string->parent, TRUE);
string->encoding = BT_CTF_STRING_ENCODING_UTF8;
string->parent.alignment = CHAR_BIT;
struct bt_ctf_field_type_string *string;
enum bt_ctf_string_encoding ret = BT_CTF_STRING_ENCODING_UNKNOWN;
- if (!type || (type->id != BT_CTF_TYPE_ID_STRING)) {
+ if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_STRING)) {
goto end;
}
int ret = 0;
struct bt_ctf_field_type_string *string;
- if (!type || type->id != BT_CTF_TYPE_ID_STRING ||
+ if (!type || type->id != BT_CTF_FIELD_TYPE_ID_STRING ||
(encoding != BT_CTF_STRING_ENCODING_UTF8 &&
encoding != BT_CTF_STRING_ENCODING_ASCII)) {
ret = -1;
int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type)
{
int ret;
- enum bt_ctf_type_id type_id;
+ enum bt_ctf_field_type_id type_id;
if (!type) {
ret = -1;
type_id = bt_ctf_field_type_get_type_id(type);
switch (type_id) {
- case BT_CTF_TYPE_ID_SEQUENCE:
+ case BT_CTF_FIELD_TYPE_ID_SEQUENCE:
{
struct bt_ctf_field_type *element =
bt_ctf_field_type_sequence_get_element_type(type);
bt_put(element);
break;
}
- case BT_CTF_TYPE_ID_ARRAY:
+ case BT_CTF_FIELD_TYPE_ID_ARRAY:
{
struct bt_ctf_field_type *element =
bt_ctf_field_type_array_get_element_type(type);
bt_put(element);
break;
}
- case BT_CTF_TYPE_ID_STRUCT:
+ case BT_CTF_FIELD_TYPE_ID_STRUCT:
{
- int i, element_count;
+ int64_t i, element_count;
element_count = bt_ctf_field_type_structure_get_field_count(
type);
struct bt_ctf_field_type *field;
int field_alignment;
- ret = bt_ctf_field_type_structure_get_field(type, NULL,
- &field, i);
+ ret = bt_ctf_field_type_structure_get_field_by_index(
+ type, NULL, &field, i);
if (ret) {
goto end;
}
ret = (int) type->alignment;
break;
}
- case BT_CTF_TYPE_ID_UNKNOWN:
+ case BT_CTF_FIELD_TYPE_ID_UNKNOWN:
ret = -1;
break;
default:
unsigned int alignment)
{
int ret = 0;
- enum bt_ctf_type_id type_id;
+ enum bt_ctf_field_type_id type_id;
/* Alignment must be a power of two */
if (!type || type->frozen || !is_power_of_two(alignment)) {
}
type_id = bt_ctf_field_type_get_type_id(type);
- if (type_id == BT_CTF_TYPE_ID_UNKNOWN) {
+ if (type_id == BT_CTF_FIELD_TYPE_ID_UNKNOWN) {
ret = -1;
goto end;
}
- if (type->id == BT_CTF_TYPE_ID_STRING &&
+ if (type->id == BT_CTF_FIELD_TYPE_ID_STRING &&
alignment != CHAR_BIT) {
ret = -1;
goto end;
}
- if (type_id == BT_CTF_TYPE_ID_VARIANT ||
- type_id == BT_CTF_TYPE_ID_SEQUENCE ||
- type_id == BT_CTF_TYPE_ID_ARRAY) {
+ if (type_id == BT_CTF_FIELD_TYPE_ID_VARIANT ||
+ type_id == BT_CTF_FIELD_TYPE_ID_SEQUENCE ||
+ type_id == BT_CTF_FIELD_TYPE_ID_ARRAY) {
/* Setting an alignment on these types makes no sense */
ret = -1;
goto end;
}
switch (type->id) {
- case BT_CTF_TYPE_ID_INTEGER:
+ case BT_CTF_FIELD_TYPE_ID_INTEGER:
{
struct bt_ctf_field_type_integer *integer = container_of(
type, struct bt_ctf_field_type_integer, parent);
ret = integer->user_byte_order;
break;
}
- case BT_CTF_TYPE_ID_ENUM:
+ case BT_CTF_FIELD_TYPE_ID_ENUM:
{
struct bt_ctf_field_type_enumeration *enum_ft = container_of(
type, struct bt_ctf_field_type_enumeration, parent);
ret = bt_ctf_field_type_get_byte_order(enum_ft->container);
break;
}
- case BT_CTF_TYPE_ID_FLOAT:
+ case BT_CTF_FIELD_TYPE_ID_FLOAT:
{
struct bt_ctf_field_type_floating_point *floating_point =
container_of(type,
return ret;
}
-enum bt_ctf_type_id bt_ctf_field_type_get_type_id(
+enum bt_ctf_field_type_id bt_ctf_field_type_get_type_id(
struct bt_ctf_field_type *type)
{
if (!type) {
- return BT_CTF_TYPE_ID_UNKNOWN;
+ return BT_CTF_FIELD_TYPE_ID_UNKNOWN;
}
return type->id;
int bt_ctf_field_type_is_integer(struct bt_ctf_field_type *type)
{
- return bt_ctf_field_type_get_type_id(type) == BT_CTF_TYPE_ID_INTEGER;
+ return bt_ctf_field_type_get_type_id(type) == BT_CTF_FIELD_TYPE_ID_INTEGER;
}
int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type *type)
{
- return bt_ctf_field_type_get_type_id(type) == BT_CTF_TYPE_ID_FLOAT;
+ return bt_ctf_field_type_get_type_id(type) == BT_CTF_FIELD_TYPE_ID_FLOAT;
}
int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type *type)
{
- return bt_ctf_field_type_get_type_id(type) == BT_CTF_TYPE_ID_ENUM;
+ return bt_ctf_field_type_get_type_id(type) == BT_CTF_FIELD_TYPE_ID_ENUM;
}
int bt_ctf_field_type_is_string(struct bt_ctf_field_type *type)
{
- return bt_ctf_field_type_get_type_id(type) == BT_CTF_TYPE_ID_STRING;
+ return bt_ctf_field_type_get_type_id(type) == BT_CTF_FIELD_TYPE_ID_STRING;
}
int bt_ctf_field_type_is_structure(struct bt_ctf_field_type *type)
{
- return bt_ctf_field_type_get_type_id(type) == BT_CTF_TYPE_ID_STRUCT;
+ return bt_ctf_field_type_get_type_id(type) == BT_CTF_FIELD_TYPE_ID_STRUCT;
}
int bt_ctf_field_type_is_array(struct bt_ctf_field_type *type)
{
- return bt_ctf_field_type_get_type_id(type) == BT_CTF_TYPE_ID_ARRAY;
+ return bt_ctf_field_type_get_type_id(type) == BT_CTF_FIELD_TYPE_ID_ARRAY;
}
int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type *type)
{
- return bt_ctf_field_type_get_type_id(type) == BT_CTF_TYPE_ID_SEQUENCE;
+ return bt_ctf_field_type_get_type_id(type) == BT_CTF_FIELD_TYPE_ID_SEQUENCE;
}
int bt_ctf_field_type_is_variant(struct bt_ctf_field_type *type)
{
- return bt_ctf_field_type_get_type_id(type) == BT_CTF_TYPE_ID_VARIANT;
+ return bt_ctf_field_type_get_type_id(type) == BT_CTF_FIELD_TYPE_ID_VARIANT;
}
void bt_ctf_field_type_get(struct bt_ctf_field_type *type)
struct bt_ctf_field_type_structure *structure;
if (!type || !name ||
- bt_ctf_field_type_get_type_id(type) != BT_CTF_TYPE_ID_STRUCT) {
+ bt_ctf_field_type_get_type_id(type) != BT_CTF_FIELD_TYPE_ID_STRUCT) {
ret = -1;
goto end;
}
struct bt_ctf_field_type_structure *structure;
if (!type || !field ||
- bt_ctf_field_type_get_type_id(type) != BT_CTF_TYPE_ID_STRUCT) {
+ bt_ctf_field_type_get_type_id(type) != BT_CTF_FIELD_TYPE_ID_STRUCT) {
ret = -1;
goto end;
}
struct bt_ctf_field_type_variant *variant;
if (!type || !name ||
- bt_ctf_field_type_get_type_id(type) != BT_CTF_TYPE_ID_VARIANT) {
+ bt_ctf_field_type_get_type_id(type) != BT_CTF_FIELD_TYPE_ID_VARIANT) {
ret = -1;
goto end;
}
struct bt_ctf_field_type_sequence *sequence;
if (!type || bt_ctf_field_type_get_type_id(type) !=
- BT_CTF_TYPE_ID_SEQUENCE) {
+ BT_CTF_FIELD_TYPE_ID_SEQUENCE) {
ret = -1;
goto end;
}
struct bt_ctf_field_type_variant *variant;
if (!type || bt_ctf_field_type_get_type_id(type) !=
- BT_CTF_TYPE_ID_VARIANT) {
+ BT_CTF_FIELD_TYPE_ID_VARIANT) {
ret = -1;
goto end;
}
if (!type || !tag ||
bt_ctf_field_type_get_type_id(tag) !=
- BT_CTF_TYPE_ID_ENUM) {
+ BT_CTF_FIELD_TYPE_ID_ENUM) {
ret = -1;
goto end;
}
struct bt_ctf_field_type_variant *variant;
if (!type || !field ||
- bt_ctf_field_type_get_type_id(type) != BT_CTF_TYPE_ID_VARIANT) {
+ bt_ctf_field_type_get_type_id(type) != BT_CTF_FIELD_TYPE_ID_VARIANT) {
ret = -1;
goto end;
}
goto end;
}
- if (type_a->id == BT_CTF_TYPE_ID_UNKNOWN) {
+ if (type_a->id == BT_CTF_FIELD_TYPE_ID_UNKNOWN) {
/* Both have unknown type IDs */
goto end;
}
}
BT_HIDDEN
-int bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *field_type)
+int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *field_type)
{
- int field_count = -1;
- enum bt_ctf_type_id type_id = bt_ctf_field_type_get_type_id(field_type);
+ int64_t field_count = -1;
+ enum bt_ctf_field_type_id type_id = bt_ctf_field_type_get_type_id(field_type);
switch (type_id) {
case CTF_TYPE_STRUCT:
struct bt_ctf_field_type *field_type, int index)
{
struct bt_ctf_field_type *field = NULL;
- enum bt_ctf_type_id type_id = bt_ctf_field_type_get_type_id(field_type);
+ enum bt_ctf_field_type_id type_id = bt_ctf_field_type_get_type_id(field_type);
switch (type_id) {
case CTF_TYPE_STRUCT:
- bt_ctf_field_type_structure_get_field(field_type, NULL, &field,
- index);
+ bt_ctf_field_type_structure_get_field_by_index(field_type,
+ NULL, &field, index);
break;
case CTF_TYPE_VARIANT:
{
- int ret = bt_ctf_field_type_variant_get_field(field_type, NULL,
- &field, index);
+ int ret = bt_ctf_field_type_variant_get_field_by_index(
+ field_type, NULL, &field, index);
if (ret) {
field = NULL;
goto end;
const char *name)
{
int field_index = -1;
- enum bt_ctf_type_id type_id = bt_ctf_field_type_get_type_id(field_type);
+ enum bt_ctf_field_type_id type_id = bt_ctf_field_type_get_type_id(field_type);
switch (type_id) {
case CTF_TYPE_STRUCT: