- struct bt_ctf_field_type_sequence *sequence_type = container_of(
- type, struct bt_ctf_field_type_sequence, parent);
-
- /* Cache the alignment */
- BT_LOGD("Freezing sequence field type object: addr=%p", type);
- type->alignment = bt_ctf_field_type_get_alignment(type);
- generic_field_type_freeze(type);
- BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
- sequence_type->element_type);
- bt_ctf_field_type_freeze(sequence_type->element_type);
-}
-
-static
-const char *get_encoding_string(enum bt_ctf_string_encoding encoding)
-{
- const char *encoding_string;
-
- switch (encoding) {
- case BT_CTF_STRING_ENCODING_NONE:
- encoding_string = "none";
- break;
- case BT_CTF_STRING_ENCODING_ASCII:
- encoding_string = "ASCII";
- break;
- case BT_CTF_STRING_ENCODING_UTF8:
- encoding_string = "UTF8";
- break;
- default:
- encoding_string = "unknown";
- break;
- }
-
- return encoding_string;
-}
-
-static
-const char *get_integer_base_string(enum bt_ctf_integer_base base)
-{
- const char *base_string;
-
- switch (base) {
- case BT_CTF_INTEGER_BASE_DECIMAL:
- base_string = "decimal";
- break;
- case BT_CTF_INTEGER_BASE_HEXADECIMAL:
- base_string = "hexadecimal";
- break;
- case BT_CTF_INTEGER_BASE_OCTAL:
- base_string = "octal";
- break;
- case BT_CTF_INTEGER_BASE_BINARY:
- base_string = "binary";
- break;
- default:
- base_string = "unknown";
- break;
- }
-
- return base_string;
-}
-
-static
-int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type *type,
- struct metadata_context *context)
-{
- struct bt_ctf_field_type_integer *integer = container_of(type,
- struct bt_ctf_field_type_integer, parent);
- int ret = 0;
-
- BT_LOGD("Serializing integer field type's metadata: "
- "ft-addr=%p, metadata-context-addr=%p", type, context);
- g_string_append_printf(context->string,
- "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
- integer->size, type->alignment,
- (integer->is_signed ? "true" : "false"),
- get_encoding_string(integer->encoding),
- get_integer_base_string(integer->base),
- get_byte_order_string(integer->user_byte_order));
- if (integer->mapped_clock) {
- const char *clock_name = bt_ctf_clock_class_get_name(
- integer->mapped_clock);
-
- assert(clock_name);
- g_string_append_printf(context->string,
- "; map = clock.%s.value", clock_name);
- }
-
- g_string_append(context->string, "; }");
- return ret;
-}
-
-static
-int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type *type,
- struct metadata_context *context)
-{
- size_t entry;
- int ret;
- struct bt_ctf_field_type_enumeration *enumeration = container_of(type,
- struct bt_ctf_field_type_enumeration, parent);
- struct bt_ctf_field_type *container_type;
- int container_signed;
-
- BT_LOGD("Serializing enumeration field type's metadata: "
- "ft-addr=%p, metadata-context-addr=%p", type, context);
- container_type = bt_ctf_field_type_enumeration_get_container_type(type);
- assert(container_type);
- container_signed = bt_ctf_field_type_integer_get_signed(container_type);
- assert(container_signed >= 0);
- g_string_append(context->string, "enum : ");
- BT_LOGD_STR("Serializing enumeration field type's container field type's metadata.");
- ret = bt_ctf_field_type_serialize(enumeration->container, context);
- if (ret) {
- BT_LOGW("Cannot serialize enumeration field type's container field type's metadata: "
- "container-ft-addr=%p", enumeration->container);
- goto end;
- }
-
- g_string_append(context->string, " { ");
- for (entry = 0; entry < enumeration->entries->len; entry++) {
- struct enumeration_mapping *mapping =
- enumeration->entries->pdata[entry];
-
- if (container_signed) {
- if (mapping->range_start._signed ==
- mapping->range_end._signed) {
- g_string_append_printf(context->string,
- "\"%s\" = %" PRId64,
- g_quark_to_string(mapping->string),
- mapping->range_start._signed);
- } else {
- g_string_append_printf(context->string,
- "\"%s\" = %" PRId64 " ... %" PRId64,
- g_quark_to_string(mapping->string),
- mapping->range_start._signed,
- mapping->range_end._signed);
- }
- } else {
- if (mapping->range_start._unsigned ==
- mapping->range_end._unsigned) {
- g_string_append_printf(context->string,
- "\"%s\" = %" PRIu64,
- g_quark_to_string(mapping->string),
- mapping->range_start._unsigned);
- } else {
- g_string_append_printf(context->string,
- "\"%s\" = %" PRIu64 " ... %" PRIu64,
- g_quark_to_string(mapping->string),
- mapping->range_start._unsigned,
- mapping->range_end._unsigned);
- }
- }
-
- g_string_append(context->string,
- ((entry != (enumeration->entries->len - 1)) ?
- ", " : " }"));
- }
-
- if (context->field_name->len) {
- g_string_append_printf(context->string, " %s",
- context->field_name->str);
- g_string_assign(context->field_name, "");
- }
-end:
- bt_put(container_type);
- return ret;
-}
-
-static
-int bt_ctf_field_type_floating_point_serialize(struct bt_ctf_field_type *type,
- struct metadata_context *context)
-{
- struct bt_ctf_field_type_floating_point *floating_point = container_of(
- type, struct bt_ctf_field_type_floating_point, parent);
-
- BT_LOGD("Serializing floating point number field type's metadata: "
- "ft-addr=%p, metadata-context-addr=%p", type, context);
- g_string_append_printf(context->string,
- "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
- floating_point->exp_dig,
- floating_point->mant_dig,
- get_byte_order_string(floating_point->user_byte_order),
- type->alignment);
- return 0;
-}
-
-static
-int bt_ctf_field_type_structure_serialize(struct bt_ctf_field_type *type,
- struct metadata_context *context)
-{
- size_t i;
- unsigned int indent;
- int ret = 0;
- struct bt_ctf_field_type_structure *structure = container_of(type,
- struct bt_ctf_field_type_structure, parent);
- GString *structure_field_name = context->field_name;
-
- BT_LOGD("Serializing structure field type's metadata: "
- "ft-addr=%p, metadata-context-addr=%p", type, context);
- context->field_name = g_string_new("");
-
- context->current_indentation_level++;
- g_string_append(context->string, "struct {\n");
-
- for (i = 0; i < structure->fields->len; i++) {
- struct structure_field *field = structure->fields->pdata[i];
-
- BT_LOGD("Serializing structure field type's field metadata: "
- "index=%" PRId64 ", "
- "field-ft-addr=%p, field-name=\"%s\"",
- i, field, g_quark_to_string(field->name));
-
- for (indent = 0; indent < context->current_indentation_level;
- indent++) {
- g_string_append_c(context->string, '\t');
- }
-
- g_string_assign(context->field_name,
- g_quark_to_string(field->name));
- ret = bt_ctf_field_type_serialize(field->type, context);
- if (ret) {
- BT_LOGW("Cannot serialize structure field type's field's metadata: "
- "index=%" PRId64 ", "
- "field-ft-addr=%p, field-name=\"%s\"",
- i, field->type,
- g_quark_to_string(field->name));
- goto end;
- }
-
- if (context->field_name->len) {
- g_string_append_printf(context->string, " %s",
- context->field_name->str);
- }
- g_string_append(context->string, ";\n");
- }
-
- context->current_indentation_level--;
- for (indent = 0; indent < context->current_indentation_level;
- indent++) {
- g_string_append_c(context->string, '\t');
- }
-
- g_string_append_printf(context->string, "} align(%u)",
- type->alignment);
-end:
- g_string_free(context->field_name, TRUE);
- context->field_name = structure_field_name;
- return ret;
-}
-
-static
-int bt_ctf_field_type_variant_serialize(struct bt_ctf_field_type *type,
- struct metadata_context *context)
-{
- size_t i;
- unsigned int indent;
- int ret = 0;
- struct bt_ctf_field_type_variant *variant = container_of(
- type, struct bt_ctf_field_type_variant, parent);
- GString *variant_field_name = context->field_name;
-
- BT_LOGD("Serializing variant field type's metadata: "
- "ft-addr=%p, metadata-context-addr=%p", type, context);
- context->field_name = g_string_new("");
- if (variant->tag_name->len > 0) {
- g_string_append_printf(context->string,
- "variant <%s> {\n", variant->tag_name->str);
- } else {
- g_string_append(context->string, "variant {\n");
- }
-
- context->current_indentation_level++;
- for (i = 0; i < variant->fields->len; i++) {
- struct structure_field *field = variant->fields->pdata[i];
-
- BT_LOGD("Serializing variant field type's field metadata: "
- "index=%" PRId64 ", "
- "field-ft-addr=%p, field-name=\"%s\"",
- i, field, g_quark_to_string(field->name));
-
- g_string_assign(context->field_name,
- g_quark_to_string(field->name));
- for (indent = 0; indent < context->current_indentation_level;
- indent++) {
- g_string_append_c(context->string, '\t');
- }
-
- g_string_assign(context->field_name,
- g_quark_to_string(field->name));
- ret = bt_ctf_field_type_serialize(field->type, context);
- if (ret) {
- BT_LOGW("Cannot serialize variant field type's field's metadata: "
- "index=%" PRId64 ", "
- "field-ft-addr=%p, field-name=\"%s\"",
- i, field->type,
- g_quark_to_string(field->name));
- goto end;
- }
-
- if (context->field_name->len) {
- g_string_append_printf(context->string, " %s;",
- context->field_name->str);
- }
-
- g_string_append_c(context->string, '\n');
- }
-
- context->current_indentation_level--;
- for (indent = 0; indent < context->current_indentation_level;
- indent++) {
- g_string_append_c(context->string, '\t');
- }
-
- g_string_append(context->string, "}");
-end:
- g_string_free(context->field_name, TRUE);
- context->field_name = variant_field_name;
- return ret;
-}
-
-static
-int bt_ctf_field_type_array_serialize(struct bt_ctf_field_type *type,
- struct metadata_context *context)
-{
- int ret = 0;
- struct bt_ctf_field_type_array *array = container_of(type,
- struct bt_ctf_field_type_array, parent);
-
- BT_LOGD("Serializing array field type's metadata: "
- "ft-addr=%p, metadata-context-addr=%p", type, context);
- BT_LOGD_STR("Serializing array field type's element field type's metadata.");
- ret = bt_ctf_field_type_serialize(array->element_type, context);
- if (ret) {
- BT_LOGW("Cannot serialize array field type's element field type's metadata: "
- "element-ft-addr=%p", array->element_type);
- goto end;
- }
-
- if (context->field_name->len) {
- g_string_append_printf(context->string, " %s[%u]",
- context->field_name->str, array->length);
- g_string_assign(context->field_name, "");
- } else {
- g_string_append_printf(context->string, "[%u]", array->length);
- }
-end:
- return ret;
-}
-
-static
-int bt_ctf_field_type_sequence_serialize(struct bt_ctf_field_type *type,
- struct metadata_context *context)
-{
- int ret = 0;
- struct bt_ctf_field_type_sequence *sequence = container_of(
- type, struct bt_ctf_field_type_sequence, parent);
-
- BT_LOGD("Serializing sequence field type's metadata: "
- "ft-addr=%p, metadata-context-addr=%p", type, context);
- BT_LOGD_STR("Serializing sequence field type's element field type's metadata.");
- ret = bt_ctf_field_type_serialize(sequence->element_type, context);
- if (ret) {
- BT_LOGW("Cannot serialize sequence field type's element field type's metadata: "
- "element-ft-addr=%p", sequence->element_type);
- goto end;
- }
-
- if (context->field_name->len) {
- g_string_append_printf(context->string, " %s[%s]",
- context->field_name->str,
- sequence->length_field_name->str);
- g_string_assign(context->field_name, "");
- } else {
- g_string_append_printf(context->string, "[%s]",
- sequence->length_field_name->str);
- }
-end:
- return ret;
-}
-
-static
-int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type *type,
- struct metadata_context *context)
-{
- struct bt_ctf_field_type_string *string = container_of(
- type, struct bt_ctf_field_type_string, parent);
-
- BT_LOGD("Serializing string field type's metadata: "
- "ft-addr=%p, metadata-context-addr=%p", type, context);
- g_string_append_printf(context->string,
- "string { encoding = %s; }",
- get_encoding_string(string->encoding));
- return 0;
-}
-
-static
-void bt_ctf_field_type_integer_set_byte_order(struct bt_ctf_field_type *type,
- enum bt_ctf_byte_order byte_order)
-{
- struct bt_ctf_field_type_integer *integer_type = container_of(type,
- struct bt_ctf_field_type_integer, parent);
-
- integer_type->user_byte_order = byte_order;
-}
-
-static
-void bt_ctf_field_type_enumeration_set_byte_order(
- struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order)
-{
- struct bt_ctf_field_type_enumeration *enum_type = container_of(type,
- struct bt_ctf_field_type_enumeration, parent);
-
- /* Safe to assume that container is an integer */
- bt_ctf_field_type_integer_set_byte_order(enum_type->container,
- byte_order);
-}
-
-static
-void bt_ctf_field_type_floating_point_set_byte_order(
- struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order)
-{
- struct bt_ctf_field_type_floating_point *floating_point_type =
- container_of(type, struct bt_ctf_field_type_floating_point,
- parent);
-
- floating_point_type->user_byte_order = byte_order;
-}
-
-static
-void bt_ctf_field_type_structure_set_byte_order(struct bt_ctf_field_type *type,
- enum bt_ctf_byte_order byte_order)
-{
- int i;
- struct bt_ctf_field_type_structure *structure_type =
- container_of(type, struct bt_ctf_field_type_structure,
- parent);
-
- for (i = 0; i < structure_type->fields->len; i++) {
- struct structure_field *field = g_ptr_array_index(
- structure_type->fields, i);
- struct bt_ctf_field_type *field_type = field->type;
-
- if (set_byte_order_funcs[field_type->id]) {
- set_byte_order_funcs[field_type->id](
- field_type, byte_order);
- }
- }
-}
-
-static
-void bt_ctf_field_type_variant_set_byte_order(struct bt_ctf_field_type *type,
- enum bt_ctf_byte_order byte_order)
-{
- int i;
- struct bt_ctf_field_type_variant *variant_type =
- container_of(type, struct bt_ctf_field_type_variant,
- parent);
-
- for (i = 0; i < variant_type->fields->len; i++) {
- struct structure_field *field = g_ptr_array_index(
- variant_type->fields, i);
- struct bt_ctf_field_type *field_type = field->type;
-
- if (set_byte_order_funcs[field_type->id]) {
- set_byte_order_funcs[field_type->id](
- field_type, byte_order);
- }
- }
-}
-
-static
-void bt_ctf_field_type_array_set_byte_order(struct bt_ctf_field_type *type,
- enum bt_ctf_byte_order byte_order)
-{
- struct bt_ctf_field_type_array *array_type =
- container_of(type, struct bt_ctf_field_type_array,
- parent);
-
- if (set_byte_order_funcs[array_type->element_type->id]) {
- set_byte_order_funcs[array_type->element_type->id](
- array_type->element_type, byte_order);
- }
-}
-
-static
-void bt_ctf_field_type_sequence_set_byte_order(struct bt_ctf_field_type *type,
- enum bt_ctf_byte_order byte_order)
-{
- struct bt_ctf_field_type_sequence *sequence_type =
- container_of(type, struct bt_ctf_field_type_sequence,
- parent);
-
- if (set_byte_order_funcs[
- sequence_type->element_type->id]) {
- set_byte_order_funcs[
- sequence_type->element_type->id](
- sequence_type->element_type, byte_order);
- }
-}
-
-static
-struct bt_ctf_field_type *bt_ctf_field_type_integer_copy(
- struct bt_ctf_field_type *type)
-{
- struct bt_ctf_field_type *copy;
- struct bt_ctf_field_type_integer *integer, *copy_integer;
-
- BT_LOGD("Copying integer field type's: addr=%p", type);
- integer = container_of(type, struct bt_ctf_field_type_integer, parent);
- copy = bt_ctf_field_type_integer_create(integer->size);
- if (!copy) {
- BT_LOGE_STR("Cannot create integer field type.");
- goto end;
- }
-
- copy_integer = container_of(copy, struct bt_ctf_field_type_integer,
- parent);
- copy_integer->mapped_clock = bt_get(integer->mapped_clock);
- copy_integer->user_byte_order = integer->user_byte_order;
- copy_integer->is_signed = integer->is_signed;
- copy_integer->size = integer->size;
- copy_integer->base = integer->base;
- copy_integer->encoding = integer->encoding;
- BT_LOGD("Copied integer field type: original-ft-addr=%p, copy-ft-addr=%p",
- type, copy);
-
-end:
- return copy;
-}
-
-static
-struct bt_ctf_field_type *bt_ctf_field_type_enumeration_copy(
- struct bt_ctf_field_type *type)
-{
- size_t i;
- struct bt_ctf_field_type *copy = NULL, *copy_container;
- struct bt_ctf_field_type_enumeration *enumeration, *copy_enumeration;
-
- BT_LOGD("Copying enumeration field type's: addr=%p", type);
- enumeration = container_of(type, struct bt_ctf_field_type_enumeration,
- parent);
-
- /* Copy the source enumeration's container */
- BT_LOGD_STR("Copying enumeration field type's container field type.");
- copy_container = bt_ctf_field_type_copy(enumeration->container);
- if (!copy_container) {
- BT_LOGE_STR("Cannot copy enumeration field type's container field type.");
- goto end;
- }
-
- copy = bt_ctf_field_type_enumeration_create(copy_container);
- if (!copy) {
- BT_LOGE_STR("Cannot create enumeration field type.");
- goto end;
- }
- copy_enumeration = container_of(copy,
- struct bt_ctf_field_type_enumeration, parent);
-
- /* Copy all enumaration entries */
- for (i = 0; i < enumeration->entries->len; i++) {
- struct enumeration_mapping *mapping = g_ptr_array_index(
- enumeration->entries, i);
- struct enumeration_mapping *copy_mapping = g_new0(
- struct enumeration_mapping, 1);
-
- if (!copy_mapping) {
- BT_LOGE_STR("Failed to allocate one enumeration mapping.");
- goto error;
- }
-
- *copy_mapping = *mapping;
- g_ptr_array_add(copy_enumeration->entries, copy_mapping);
- }
-
- BT_LOGD("Copied enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
- type, copy);
-
-end:
- bt_put(copy_container);
- return copy;
-error:
- bt_put(copy_container);
- BT_PUT(copy);
- return copy;
-}
-
-static
-struct bt_ctf_field_type *bt_ctf_field_type_floating_point_copy(
- struct bt_ctf_field_type *type)
-{
- struct bt_ctf_field_type *copy;
- struct bt_ctf_field_type_floating_point *floating_point, *copy_float;
-
- BT_LOGD("Copying floating point number field type's: addr=%p", type);
- floating_point = container_of(type,
- struct bt_ctf_field_type_floating_point, parent);
- copy = bt_ctf_field_type_floating_point_create();
- if (!copy) {
- BT_LOGE_STR("Cannot create floating point number field type.");
- goto end;
- }
-
- copy_float = container_of(copy,
- struct bt_ctf_field_type_floating_point, parent);
- copy_float->user_byte_order = floating_point->user_byte_order;
- copy_float->exp_dig = floating_point->exp_dig;
- copy_float->mant_dig = floating_point->mant_dig;
- BT_LOGD("Copied floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
- type, copy);
-end:
- return copy;
-}
-
-static
-struct bt_ctf_field_type *bt_ctf_field_type_structure_copy(
- struct bt_ctf_field_type *type)
-{
- int64_t i;
- GHashTableIter iter;
- gpointer key, value;
- struct bt_ctf_field_type *copy;
- struct bt_ctf_field_type_structure *structure, *copy_structure;
-
- BT_LOGD("Copying structure field type's: addr=%p", type);
- structure = container_of(type, struct bt_ctf_field_type_structure,
- parent);
- copy = bt_ctf_field_type_structure_create();
- if (!copy) {
- BT_LOGE_STR("Cannot create structure field type.");
- goto end;
- }
-
- copy_structure = container_of(copy,
- struct bt_ctf_field_type_structure, parent);
-
- /* Copy field_name_to_index */
- g_hash_table_iter_init(&iter, structure->field_name_to_index);
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- g_hash_table_insert(copy_structure->field_name_to_index,
- key, value);
- }
-
- for (i = 0; i < structure->fields->len; i++) {
- struct structure_field *entry, *copy_entry;
- struct bt_ctf_field_type *copy_field;
-
- entry = g_ptr_array_index(structure->fields, i);
- BT_LOGD("Copying structure field type's field: "
- "index=%" PRId64 ", "
- "field-ft-addr=%p, field-name=\"%s\"",
- i, entry, g_quark_to_string(entry->name));
- copy_entry = g_new0(struct structure_field, 1);
- if (!copy_entry) {
- BT_LOGE_STR("Failed to allocate one structure field type field.");
- goto error;
- }
-
- copy_field = bt_ctf_field_type_copy(entry->type);
- if (!copy_field) {
- BT_LOGE("Cannot copy structure field type's field: "
- "index=%" PRId64 ", "
- "field-ft-addr=%p, field-name=\"%s\"",
- i, entry, g_quark_to_string(entry->name));
- g_free(copy_entry);
- goto error;
- }
-
- copy_entry->name = entry->name;
- copy_entry->type = copy_field;
- g_ptr_array_add(copy_structure->fields, copy_entry);
- }
-
- BT_LOGD("Copied structure field type: original-ft-addr=%p, copy-ft-addr=%p",
- type, copy);
-
-end:
- return copy;
-error:
- BT_PUT(copy);
- return copy;
-}
-
-static
-struct bt_ctf_field_type *bt_ctf_field_type_variant_copy(
- struct bt_ctf_field_type *type)
-{
- int64_t i;
- GHashTableIter iter;
- gpointer key, value;
- struct bt_ctf_field_type *copy = NULL, *copy_tag = NULL;
- struct bt_ctf_field_type_variant *variant, *copy_variant;
-
- BT_LOGD("Copying variant field type's: addr=%p", type);
- variant = container_of(type, struct bt_ctf_field_type_variant,
- parent);
- if (variant->tag) {
- BT_LOGD_STR("Copying variant field type's tag field type.");
- copy_tag = bt_ctf_field_type_copy(&variant->tag->parent);
- if (!copy_tag) {
- BT_LOGE_STR("Cannot copy variant field type's tag field type.");
- goto end;
- }
- }
-
- copy = bt_ctf_field_type_variant_create(copy_tag,
- variant->tag_name->len ? variant->tag_name->str : NULL);
- if (!copy) {
- BT_LOGE_STR("Cannot create variant field type.");
- goto end;
- }
-
- copy_variant = container_of(copy, struct bt_ctf_field_type_variant,
- parent);
-
- /* Copy field_name_to_index */
- g_hash_table_iter_init(&iter, variant->field_name_to_index);
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- g_hash_table_insert(copy_variant->field_name_to_index,
- key, value);
- }
-
- for (i = 0; i < variant->fields->len; i++) {
- struct structure_field *entry, *copy_entry;
- struct bt_ctf_field_type *copy_field;
-
- entry = g_ptr_array_index(variant->fields, i);
- BT_LOGD("Copying variant field type's field: "
- "index=%" PRId64 ", "
- "field-ft-addr=%p, field-name=\"%s\"",
- i, entry, g_quark_to_string(entry->name));
- copy_entry = g_new0(struct structure_field, 1);
- if (!copy_entry) {
- BT_LOGE_STR("Failed to allocate one variant field type field.");
- goto error;
- }
-
- copy_field = bt_ctf_field_type_copy(entry->type);
- if (!copy_field) {
- BT_LOGE("Cannot copy variant field type's field: "
- "index=%" PRId64 ", "
- "field-ft-addr=%p, field-name=\"%s\"",
- i, entry, g_quark_to_string(entry->name));
- g_free(copy_entry);
- goto error;
- }
-
- copy_entry->name = entry->name;
- copy_entry->type = copy_field;
- g_ptr_array_add(copy_variant->fields, copy_entry);
- }
-
- if (variant->tag_field_path) {
- BT_LOGD_STR("Copying variant field type's tag field path.");
- copy_variant->tag_field_path = bt_ctf_field_path_copy(
- variant->tag_field_path);
- if (!copy_variant->tag_field_path) {
- BT_LOGE_STR("Cannot copy variant field type's tag field path.");
- goto error;
- }
- }
-
- BT_LOGD("Copied variant field type: original-ft-addr=%p, copy-ft-addr=%p",
- type, copy);
-
-end:
- bt_put(copy_tag);
- return copy;
-error:
- bt_put(copy_tag);
- BT_PUT(copy);
- return copy;
-}
-
-static
-struct bt_ctf_field_type *bt_ctf_field_type_array_copy(
- struct bt_ctf_field_type *type)
-{
- struct bt_ctf_field_type *copy = NULL, *copy_element;
- struct bt_ctf_field_type_array *array;
-
- BT_LOGD("Copying array field type's: addr=%p", type);
- array = container_of(type, struct bt_ctf_field_type_array,
- parent);
- BT_LOGD_STR("Copying array field type's element field type.");
- copy_element = bt_ctf_field_type_copy(array->element_type);
- if (!copy_element) {
- BT_LOGE_STR("Cannot copy array field type's element field type.");
- goto end;
- }
-
- copy = bt_ctf_field_type_array_create(copy_element, array->length);
- if (!copy) {
- BT_LOGE_STR("Cannot create array field type.");
- goto end;
- }
-
- BT_LOGD("Copied array field type: original-ft-addr=%p, copy-ft-addr=%p",
- type, copy);
-
-end:
- bt_put(copy_element);
- return copy;
-}
-
-static
-struct bt_ctf_field_type *bt_ctf_field_type_sequence_copy(
- struct bt_ctf_field_type *type)
-{
- struct bt_ctf_field_type *copy = NULL, *copy_element;
- struct bt_ctf_field_type_sequence *sequence, *copy_sequence;
-
- BT_LOGD("Copying sequence field type's: addr=%p", type);
- sequence = container_of(type, struct bt_ctf_field_type_sequence,
- parent);
- BT_LOGD_STR("Copying sequence field type's element field type.");
- copy_element = bt_ctf_field_type_copy(sequence->element_type);
- if (!copy_element) {
- BT_LOGE_STR("Cannot copy sequence field type's element field type.");
- goto end;
- }
-
- copy = bt_ctf_field_type_sequence_create(copy_element,
- sequence->length_field_name->len ?
- sequence->length_field_name->str : NULL);
- if (!copy) {
- BT_LOGE_STR("Cannot create sequence field type.");
- goto end;
- }
-
- copy_sequence = container_of(copy, struct bt_ctf_field_type_sequence,
- parent);
- if (sequence->length_field_path) {
- BT_LOGD_STR("Copying sequence field type's length field path.");
- copy_sequence->length_field_path = bt_ctf_field_path_copy(
- sequence->length_field_path);
- if (!copy_sequence->length_field_path) {
- BT_LOGE_STR("Cannot copy sequence field type's length field path.");
- goto error;
- }
- }
-
- BT_LOGD("Copied sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
- type, copy);
-
-end:
- bt_put(copy_element);
- return copy;
-error:
- BT_PUT(copy);
- goto end;
-}
-
-static
-struct bt_ctf_field_type *bt_ctf_field_type_string_copy(
- struct bt_ctf_field_type *type)
-{
- struct bt_ctf_field_type *copy;
-
- BT_LOGD("Copying string field type's: addr=%p", type);
- copy = bt_ctf_field_type_string_create();
- if (!copy) {
- BT_LOGE_STR("Cannot create string field type.");
- goto end;
- }
-
- BT_LOGD("Copied string field type: original-ft-addr=%p, copy-ft-addr=%p",
- type, copy);
-end:
- return copy;
-}
-
-static
-int bt_ctf_field_type_integer_compare(struct bt_ctf_field_type *type_a,
- struct bt_ctf_field_type *type_b)
-{
- int ret = 1;
- struct bt_ctf_field_type_integer *int_type_a;
- struct bt_ctf_field_type_integer *int_type_b;
-
- int_type_a = container_of(type_a, struct bt_ctf_field_type_integer,
- parent);
- int_type_b = container_of(type_b, struct bt_ctf_field_type_integer,
- parent);