2 * SPDX-License-Identifier: MIT
4 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 #define BT_LOG_TAG "CTF-WRITER/FIELD-TYPES"
15 #include <babeltrace2-ctf-writer/fields.h>
16 #include <babeltrace2-ctf-writer/field-types.h>
17 #include <babeltrace2-ctf-writer/object.h>
18 #include <babeltrace2-ctf-writer/utils.h>
20 #include "common/assert.h"
21 #include "compat/compiler.h"
22 #include "compat/endian.h"
24 #include "assert-pre.h"
25 #include "clock-class.h"
27 #include "field-path.h"
29 #include "field-types.h"
34 void destroy_enumeration_mapping(struct bt_ctf_enumeration_mapping
*mapping
)
40 void bt_ctf_field_type_common_initialize(struct bt_ctf_field_type_common
*ft
,
41 bool init_bo
, bt_ctf_object_release_func release_func
,
42 struct bt_ctf_field_type_common_methods
*methods
)
44 BT_ASSERT_DBG(ft
&& (ft
->id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
) &&
45 (ft
->id
< BT_CTF_FIELD_TYPE_ID_NR
));
47 bt_ctf_object_init_shared(&ft
->base
, release_func
);
48 ft
->methods
= methods
;
52 const enum bt_ctf_byte_order bo
= BT_CTF_BYTE_ORDER_NATIVE
;
54 BT_LOGD("Setting initial field type's byte order: bo=%s",
55 bt_ctf_byte_order_string(bo
));
56 ret
= bt_ctf_field_type_common_set_byte_order(ft
, bo
);
57 BT_ASSERT_DBG(ret
== 0);
64 void bt_ctf_field_type_common_integer_initialize(
65 struct bt_ctf_field_type_common
*ft
,
66 unsigned int size
, bt_ctf_object_release_func release_func
,
67 struct bt_ctf_field_type_common_methods
*methods
)
69 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
71 BT_ASSERT_DBG(size
> 0);
72 BT_LOGD("Initializing common integer field type object: size=%u",
74 ft
->id
= BT_CTF_FIELD_TYPE_ID_INTEGER
;
76 int_ft
->base
= BT_CTF_INTEGER_BASE_DECIMAL
;
77 int_ft
->encoding
= BT_CTF_STRING_ENCODING_NONE
;
78 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
79 BT_LOGD("Initialized common integer field type object: addr=%p, size=%u",
84 void bt_ctf_field_type_common_floating_point_initialize(
85 struct bt_ctf_field_type_common
*ft
,
86 bt_ctf_object_release_func release_func
,
87 struct bt_ctf_field_type_common_methods
*methods
)
89 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
91 BT_LOGD_STR("Initializing common floating point number field type object.");
92 ft
->id
= BT_CTF_FIELD_TYPE_ID_FLOAT
;
93 flt_ft
->exp_dig
= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
;
94 flt_ft
->mant_dig
= FLT_MANT_DIG
;
95 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
96 BT_LOGD("Initialized common floating point number field type object: addr=%p, "
97 "exp-size=%u, mant-size=%u", ft
, flt_ft
->exp_dig
,
102 void bt_ctf_field_type_common_enumeration_initialize(
103 struct bt_ctf_field_type_common
*ft
,
104 struct bt_ctf_field_type_common
*container_ft
,
105 bt_ctf_object_release_func release_func
,
106 struct bt_ctf_field_type_common_methods
*methods
)
108 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
110 BT_ASSERT_DBG(container_ft
);
111 BT_LOGD("Initializing common enumeration field type object: int-ft-addr=%p",
113 ft
->id
= BT_CTF_FIELD_TYPE_ID_ENUM
;
114 enum_ft
->container_ft
= bt_ctf_object_get_ref(container_ft
);
115 enum_ft
->entries
= g_ptr_array_new_with_free_func(
116 (GDestroyNotify
) destroy_enumeration_mapping
);
117 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
118 BT_LOGD("Initialized common enumeration field type object: addr=%p, "
119 "int-ft-addr=%p, int-ft-size=%u", ft
, container_ft
,
120 bt_ctf_field_type_common_integer_get_size(container_ft
));
124 void bt_ctf_field_type_common_string_initialize(
125 struct bt_ctf_field_type_common
*ft
,
126 bt_ctf_object_release_func release_func
,
127 struct bt_ctf_field_type_common_methods
*methods
)
129 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
131 BT_LOGD_STR("Initializing common string field type object.");
132 ft
->id
= BT_CTF_FIELD_TYPE_ID_STRING
;
133 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
134 string_ft
->encoding
= BT_CTF_STRING_ENCODING_UTF8
;
135 ft
->alignment
= CHAR_BIT
;
136 BT_LOGD("Initialized common string field type object: addr=%p", ft
);
140 void bt_ctf_field_type_common_structure_initialize(
141 struct bt_ctf_field_type_common
*ft
,
142 bt_ctf_object_release_func release_func
,
143 struct bt_ctf_field_type_common_methods
*methods
)
145 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
147 BT_LOGD_STR("Initializing common structure field type object.");
148 ft
->id
= BT_CTF_FIELD_TYPE_ID_STRUCT
;
149 struct_ft
->fields
= g_array_new(FALSE
, TRUE
,
150 sizeof(struct bt_ctf_field_type_common_structure_field
));
151 struct_ft
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
152 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
153 BT_LOGD("Initialized common structure field type object: addr=%p", ft
);
157 void bt_ctf_field_type_common_array_initialize(
158 struct bt_ctf_field_type_common
*ft
,
159 struct bt_ctf_field_type_common
*element_ft
,
160 unsigned int length
, bt_ctf_object_release_func release_func
,
161 struct bt_ctf_field_type_common_methods
*methods
)
163 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
165 BT_ASSERT_DBG(element_ft
);
166 BT_LOGD("Initializing common array field type object: element-ft-addr=%p, "
167 "length=%u", element_ft
, length
);
168 ft
->id
= BT_CTF_FIELD_TYPE_ID_ARRAY
;
169 array_ft
->element_ft
= bt_ctf_object_get_ref(element_ft
);
170 array_ft
->length
= length
;
171 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
172 BT_LOGD("Initialized common array field type object: addr=%p, "
173 "element-ft-addr=%p, length=%u", ft
, element_ft
, length
);
177 void bt_ctf_field_type_common_sequence_initialize(
178 struct bt_ctf_field_type_common
*ft
,
179 struct bt_ctf_field_type_common
*element_ft
,
180 const char *length_field_name
,
181 bt_ctf_object_release_func release_func
,
182 struct bt_ctf_field_type_common_methods
*methods
)
184 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
186 BT_ASSERT_DBG(element_ft
);
187 BT_ASSERT_DBG(length_field_name
);
188 BT_ASSERT_DBG(bt_ctf_identifier_is_valid(length_field_name
));
189 BT_LOGD("Initializing common sequence field type object: element-ft-addr=%p, "
190 "length-field-name=\"%s\"", element_ft
, length_field_name
);
191 ft
->id
= BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
192 seq_ft
->element_ft
= bt_ctf_object_get_ref(element_ft
);
193 seq_ft
->length_field_name
= g_string_new(length_field_name
);
194 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
195 BT_LOGD("Initialized common sequence field type object: addr=%p, "
196 "element-ft-addr=%p, length-field-name=\"%s\"",
197 ft
, element_ft
, length_field_name
);
201 void bt_ctf_field_type_common_variant_initialize(
202 struct bt_ctf_field_type_common
*ft
,
203 struct bt_ctf_field_type_common
*tag_ft
,
204 const char *tag_name
,
205 bt_ctf_object_release_func release_func
,
206 struct bt_ctf_field_type_common_methods
*methods
)
208 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
210 BT_ASSERT_DBG(!tag_name
|| bt_ctf_identifier_is_valid(tag_name
));
211 BT_LOGD("Initializing common variant field type object: "
212 "tag-ft-addr=%p, tag-field-name=\"%s\"",
214 ft
->id
= BT_CTF_FIELD_TYPE_ID_VARIANT
;
215 var_ft
->tag_name
= g_string_new(tag_name
);
216 var_ft
->choice_name_to_index
= g_hash_table_new(NULL
, NULL
);
217 var_ft
->choices
= g_array_new(FALSE
, TRUE
,
218 sizeof(struct bt_ctf_field_type_common_variant_choice
));
221 var_ft
->tag_ft
= bt_ctf_object_get_ref(tag_ft
);
224 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
225 /* A variant's alignment is undefined */
227 BT_LOGD("Initialized common variant field type object: addr=%p, "
228 "tag-ft-addr=%p, tag-field-name=\"%s\"",
229 ft
, tag_ft
, tag_name
);
233 void bt_ctf_field_type_common_integer_destroy(struct bt_ctf_object
*obj
)
235 struct bt_ctf_field_type_common_integer
*ft
= (void *) obj
;
241 BT_LOGD("Destroying integer field type object: addr=%p", ft
);
242 BT_LOGD_STR("Putting mapped clock class.");
243 bt_ctf_object_put_ref(ft
->mapped_clock_class
);
248 void bt_ctf_field_type_common_floating_point_destroy(struct bt_ctf_object
*obj
)
250 struct bt_ctf_field_type_common_floating_point
*ft
= (void *) obj
;
256 BT_LOGD("Destroying floating point number field type object: addr=%p", ft
);
261 void bt_ctf_field_type_common_enumeration_destroy_recursive(struct bt_ctf_object
*obj
)
263 struct bt_ctf_field_type_common_enumeration
*ft
= (void *) obj
;
269 BT_LOGD("Destroying enumeration field type object: addr=%p", ft
);
270 g_ptr_array_free(ft
->entries
, TRUE
);
271 BT_LOGD_STR("Putting container field type.");
272 bt_ctf_object_put_ref(ft
->container_ft
);
277 void bt_ctf_field_type_common_string_destroy(struct bt_ctf_object
*obj
)
279 struct bt_ctf_field_type_common_string
*ft
= (void *) obj
;
285 BT_LOGD("Destroying string field type object: addr=%p", ft
);
290 void bt_ctf_field_type_common_structure_field_finalize(
291 struct bt_ctf_field_type_common_structure_field
*field
)
297 BT_LOGD("Finalizing structure field type's field: "
298 "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
299 field
, field
->type
, g_quark_to_string(field
->name
));
300 BT_LOGD_STR("Putting field type.");
301 bt_ctf_object_put_ref(field
->type
);
305 void bt_ctf_field_type_common_structure_destroy_recursive(struct bt_ctf_object
*obj
)
307 struct bt_ctf_field_type_common_structure
*ft
= (void *) obj
;
314 BT_LOGD("Destroying structure field type object: addr=%p", ft
);
317 for (i
= 0; i
< ft
->fields
->len
; i
++) {
318 bt_ctf_field_type_common_structure_field_finalize(
319 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
323 g_array_free(ft
->fields
, TRUE
);
326 if (ft
->field_name_to_index
) {
327 g_hash_table_destroy(ft
->field_name_to_index
);
334 void bt_ctf_field_type_common_array_destroy_recursive(struct bt_ctf_object
*obj
)
336 struct bt_ctf_field_type_common_array
*ft
= (void *) obj
;
342 BT_LOGD("Destroying array field type object: addr=%p", ft
);
343 BT_LOGD_STR("Putting element field type.");
344 bt_ctf_object_put_ref(ft
->element_ft
);
349 void bt_ctf_field_type_common_sequence_destroy_recursive(struct bt_ctf_object
*obj
)
351 struct bt_ctf_field_type_common_sequence
*ft
= (void *) obj
;
357 BT_LOGD("Destroying sequence field type object: addr=%p", ft
);
358 BT_LOGD_STR("Putting element field type.");
359 bt_ctf_object_put_ref(ft
->element_ft
);
360 g_string_free(ft
->length_field_name
, TRUE
);
361 BT_LOGD_STR("Putting length field path.");
362 bt_ctf_object_put_ref(ft
->length_field_path
);
367 void bt_ctf_field_type_common_variant_choice_finalize(
368 struct bt_ctf_field_type_common_variant_choice
*choice
)
374 BT_LOGD("Finalizing variant field type's choice: "
375 "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
376 choice
, choice
->type
, g_quark_to_string(choice
->name
));
377 BT_LOGD_STR("Putting field type.");
378 bt_ctf_object_put_ref(choice
->type
);
380 if (choice
->ranges
) {
381 g_array_free(choice
->ranges
, TRUE
);
386 void bt_ctf_field_type_common_variant_destroy_recursive(struct bt_ctf_object
*obj
)
388 struct bt_ctf_field_type_common_variant
*ft
= (void *) obj
;
395 BT_LOGD("Destroying variant field type object: addr=%p", ft
);
398 for (i
= 0; i
< ft
->choices
->len
; i
++) {
399 bt_ctf_field_type_common_variant_choice_finalize(
400 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
404 g_array_free(ft
->choices
, TRUE
);
407 if (ft
->choice_name_to_index
) {
408 g_hash_table_destroy(ft
->choice_name_to_index
);
412 g_string_free(ft
->tag_name
, TRUE
);
415 BT_LOGD_STR("Putting tag field type.");
416 bt_ctf_object_put_ref(ft
->tag_ft
);
417 BT_LOGD_STR("Putting tag field path.");
418 bt_ctf_object_put_ref(ft
->tag_field_path
);
422 struct range_overlap_query
{
437 void check_ranges_overlap(gpointer element
, gpointer query
)
439 struct bt_ctf_enumeration_mapping
*mapping
= element
;
440 struct range_overlap_query
*overlap_query
= query
;
442 if (mapping
->range_start
._signed
<= overlap_query
->range_end
._signed
443 && overlap_query
->range_start
._signed
<=
444 mapping
->range_end
._signed
) {
445 overlap_query
->overlaps
= 1;
446 overlap_query
->mapping_name
= mapping
->string
;
449 overlap_query
->overlaps
|=
450 mapping
->string
== overlap_query
->mapping_name
;
452 if (overlap_query
->overlaps
) {
453 BT_LOGT("Overlapping enumeration field type mappings: "
454 "mapping-name=\"%s\", "
455 "mapping-a-range-start=%" PRId64
", "
456 "mapping-a-range-end=%" PRId64
", "
457 "mapping-b-range-start=%" PRId64
", "
458 "mapping-b-range-end=%" PRId64
,
459 g_quark_to_string(mapping
->string
),
460 mapping
->range_start
._signed
,
461 mapping
->range_end
._signed
,
462 overlap_query
->range_start
._signed
,
463 overlap_query
->range_end
._signed
);
468 void check_ranges_overlap_unsigned(gpointer element
, gpointer query
)
470 struct bt_ctf_enumeration_mapping
*mapping
= element
;
471 struct range_overlap_query
*overlap_query
= query
;
473 if (mapping
->range_start
._unsigned
<= overlap_query
->range_end
._unsigned
474 && overlap_query
->range_start
._unsigned
<=
475 mapping
->range_end
._unsigned
) {
476 overlap_query
->overlaps
= 1;
477 overlap_query
->mapping_name
= mapping
->string
;
480 overlap_query
->overlaps
|=
481 mapping
->string
== overlap_query
->mapping_name
;
483 if (overlap_query
->overlaps
) {
484 BT_LOGW("Overlapping enumeration field type mappings: "
485 "mapping-name=\"%s\", "
486 "mapping-a-range-start=%" PRIu64
", "
487 "mapping-a-range-end=%" PRIu64
", "
488 "mapping-b-range-start=%" PRIu64
", "
489 "mapping-b-range-end=%" PRIu64
,
490 g_quark_to_string(mapping
->string
),
491 mapping
->range_start
._unsigned
,
492 mapping
->range_end
._unsigned
,
493 overlap_query
->range_start
._unsigned
,
494 overlap_query
->range_end
._unsigned
);
499 gint
compare_enumeration_mappings_signed(struct bt_ctf_enumeration_mapping
**a
,
500 struct bt_ctf_enumeration_mapping
**b
)
502 return ((*a
)->range_start
._signed
< (*b
)->range_start
._signed
) ? -1 : 1;
506 gint
compare_enumeration_mappings_unsigned(struct bt_ctf_enumeration_mapping
**a
,
507 struct bt_ctf_enumeration_mapping
**b
)
509 return ((*a
)->range_start
._unsigned
< (*b
)->range_start
._unsigned
) ? -1 : 1;
513 int add_structure_variant_member(GArray
*members
,
514 GHashTable
*field_name_to_index
,
515 struct bt_ctf_field_type_common
*field_type
, const char *field_name
,
519 GQuark name_quark
= g_quark_from_string(field_name
);
520 struct bt_ctf_field_type_common
**member_ft
;
523 /* Make sure structure does not contain a field of the same name */
524 if (g_hash_table_lookup_extended(field_name_to_index
,
525 GUINT_TO_POINTER(name_quark
), NULL
, NULL
)) {
526 BT_LOGW("Structure or variant field type already contains a field type with this name: "
527 "field-name=\"%s\"", field_name
);
532 g_array_set_size(members
, members
->len
+ 1);
535 struct bt_ctf_field_type_common_variant_choice
*choice
=
536 &g_array_index(members
,
537 struct bt_ctf_field_type_common_variant_choice
,
540 member_ft
= &choice
->type
;
541 member_name
= &choice
->name
;
542 BT_ASSERT_DBG(!choice
->ranges
);
543 choice
->ranges
= g_array_new(FALSE
, TRUE
,
544 sizeof(struct bt_ctf_field_type_common_variant_choice_range
));
545 BT_ASSERT_DBG(choice
->ranges
);
547 struct bt_ctf_field_type_common_structure_field
*field
=
548 &g_array_index(members
,
549 struct bt_ctf_field_type_common_structure_field
,
552 member_ft
= &field
->type
;
553 member_name
= &field
->name
;
556 *member_name
= name_quark
;
557 *member_ft
= bt_ctf_object_get_ref(field_type
);
558 g_hash_table_insert(field_name_to_index
,
559 GUINT_TO_POINTER(name_quark
),
560 GUINT_TO_POINTER(members
->len
- 1));
561 BT_LOGT("Added structure/variant field type member: member-ft-addr=%p, "
562 "member-name=\"%s\"", field_type
, field_name
);
569 int bt_ctf_field_type_common_integer_validate(struct bt_ctf_field_type_common
*ft
)
572 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
574 if (int_ft
->mapped_clock_class
&& int_ft
->is_signed
) {
575 BT_LOGW("Invalid integer field type: cannot be signed and have a mapped clock class: "
576 "ft-addr=%p, clock-class-addr=%p, clock-class-name=\"%s\"",
577 ft
, int_ft
->mapped_clock_class
,
578 bt_ctf_clock_class_get_name(int_ft
->mapped_clock_class
));
588 void bt_ctf_field_type_enum_iter_destroy(struct bt_ctf_object
*obj
)
590 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
592 struct bt_ctf_field_type_enumeration_mapping_iterator
,
595 BT_LOGD("Destroying enumeration field type mapping iterator: addr=%p",
597 BT_LOGD_STR("Putting parent enumeration field type.");
598 bt_ctf_object_put_ref(iter
->enumeration_ft
);
603 struct bt_ctf_field_type_enumeration_mapping_iterator
*
604 bt_ctf_field_type_common_enumeration_find_mappings_type(
605 struct bt_ctf_field_type_common
*ft
,
606 enum bt_ctf_field_type_enumeration_mapping_iterator_type iterator_type
)
608 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
610 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
611 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
,
613 iter
= g_new0(struct bt_ctf_field_type_enumeration_mapping_iterator
, 1);
615 BT_LOGE_STR("Failed to allocate one enumeration field type mapping.");
619 bt_ctf_object_init_shared(&iter
->base
, bt_ctf_field_type_enum_iter_destroy
);
620 iter
->enumeration_ft
= bt_ctf_object_get_ref(ft
);
622 iter
->type
= iterator_type
;
629 struct bt_ctf_field_type_enumeration_mapping_iterator
*
630 bt_ctf_field_type_common_enumeration_find_mappings_by_name(
631 struct bt_ctf_field_type_common
*ft
, const char *name
)
633 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
635 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
636 ft
, CTF_ITERATOR_BY_NAME
);
638 BT_LOGW("Cannot create enumeration field type mapping iterator: "
639 "ft-addr=%p, mapping-name=\"%s\"", ft
, name
);
643 iter
->u
.name_quark
= g_quark_try_string(name
);
644 if (!iter
->u
.name_quark
) {
646 * No results are possible, set the iterator's position at the
649 iter
->index
= iter
->enumeration_ft
->entries
->len
;
655 bt_ctf_object_put_ref(iter
);
660 struct bt_ctf_enumeration_mapping
*bt_ctf_field_type_common_enumeration_get_mapping_by_index(
661 struct bt_ctf_field_type_common
*ft
, uint64_t index
)
663 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
664 struct bt_ctf_enumeration_mapping
*mapping
= NULL
;
666 if (index
>= enum_ft
->entries
->len
) {
667 BT_LOGW("Invalid parameter: index is out of bounds: "
668 "addr=%p, index=%" PRIu64
", count=%u",
669 ft
, index
, enum_ft
->entries
->len
);
673 mapping
= g_ptr_array_index(enum_ft
->entries
, index
);
680 int bt_ctf_field_type_enumeration_mapping_iterator_next(
681 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
)
683 struct bt_ctf_field_type_common_enumeration
*enum_ft
= iter
->enumeration_ft
;
686 BT_CTF_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
687 len
= enum_ft
->entries
->len
;
688 for (i
= iter
->index
+ 1; i
< len
; i
++) {
689 struct bt_ctf_enumeration_mapping
*mapping
=
690 bt_ctf_field_type_common_enumeration_get_mapping_by_index(
691 BT_CTF_TO_COMMON(enum_ft
), i
);
693 switch (iter
->type
) {
694 case CTF_ITERATOR_BY_NAME
:
695 if (mapping
->string
== iter
->u
.name_quark
) {
700 case CTF_ITERATOR_BY_SIGNED_VALUE
:
702 int64_t value
= iter
->u
.signed_value
;
704 if (value
>= mapping
->range_start
._signed
&&
705 value
<= mapping
->range_end
._signed
) {
711 case CTF_ITERATOR_BY_UNSIGNED_VALUE
:
713 uint64_t value
= iter
->u
.unsigned_value
;
715 if (value
>= mapping
->range_start
._unsigned
&&
716 value
<= mapping
->range_end
._unsigned
) {
723 BT_LOGF("Invalid enumeration field type mapping iterator type: "
724 "type=%d", iter
->type
);
736 struct bt_ctf_field_type_enumeration_mapping_iterator
*
737 bt_ctf_field_type_common_enumeration_signed_find_mappings_by_value(
738 struct bt_ctf_field_type_common
*ft
, int64_t value
)
740 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
742 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
743 ft
, CTF_ITERATOR_BY_SIGNED_VALUE
);
745 BT_LOGW("Cannot create enumeration field type mapping iterator: "
746 "ft-addr=%p, value=%" PRId64
, ft
, value
);
750 if (bt_ctf_field_type_common_integer_is_signed(
751 BT_CTF_TO_COMMON(iter
->enumeration_ft
->container_ft
)) != 1) {
752 BT_LOGW("Invalid parameter: enumeration field type is unsigned: "
753 "enum-ft-addr=%p, int-ft-addr=%p",
754 ft
, iter
->enumeration_ft
->container_ft
);
758 iter
->u
.signed_value
= value
;
762 bt_ctf_object_put_ref(iter
);
767 struct bt_ctf_field_type_enumeration_mapping_iterator
*
768 bt_ctf_field_type_common_enumeration_unsigned_find_mappings_by_value(
769 struct bt_ctf_field_type_common
*ft
, uint64_t value
)
771 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
773 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
774 ft
, CTF_ITERATOR_BY_UNSIGNED_VALUE
);
776 BT_LOGW("Cannot create enumeration field type mapping iterator: "
777 "ft-addr=%p, value=%" PRIu64
, ft
, value
);
781 if (bt_ctf_field_type_common_integer_is_signed(
782 BT_CTF_TO_COMMON(iter
->enumeration_ft
->container_ft
)) != 0) {
783 BT_LOGW("Invalid parameter: enumeration field type is signed: "
784 "enum-ft-addr=%p, int-ft-addr=%p",
785 ft
, iter
->enumeration_ft
->container_ft
);
789 iter
->u
.unsigned_value
= value
;
793 bt_ctf_object_put_ref(iter
);
798 int bt_ctf_field_type_enumeration_mapping_iterator_signed_get(
799 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
800 const char **mapping_name
, int64_t *range_begin
,
803 BT_CTF_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
804 BT_CTF_ASSERT_PRE(iter
->index
!= -1,
805 "Invalid enumeration field type mapping iterator access: "
806 "addr=%p, position=-1", iter
);
807 return bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
808 (void *) iter
->enumeration_ft
, iter
->index
,
809 mapping_name
, range_begin
, range_end
);
813 int bt_ctf_field_type_enumeration_mapping_iterator_unsigned_get(
814 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
815 const char **mapping_name
, uint64_t *range_begin
,
818 BT_CTF_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
819 BT_CTF_ASSERT_PRE(iter
->index
!= -1,
820 "Invalid enumeration field type mapping iterator access: "
821 "addr=%p, position=-1", iter
);
822 return bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
823 (void *) iter
->enumeration_ft
, iter
->index
,
824 mapping_name
, range_begin
, range_end
);
828 * Note: This algorithm is O(n^2) vs number of enumeration mappings.
829 * Only used when freezing an enumeration.
832 void bt_ctf_field_type_common_enumeration_set_range_overlap(
833 struct bt_ctf_field_type_common_enumeration
*ft
)
838 BT_LOGT("Setting enumeration field type's overlap flag: addr=%p",
840 len
= ft
->entries
->len
;
841 is_signed
= bt_ctf_field_type_common_integer_is_signed(
842 BT_CTF_TO_COMMON(ft
->container_ft
));
844 for (i
= 0; i
< len
; i
++) {
845 for (j
= i
+ 1; j
< len
; j
++) {
846 struct bt_ctf_enumeration_mapping
*mapping
[2];
848 mapping
[0] = bt_ctf_field_type_common_enumeration_get_mapping_by_index(
849 BT_CTF_TO_COMMON(ft
), i
);
850 mapping
[1] = bt_ctf_field_type_common_enumeration_get_mapping_by_index(
851 BT_CTF_TO_COMMON(ft
), j
);
853 if (mapping
[0]->range_start
._signed
854 <= mapping
[1]->range_end
._signed
855 && mapping
[0]->range_end
._signed
856 >= mapping
[1]->range_start
._signed
) {
857 ft
->has_overlapping_ranges
= BT_CTF_TRUE
;
861 if (mapping
[0]->range_start
._unsigned
862 <= mapping
[1]->range_end
._unsigned
863 && mapping
[0]->range_end
._unsigned
864 >= mapping
[1]->range_start
._unsigned
) {
865 ft
->has_overlapping_ranges
= BT_CTF_TRUE
;
873 if (ft
->has_overlapping_ranges
) {
874 BT_LOGT_STR("Enumeration field type has overlapping ranges.");
876 BT_LOGT_STR("Enumeration field type has no overlapping ranges.");
881 int bt_ctf_field_type_common_enumeration_validate_recursive(
882 struct bt_ctf_field_type_common
*ft
)
885 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
887 ret
= bt_ctf_field_type_common_integer_validate(
888 BT_CTF_TO_COMMON(enum_ft
->container_ft
));
890 BT_LOGW("Invalid enumeration field type: container type is invalid: "
891 "enum-ft-addr=%p, int-ft-addr=%p",
892 ft
, enum_ft
->container_ft
);
896 /* Ensure enum has entries */
897 if (enum_ft
->entries
->len
== 0) {
898 BT_LOGW("Invalid enumeration field type: no entries: "
909 int bt_ctf_field_type_common_sequence_validate_recursive(
910 struct bt_ctf_field_type_common
*ft
)
913 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
915 /* Length field name should be set at this point */
916 if (seq_ft
->length_field_name
->len
== 0) {
917 BT_LOGW("Invalid sequence field type: no length field name: "
923 ret
= bt_ctf_field_type_common_validate(seq_ft
->element_ft
);
925 BT_LOGW("Invalid sequence field type: invalid element field type: "
926 "seq-ft-addr=%p, element-ft-add=%p",
927 ft
, seq_ft
->element_ft
);
935 int bt_ctf_field_type_common_array_validate_recursive(
936 struct bt_ctf_field_type_common
*ft
)
939 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
941 ret
= bt_ctf_field_type_common_validate(array_ft
->element_ft
);
943 BT_LOGW("Invalid array field type: invalid element field type: "
944 "array-ft-addr=%p, element-ft-add=%p",
945 ft
, array_ft
->element_ft
);
952 int bt_ctf_field_type_common_structure_validate_recursive(
953 struct bt_ctf_field_type_common
*ft
)
956 struct bt_ctf_field_type_common
*child_ft
= NULL
;
957 int64_t field_count
=
958 bt_ctf_field_type_common_structure_get_field_count(ft
);
961 BT_ASSERT_DBG(field_count
>= 0);
963 for (i
= 0; i
< field_count
; ++i
) {
964 const char *field_name
;
966 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(ft
,
967 &field_name
, &child_ft
, i
);
968 BT_ASSERT_DBG(ret
== 0);
969 ret
= bt_ctf_field_type_common_validate(child_ft
);
971 BT_LOGW("Invalid structure field type: "
972 "a contained field type is invalid: "
973 "struct-ft-addr=%p, field-ft-addr=%p, "
974 "field-name=\"%s\", field-index=%" PRId64
,
975 ft
, child_ft
, field_name
, i
);
985 bt_ctf_bool
bt_ctf_field_type_common_enumeration_has_overlapping_ranges(
986 struct bt_ctf_field_type_common_enumeration
*enum_ft
)
988 if (!enum_ft
->common
.frozen
) {
989 bt_ctf_field_type_common_enumeration_set_range_overlap(enum_ft
);
992 return enum_ft
->has_overlapping_ranges
;
996 int bt_ctf_field_type_common_variant_validate_recursive(
997 struct bt_ctf_field_type_common
*ft
)
1000 int64_t field_count
;
1001 struct bt_ctf_field_type_common
*child_ft
= NULL
;
1002 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
1005 if (var_ft
->tag_name
->len
== 0) {
1006 BT_LOGW("Invalid variant field type: no tag field name: "
1012 if (!var_ft
->tag_ft
) {
1013 BT_LOGW("Invalid variant field type: no tag field type: "
1014 "addr=%p, tag-field-name=\"%s\"", var_ft
,
1015 var_ft
->tag_name
->str
);
1020 if (bt_ctf_field_type_common_enumeration_has_overlapping_ranges(var_ft
->tag_ft
)) {
1021 BT_LOGW("Invalid variant field type: enumeration tag field type has overlapping ranges: "
1022 "variant-ft-addr=%p, tag-field-name=\"%s\", "
1023 "enum-ft-addr=%p", ft
, var_ft
->tag_name
->str
,
1030 * It is valid to have a variant field type which does not have
1031 * the fields corresponding to each label in the associated
1034 * It is also valid to have variant field type fields which
1035 * cannot be selected because the variant field type tag has no
1036 * mapping named as such. This scenario, while not ideal, cannot
1039 * If a non-existing field happens to be selected by an
1040 * enumeration while reading a variant field, an error will be
1041 * generated at that point (while reading the stream).
1043 field_count
= bt_ctf_field_type_common_variant_get_field_count(ft
);
1044 if (field_count
< 0) {
1045 BT_LOGW("Invalid variant field type: no fields: "
1046 "addr=%p, tag-field-name=\"%s\"",
1047 ft
, var_ft
->tag_name
->str
);
1052 for (i
= 0; i
< field_count
; ++i
) {
1053 const char *field_name
;
1055 ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(ft
,
1056 &field_name
, &child_ft
, i
);
1057 BT_ASSERT_DBG(ret
== 0);
1058 ret
= bt_ctf_field_type_common_validate(child_ft
);
1060 BT_LOGW("Invalid variant field type: "
1061 "a contained field type is invalid: "
1062 "variant-ft-addr=%p, tag-field-name=\"%s\", "
1063 "field-ft-addr=%p, field-name=\"%s\", "
1064 "field-index=%" PRId64
,
1065 ft
, var_ft
->tag_name
->str
, child_ft
,
1076 * This function validates a given field type without considering
1077 * where this field type is located. It only validates the properties
1078 * of the given field type and the properties of its children if
1082 int bt_ctf_field_type_common_validate(struct bt_ctf_field_type_common
*ft
)
1089 /* Already marked as valid */
1093 if (ft
->methods
->validate
) {
1094 ret
= ft
->methods
->validate(ft
);
1097 if (ret
== 0 && ft
->frozen
) {
1098 /* Field type is valid */
1099 BT_LOGT("Marking field type as valid: addr=%p", ft
);
1108 int bt_ctf_field_type_common_integer_get_size(struct bt_ctf_field_type_common
*ft
)
1110 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1112 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1113 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1115 return (int) int_ft
->size
;
1119 bt_ctf_bool
bt_ctf_field_type_common_integer_is_signed(struct bt_ctf_field_type_common
*ft
)
1121 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1123 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1124 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1126 return int_ft
->is_signed
;
1130 int bt_ctf_field_type_common_integer_set_is_signed(struct bt_ctf_field_type_common
*ft
,
1131 bt_ctf_bool is_signed
)
1134 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1137 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1143 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1149 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1150 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1151 "addr=%p, ft-id=%s", ft
,
1152 bt_ctf_field_type_id_string(ft
->id
));
1157 int_ft
->is_signed
= !!is_signed
;
1158 BT_LOGT("Set integer field type's signedness: addr=%p, is-signed=%d",
1166 int bt_ctf_field_type_common_integer_set_size(struct bt_ctf_field_type_common
*ft
,
1170 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1173 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1179 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1185 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1186 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1187 "addr=%p, ft-id=%s", ft
,
1188 bt_ctf_field_type_id_string(ft
->id
));
1193 if (size
== 0 || size
> 64) {
1194 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
1195 "addr=%p, size=%u", ft
, size
);
1200 int_ft
->size
= size
;
1201 BT_LOGT("Set integer field type's size: addr=%p, size=%u",
1209 enum bt_ctf_integer_base
bt_ctf_field_type_common_integer_get_base(
1210 struct bt_ctf_field_type_common
*ft
)
1212 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1214 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1215 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1217 return int_ft
->base
;
1221 int bt_ctf_field_type_common_integer_set_base(struct bt_ctf_field_type_common
*ft
,
1222 enum bt_ctf_integer_base base
)
1225 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1228 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1234 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1240 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1241 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1242 "addr=%p, ft-id=%s", ft
,
1243 bt_ctf_field_type_id_string(ft
->id
));
1249 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
1250 case BT_CTF_INTEGER_BASE_BINARY
:
1251 case BT_CTF_INTEGER_BASE_OCTAL
:
1252 case BT_CTF_INTEGER_BASE_DECIMAL
:
1253 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
1255 int_ft
->base
= base
;
1259 BT_LOGW("Invalid parameter: unknown integer field type base: "
1260 "addr=%p, base=%d", ft
, base
);
1264 BT_LOGT("Set integer field type's base: addr=%p, base=%s",
1265 ft
, bt_ctf_integer_base_string(base
));
1272 enum bt_ctf_string_encoding
bt_ctf_field_type_common_integer_get_encoding(
1273 struct bt_ctf_field_type_common
*ft
)
1275 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1277 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1278 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1280 return int_ft
->encoding
;
1284 int bt_ctf_field_type_common_integer_set_encoding(struct bt_ctf_field_type_common
*ft
,
1285 enum bt_ctf_string_encoding encoding
)
1288 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1291 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1297 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1303 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1304 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1305 "addr=%p, ft-id=%s", ft
,
1306 bt_ctf_field_type_id_string(ft
->id
));
1311 if (encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
1312 encoding
!= BT_CTF_STRING_ENCODING_ASCII
&&
1313 encoding
!= BT_CTF_STRING_ENCODING_NONE
) {
1314 BT_LOGW("Invalid parameter: unknown string encoding: "
1315 "addr=%p, encoding=%d", ft
, encoding
);
1320 int_ft
->encoding
= encoding
;
1321 BT_LOGT("Set integer field type's encoding: addr=%p, encoding=%s",
1322 ft
, bt_ctf_string_encoding_string(encoding
));
1329 struct bt_ctf_clock_class
*bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
1330 struct bt_ctf_field_type_common
*ft
)
1332 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1334 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1335 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1337 return int_ft
->mapped_clock_class
;
1341 int bt_ctf_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
1342 struct bt_ctf_field_type_common
*ft
,
1343 struct bt_ctf_clock_class
*clock_class
)
1345 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1349 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
1354 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1355 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1356 "addr=%p, ft-id=%s", ft
,
1357 bt_ctf_field_type_id_string(ft
->id
));
1361 if (!bt_ctf_clock_class_is_valid(clock_class
)) {
1362 BT_LOGW("Invalid parameter: clock class is invalid: ft-addr=%p"
1363 "clock-class-addr=%p, clock-class-name=\"%s\"",
1365 bt_ctf_clock_class_get_name(clock_class
));
1370 bt_ctf_object_put_ref(int_ft
->mapped_clock_class
);
1371 int_ft
->mapped_clock_class
= bt_ctf_object_get_ref(clock_class
);
1372 BT_LOGT("Set integer field type's mapped clock class: ft-addr=%p, "
1373 "clock-class-addr=%p, clock-class-name=\"%s\"",
1374 ft
, clock_class
, bt_ctf_clock_class_get_name(clock_class
));
1381 int bt_ctf_field_type_common_integer_set_mapped_clock_class(
1382 struct bt_ctf_field_type_common
*ft
,
1383 struct bt_ctf_clock_class
*clock_class
)
1388 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1394 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1400 ret
= bt_ctf_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
1408 int bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
1409 struct bt_ctf_field_type_common
*ft
, uint64_t index
,
1410 const char **mapping_name
, int64_t *range_begin
,
1414 struct bt_ctf_enumeration_mapping
*mapping
;
1416 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1417 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
,
1418 BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1419 mapping
= bt_ctf_field_type_common_enumeration_get_mapping_by_index(ft
,
1422 /* bt_ctf_field_type_common_enumeration_get_mapping_by_index() logs errors */
1428 *mapping_name
= g_quark_to_string(mapping
->string
);
1429 BT_ASSERT_DBG(*mapping_name
);
1433 *range_begin
= mapping
->range_start
._signed
;
1437 *range_end
= mapping
->range_end
._signed
;
1445 int bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
1446 struct bt_ctf_field_type_common
*ft
, uint64_t index
,
1447 const char **mapping_name
, uint64_t *range_begin
,
1448 uint64_t *range_end
)
1451 struct bt_ctf_enumeration_mapping
*mapping
;
1453 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1454 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1455 mapping
= bt_ctf_field_type_common_enumeration_get_mapping_by_index(
1458 /* bt_ctf_field_type_common_enumeration_get_mapping_by_index() reports any error */
1464 *mapping_name
= g_quark_to_string(mapping
->string
);
1465 BT_ASSERT_DBG(*mapping_name
);
1469 *range_begin
= mapping
->range_start
._unsigned
;
1473 *range_end
= mapping
->range_end
._unsigned
;
1481 struct bt_ctf_field_type_common
*
1482 bt_ctf_field_type_common_enumeration_borrow_container_field_type(
1483 struct bt_ctf_field_type_common
*ft
)
1485 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1487 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1488 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1489 return BT_CTF_TO_COMMON(enum_ft
->container_ft
);
1493 int bt_ctf_field_type_common_enumeration_signed_add_mapping(
1494 struct bt_ctf_field_type_common
*ft
, const char *string
,
1495 int64_t range_start
, int64_t range_end
)
1498 GQuark mapping_name
;
1499 struct bt_ctf_enumeration_mapping
*mapping
;
1500 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1501 char *escaped_string
;
1504 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1510 BT_LOGW_STR("Invalid parameter: string is NULL.");
1516 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1522 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1523 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1524 "addr=%p, ft-id=%s", ft
,
1525 bt_ctf_field_type_id_string(ft
->id
));
1530 if (range_end
< range_start
) {
1531 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1532 "addr=%p, range-start=%" PRId64
", range-end=%" PRId64
,
1533 ft
, range_start
, range_end
);
1538 if (strlen(string
) == 0) {
1539 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1540 "enum-ft-addr=%p, mapping-name-addr=%p", ft
,
1546 escaped_string
= g_strescape(string
, NULL
);
1547 if (!escaped_string
) {
1548 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1549 "mapping-name-addr=%p, mapping-name=\"%s\"",
1550 ft
, string
, string
);
1555 mapping
= g_new(struct bt_ctf_enumeration_mapping
, 1);
1557 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1561 mapping_name
= g_quark_from_string(escaped_string
);
1562 *mapping
= (struct bt_ctf_enumeration_mapping
) {
1563 .range_start
._signed
= range_start
,
1564 .range_end
._signed
= range_end
,
1565 .string
= mapping_name
,
1567 g_ptr_array_add(enum_ft
->entries
, mapping
);
1568 g_ptr_array_sort(enum_ft
->entries
,
1569 (GCompareFunc
) compare_enumeration_mappings_signed
);
1570 BT_LOGT("Added mapping to signed enumeration field type: addr=%p, "
1571 "name=\"%s\", range-start=%" PRId64
", "
1572 "range-end=%" PRId64
,
1573 ft
, string
, range_start
, range_end
);
1576 free(escaped_string
);
1583 int bt_ctf_field_type_common_enumeration_unsigned_add_mapping(
1584 struct bt_ctf_field_type_common
*ft
, const char *string
,
1585 uint64_t range_start
, uint64_t range_end
)
1588 GQuark mapping_name
;
1589 struct bt_ctf_enumeration_mapping
*mapping
;
1590 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1591 char *escaped_string
;
1594 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1600 BT_LOGW_STR("Invalid parameter: string is NULL.");
1606 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1612 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1613 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1614 "addr=%p, ft-id=%s", ft
,
1615 bt_ctf_field_type_id_string(ft
->id
));
1620 if (range_end
< range_start
) {
1621 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1622 "addr=%p, range-start=%" PRIu64
", range-end=%" PRIu64
,
1623 ft
, range_start
, range_end
);
1628 if (strlen(string
) == 0) {
1629 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1630 "enum-ft-addr=%p, mapping-name-addr=%p", ft
,
1636 escaped_string
= g_strescape(string
, NULL
);
1637 if (!escaped_string
) {
1638 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1639 "mapping-name-addr=%p, mapping-name=\"%s\"",
1640 ft
, string
, string
);
1645 mapping
= g_new(struct bt_ctf_enumeration_mapping
, 1);
1647 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1651 mapping_name
= g_quark_from_string(escaped_string
);
1652 *mapping
= (struct bt_ctf_enumeration_mapping
) {
1653 .range_start
._unsigned
= range_start
,
1654 .range_end
._unsigned
= range_end
,
1655 .string
= mapping_name
,
1657 g_ptr_array_add(enum_ft
->entries
, mapping
);
1658 g_ptr_array_sort(enum_ft
->entries
,
1659 (GCompareFunc
) compare_enumeration_mappings_unsigned
);
1660 BT_LOGT("Added mapping to unsigned enumeration field type: addr=%p, "
1661 "name=\"%s\", range-start=%" PRIu64
", "
1662 "range-end=%" PRIu64
,
1663 ft
, string
, range_start
, range_end
);
1666 free(escaped_string
);
1673 int64_t bt_ctf_field_type_common_enumeration_get_mapping_count(
1674 struct bt_ctf_field_type_common
*ft
)
1676 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1678 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1679 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1680 return (int64_t) enum_ft
->entries
->len
;
1684 int bt_ctf_field_type_common_floating_point_get_exponent_digits(
1685 struct bt_ctf_field_type_common
*ft
)
1687 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1689 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1690 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_FLOAT
,
1692 return (int) flt_ft
->exp_dig
;
1696 int bt_ctf_field_type_common_floating_point_set_exponent_digits(
1697 struct bt_ctf_field_type_common
*ft
,
1698 unsigned int exponent_digits
)
1701 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1704 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1710 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1716 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1717 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1718 "addr=%p, ft-id=%s", ft
,
1719 bt_ctf_field_type_id_string(ft
->id
));
1724 if ((exponent_digits
!= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
) &&
1725 (exponent_digits
!= sizeof(double) * CHAR_BIT
- DBL_MANT_DIG
) &&
1727 sizeof(long double) * CHAR_BIT
- LDBL_MANT_DIG
)) {
1728 BT_LOGW("Invalid parameter: invalid exponent size: "
1729 "addr=%p, exp-size=%u", ft
, exponent_digits
);
1734 flt_ft
->exp_dig
= exponent_digits
;
1735 BT_LOGT("Set floating point number field type's exponent size: addr=%p, "
1736 "exp-size=%u", ft
, exponent_digits
);
1743 int bt_ctf_field_type_common_floating_point_get_mantissa_digits(
1744 struct bt_ctf_field_type_common
*ft
)
1746 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1748 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1749 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_FLOAT
,
1751 return (int) flt_ft
->mant_dig
;
1755 int bt_ctf_field_type_common_floating_point_set_mantissa_digits(
1756 struct bt_ctf_field_type_common
*ft
, unsigned int mantissa_digits
)
1759 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1762 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1768 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1774 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1775 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1776 "addr=%p, ft-id=%s", ft
,
1777 bt_ctf_field_type_id_string(ft
->id
));
1782 if ((mantissa_digits
!= FLT_MANT_DIG
) &&
1783 (mantissa_digits
!= DBL_MANT_DIG
) &&
1784 (mantissa_digits
!= LDBL_MANT_DIG
)) {
1785 BT_LOGW("Invalid parameter: invalid mantissa size: "
1786 "addr=%p, mant-size=%u", ft
, mantissa_digits
);
1791 flt_ft
->mant_dig
= mantissa_digits
;
1792 BT_LOGT("Set floating point number field type's mantissa size: addr=%p, "
1793 "mant-size=%u", ft
, mantissa_digits
);
1800 int bt_ctf_field_type_common_structure_replace_field(
1801 struct bt_ctf_field_type_common
*ft
,
1802 const char *field_name
,
1803 struct bt_ctf_field_type_common
*field_type
)
1806 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1811 BT_ASSERT_DBG(field_name
);
1812 BT_ASSERT_DBG(field_type
);
1813 BT_ASSERT_DBG(ft
->id
== BT_CTF_FIELD_TYPE_ID_STRUCT
);
1814 name_quark
= g_quark_from_string(field_name
);
1816 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
1817 struct bt_ctf_field_type_common_structure_field
*field
=
1818 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, i
);
1820 if (field
->name
== name_quark
) {
1821 bt_ctf_object_put_ref(field
->type
);
1822 field
->type
= bt_ctf_object_get_ref(field_type
);
1830 int bt_ctf_field_type_common_structure_add_field(struct bt_ctf_field_type_common
*ft
,
1831 struct bt_ctf_field_type_common
*field_type
,
1832 const char *field_name
)
1835 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1838 * TODO: check that `field_type` does not contain `type`,
1842 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1848 BT_LOGW_STR("Invalid parameter: field name is NULL.");
1854 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1860 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
1861 BT_LOGW("Invalid parameter: field type is not a structure field type: "
1862 "addr=%p, ft-id=%s", ft
,
1863 bt_ctf_field_type_id_string(ft
->id
));
1868 if (ft
== field_type
) {
1869 BT_LOGW("Invalid parameter: structure field type and field type to add are the same: "
1875 if (add_structure_variant_member(struct_ft
->fields
,
1876 struct_ft
->field_name_to_index
, field_type
, field_name
,
1878 BT_LOGW("Cannot add field to structure field type: "
1879 "struct-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
1880 ft
, field_type
, field_name
);
1885 BT_LOGT("Added structure field type field: struct-ft-addr=%p, "
1886 "field-ft-addr=%p, field-name=\"%s\"", ft
,
1887 field_type
, field_name
);
1894 int64_t bt_ctf_field_type_common_structure_get_field_count(
1895 struct bt_ctf_field_type_common
*ft
)
1897 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1899 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1900 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1902 return (int64_t) struct_ft
->fields
->len
;
1906 int bt_ctf_field_type_common_structure_borrow_field_by_index(
1907 struct bt_ctf_field_type_common
*ft
,
1908 const char **field_name
,
1909 struct bt_ctf_field_type_common
**field_type
, uint64_t index
)
1911 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1912 struct bt_ctf_field_type_common_structure_field
*field
;
1914 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1915 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1917 BT_CTF_ASSERT_PRE(index
< struct_ft
->fields
->len
,
1918 "Index is out of bounds: index=%" PRIu64
", "
1919 "count=%u, ft-addr=%p",
1920 index
, struct_ft
->fields
->len
, ft
);
1921 field
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(struct_ft
, index
);
1924 *field_type
= field
->type
;
1928 *field_name
= g_quark_to_string(field
->name
);
1929 BT_ASSERT_DBG(*field_name
);
1936 struct bt_ctf_field_type_common
*
1937 bt_ctf_field_type_common_structure_borrow_field_type_by_name(
1938 struct bt_ctf_field_type_common
*ft
, const char *name
)
1942 struct bt_ctf_field_type_common_structure_field
*field
;
1943 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1944 struct bt_ctf_field_type_common
*field_type
= NULL
;
1946 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1947 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
1948 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1950 name_quark
= g_quark_try_string(name
);
1952 BT_LOGT("No such structure field type field name: "
1953 "ft-addr=%p, field-name=\"%s\"",
1958 if (!g_hash_table_lookup_extended(struct_ft
->field_name_to_index
,
1959 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*) &index
)) {
1960 BT_LOGT("No such structure field type field name: "
1961 "ft-addr=%p, field-name=\"%s\"",
1966 field
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, index
);
1967 field_type
= field
->type
;
1974 struct bt_ctf_field_type_common
*
1975 bt_ctf_field_type_common_variant_borrow_tag_field_type(
1976 struct bt_ctf_field_type_common
*ft
)
1978 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
1979 struct bt_ctf_field_type_common
*tag_ft
= NULL
;
1981 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1982 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
1985 if (!var_ft
->tag_ft
) {
1986 BT_LOGT("Variant field type has no tag field type: "
1991 tag_ft
= BT_CTF_TO_COMMON(var_ft
->tag_ft
);
1998 const char *bt_ctf_field_type_common_variant_get_tag_name(
1999 struct bt_ctf_field_type_common
*ft
)
2001 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2002 const char *tag_name
= NULL
;
2004 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2005 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2008 if (var_ft
->tag_name
->len
== 0) {
2009 BT_LOGT("Variant field type has no tag field name: "
2014 tag_name
= var_ft
->tag_name
->str
;
2021 int bt_ctf_field_type_common_variant_set_tag_name(
2022 struct bt_ctf_field_type_common
*ft
, const char *name
)
2025 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2028 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2034 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2040 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2041 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2042 "addr=%p, ft-id=%s", ft
, bt_ctf_field_type_id_string(ft
->id
));
2047 if (!bt_ctf_identifier_is_valid(name
)) {
2048 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2049 "variant-ft-addr=%p, tag-field-name=\"%s\"",
2055 g_string_assign(var_ft
->tag_name
, name
);
2056 BT_LOGT("Set variant field type's tag field name: addr=%p, "
2057 "tag-field-name=\"%s\"", ft
, name
);
2064 int bt_ctf_field_type_common_variant_add_field(struct bt_ctf_field_type_common
*ft
,
2065 struct bt_ctf_field_type_common
*field_type
,
2066 const char *field_name
)
2070 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2071 GQuark field_name_quark
= g_quark_from_string(field_name
);
2074 * TODO: check that `field_type` does not contain `type`,
2078 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2084 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2090 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2091 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2092 "addr=%p, ft-id=%s", ft
,
2093 bt_ctf_field_type_id_string(ft
->id
));
2098 if (ft
== field_type
) {
2099 BT_LOGW("Invalid parameter: variant field type and field type to add are the same: "
2105 /* The user has explicitly provided a tag; validate against it. */
2106 if (var_ft
->tag_ft
) {
2109 /* Make sure this name is present in the enum tag */
2110 for (i
= 0; i
< var_ft
->tag_ft
->entries
->len
; i
++) {
2111 struct bt_ctf_enumeration_mapping
*mapping
=
2112 g_ptr_array_index(var_ft
->tag_ft
->entries
, i
);
2114 if (mapping
->string
== field_name_quark
) {
2121 /* Validation failed */
2122 BT_LOGW("Invalid parameter: field name does not name a tag field type's mapping: "
2123 "variant-ft-addr=%p, tag-ft-addr=%p, "
2124 "tag-field-name=\"%s\""
2125 "field-ft-addr=%p, field-name=\"%s\"",
2126 ft
, var_ft
->tag_ft
, var_ft
->tag_name
->str
,
2127 field_type
, field_name
);
2133 if (add_structure_variant_member(var_ft
->choices
,
2134 var_ft
->choice_name_to_index
, field_type
,
2135 field_name
, true)) {
2136 BT_LOGW("Cannot add field to variant field type: "
2137 "variant-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2138 ft
, field_type
, field_name
);
2143 BT_LOGT("Added variant field type field: variant-ft-addr=%p, "
2144 "field-ft-addr=%p, field-name=\"%s\"", ft
,
2145 field_type
, field_name
);
2152 struct bt_ctf_field_type_common
*
2153 bt_ctf_field_type_common_variant_borrow_field_type_by_name(
2154 struct bt_ctf_field_type_common
*ft
,
2155 const char *field_name
)
2159 struct bt_ctf_field_type_common_variant_choice
*choice
;
2160 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2161 struct bt_ctf_field_type_common
*field_type
= NULL
;
2163 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2164 BT_CTF_ASSERT_PRE_NON_NULL(field_name
, "Name");
2165 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2167 name_quark
= g_quark_try_string(field_name
);
2169 BT_LOGT("No such variant field type field name: "
2170 "ft-addr=%p, field-name=\"%s\"",
2175 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2176 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*) &index
)) {
2177 BT_LOGT("No such variant field type field name: "
2178 "ft-addr=%p, field-name=\"%s\"",
2183 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, index
);
2184 field_type
= choice
->type
;
2191 int64_t bt_ctf_field_type_common_variant_get_field_count(
2192 struct bt_ctf_field_type_common
*ft
)
2194 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2196 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Variant field type");
2197 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2199 return (int64_t) var_ft
->choices
->len
;
2203 int bt_ctf_field_type_common_variant_borrow_field_by_index(
2204 struct bt_ctf_field_type_common
*ft
,
2205 const char **field_name
,
2206 struct bt_ctf_field_type_common
**field_type
, uint64_t index
)
2208 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2209 struct bt_ctf_field_type_common_variant_choice
*choice
;
2211 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2212 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2214 BT_CTF_ASSERT_PRE(index
< var_ft
->choices
->len
,
2215 "Index is out of bounds: index=%" PRIu64
", "
2216 "count=%u, ft-addr=%p",
2217 index
, var_ft
->choices
->len
, ft
);
2218 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, index
);
2221 *field_type
= choice
->type
;
2225 *field_name
= g_quark_to_string(choice
->name
);
2226 BT_ASSERT_DBG(*field_name
);
2233 int64_t bt_ctf_field_type_common_variant_find_choice_index(
2234 struct bt_ctf_field_type_common
*ft
, uint64_t uval
,
2239 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2242 BT_ASSERT_DBG(ft
->id
== BT_CTF_FIELD_TYPE_ID_VARIANT
);
2244 if (bt_ctf_field_type_common_variant_update_choices(ft
)) {
2249 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
2251 struct bt_ctf_field_type_common_variant_choice
*choice
=
2252 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
2255 for (range_i
= 0; range_i
< choice
->ranges
->len
; range_i
++) {
2256 struct bt_ctf_field_type_common_variant_choice_range
*range
=
2259 struct bt_ctf_field_type_common_variant_choice_range
,
2263 int64_t tag_ival
= (int64_t) uval
;
2265 if (tag_ival
>= range
->lower
.i
&&
2266 tag_ival
<= range
->upper
.i
) {
2270 if (uval
>= range
->lower
.u
&&
2271 uval
<= range
->upper
.u
) {
2278 /* Range not found */
2290 struct bt_ctf_field_type_common
*
2291 bt_ctf_field_type_common_array_borrow_element_field_type(
2292 struct bt_ctf_field_type_common
*ft
)
2294 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2296 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2297 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ARRAY
,
2299 BT_ASSERT_DBG(array_ft
&& array_ft
->element_ft
);
2300 return array_ft
->element_ft
;
2304 int bt_ctf_field_type_common_array_set_element_field_type(
2305 struct bt_ctf_field_type_common
*ft
,
2306 struct bt_ctf_field_type_common
*element_ft
)
2309 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2312 BT_LOGW_STR("Invalid parameter: array field type is NULL.");
2318 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2323 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2324 BT_LOGW("Invalid parameter: field type is not an array field type: "
2325 "addr=%p, ft-id=%s", ft
,
2326 bt_ctf_field_type_id_string(ft
->id
));
2331 if (array_ft
->element_ft
) {
2332 BT_CTF_OBJECT_PUT_REF_AND_RESET(array_ft
->element_ft
);
2335 array_ft
->element_ft
= bt_ctf_object_get_ref(element_ft
);
2336 BT_LOGT("Set array field type's element field type: array-ft-addr=%p, "
2337 "element-ft-addr=%p", ft
, element_ft
);
2344 int64_t bt_ctf_field_type_common_array_get_length(struct bt_ctf_field_type_common
*ft
)
2346 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2348 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2349 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ARRAY
,
2351 return (int64_t) array_ft
->length
;
2355 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_sequence_borrow_element_field_type(
2356 struct bt_ctf_field_type_common
*ft
)
2358 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2360 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2361 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
2363 return seq_ft
->element_ft
;
2367 int bt_ctf_field_type_common_sequence_set_element_field_type(
2368 struct bt_ctf_field_type_common
*ft
,
2369 struct bt_ctf_field_type_common
*element_ft
)
2372 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2375 BT_LOGW_STR("Invalid parameter: sequence field type is NULL.");
2381 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2386 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2387 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2388 "addr=%p, ft-id=%s", ft
,
2389 bt_ctf_field_type_id_string(ft
->id
));
2394 if (seq_ft
->element_ft
) {
2395 BT_CTF_OBJECT_PUT_REF_AND_RESET(seq_ft
->element_ft
);
2398 seq_ft
->element_ft
= element_ft
;
2399 bt_ctf_object_get_ref(seq_ft
->element_ft
);
2400 BT_LOGT("Set sequence field type's element field type: sequence-ft-addr=%p, "
2401 "element-ft-addr=%p", ft
, element_ft
);
2408 const char *bt_ctf_field_type_common_sequence_get_length_field_name(
2409 struct bt_ctf_field_type_common
*ft
)
2411 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2413 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2414 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
2416 return seq_ft
->length_field_name
?
2417 seq_ft
->length_field_name
->str
: NULL
;
2421 enum bt_ctf_string_encoding
bt_ctf_field_type_common_string_get_encoding(
2422 struct bt_ctf_field_type_common
*ft
)
2424 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
2426 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2427 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRING
,
2429 return string_ft
->encoding
;
2433 int bt_ctf_field_type_common_string_set_encoding(struct bt_ctf_field_type_common
*ft
,
2434 enum bt_ctf_string_encoding encoding
)
2437 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
2440 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2445 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2446 BT_LOGW("Invalid parameter: field type is not a string field type: "
2447 "addr=%p, ft-id=%s", ft
,
2448 bt_ctf_field_type_id_string(ft
->id
));
2453 if (encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
2454 encoding
!= BT_CTF_STRING_ENCODING_ASCII
) {
2455 BT_LOGW("Invalid parameter: unknown string encoding: "
2456 "addr=%p, encoding=%d", ft
, encoding
);
2461 string_ft
->encoding
= encoding
;
2462 BT_LOGT("Set string field type's encoding: addr=%p, encoding=%s",
2463 ft
, bt_ctf_string_encoding_string(encoding
));
2470 int bt_ctf_field_type_common_get_alignment(struct bt_ctf_field_type_common
*ft
)
2473 enum bt_ctf_field_type_id type_id
;
2475 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2478 ret
= (int) ft
->alignment
;
2482 type_id
= bt_ctf_field_type_common_get_type_id(ft
);
2484 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
2486 struct bt_ctf_field_type_common
*element_ft
=
2487 bt_ctf_field_type_common_sequence_borrow_element_field_type(ft
);
2489 BT_ASSERT_DBG(element_ft
);
2490 ret
= bt_ctf_field_type_common_get_alignment(element_ft
);
2493 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
2495 struct bt_ctf_field_type_common
*element_ft
=
2496 bt_ctf_field_type_common_array_borrow_element_field_type(ft
);
2498 BT_ASSERT_DBG(element_ft
);
2499 ret
= bt_ctf_field_type_common_get_alignment(element_ft
);
2502 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
2504 int64_t i
, element_count
;
2506 element_count
= bt_ctf_field_type_common_structure_get_field_count(
2508 BT_ASSERT_DBG(element_count
>= 0);
2510 for (i
= 0; i
< element_count
; i
++) {
2511 struct bt_ctf_field_type_common
*field
= NULL
;
2512 int field_alignment
;
2514 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
2515 ft
, NULL
, &field
, i
);
2516 BT_ASSERT_DBG(ret
== 0);
2517 BT_ASSERT_DBG(field
);
2518 field_alignment
= bt_ctf_field_type_common_get_alignment(
2520 if (field_alignment
< 0) {
2521 ret
= field_alignment
;
2525 ft
->alignment
= MAX(field_alignment
, ft
->alignment
);
2527 ret
= (int) ft
->alignment
;
2530 case BT_CTF_FIELD_TYPE_ID_UNKNOWN
:
2531 BT_LOGW("Invalid parameter: unknown field type ID: "
2532 "addr=%p, ft-id=%d", ft
, type_id
);
2536 ret
= (int) ft
->alignment
;
2545 int is_power_of_two(unsigned int value
)
2547 return ((value
& (value
- 1)) == 0) && value
> 0;
2551 int bt_ctf_field_type_common_set_alignment(struct bt_ctf_field_type_common
*ft
,
2552 unsigned int alignment
)
2555 enum bt_ctf_field_type_id type_id
;
2557 /* Alignment must be a power of two */
2559 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2565 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2571 if (!is_power_of_two(alignment
)) {
2572 BT_LOGW("Invalid parameter: alignment is not a power of two: "
2573 "addr=%p, align=%u", ft
, alignment
);
2578 type_id
= bt_ctf_field_type_common_get_type_id(ft
);
2579 if (type_id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
2580 BT_LOGW("Invalid parameter: unknown field type ID: "
2581 "addr=%p, ft-id=%d", ft
, type_id
);
2586 if (ft
->id
== BT_CTF_FIELD_TYPE_ID_STRING
&& alignment
!= CHAR_BIT
) {
2587 BT_LOGW("Invalid parameter: alignment must be %u for a string field type: "
2588 "addr=%p, align=%u", CHAR_BIT
, ft
, alignment
);
2593 if (type_id
== BT_CTF_FIELD_TYPE_ID_VARIANT
||
2594 type_id
== BT_CTF_FIELD_TYPE_ID_SEQUENCE
||
2595 type_id
== BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2596 /* Setting an alignment on these types makes no sense */
2597 BT_LOGW("Invalid parameter: cannot set the alignment of this field type: "
2598 "addr=%p, ft-id=%s", ft
,
2599 bt_ctf_field_type_id_string(ft
->id
));
2604 ft
->alignment
= alignment
;
2606 BT_LOGT("Set field type's alignment: addr=%p, align=%u",
2614 enum bt_ctf_byte_order
bt_ctf_field_type_common_get_byte_order(
2615 struct bt_ctf_field_type_common
*ft
)
2617 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
2619 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2622 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
2624 struct bt_ctf_field_type_common_integer
*integer
=
2625 BT_CTF_FROM_COMMON(ft
);
2627 ret
= integer
->user_byte_order
;
2630 case BT_CTF_FIELD_TYPE_ID_ENUM
:
2632 struct bt_ctf_field_type_common_enumeration
*enum_ft
=
2633 BT_CTF_FROM_COMMON(ft
);
2635 ret
= bt_ctf_field_type_common_get_byte_order(
2636 BT_CTF_TO_COMMON(enum_ft
->container_ft
));
2639 case BT_CTF_FIELD_TYPE_ID_FLOAT
:
2641 struct bt_ctf_field_type_common_floating_point
*floating_point
=
2642 BT_CTF_FROM_COMMON(ft
);
2643 ret
= floating_point
->user_byte_order
;
2647 BT_LOGW("Invalid parameter: cannot get the byte order of this field type: "
2648 "addr=%p, ft-id=%s", ft
,
2649 bt_ctf_field_type_id_string(ft
->id
));
2653 BT_ASSERT_DBG(ret
== BT_CTF_BYTE_ORDER_NATIVE
||
2654 ret
== BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
||
2655 ret
== BT_CTF_BYTE_ORDER_BIG_ENDIAN
||
2656 ret
== BT_CTF_BYTE_ORDER_NETWORK
);
2663 int bt_ctf_field_type_common_set_byte_order(struct bt_ctf_field_type_common
*ft
,
2664 enum bt_ctf_byte_order byte_order
)
2669 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2675 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2681 if (byte_order
!= BT_CTF_BYTE_ORDER_NATIVE
&&
2682 byte_order
!= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
&&
2683 byte_order
!= BT_CTF_BYTE_ORDER_BIG_ENDIAN
&&
2684 byte_order
!= BT_CTF_BYTE_ORDER_NETWORK
) {
2685 BT_LOGW("Invalid parameter: invalid byte order: "
2686 "addr=%p, bo=%s", ft
,
2687 bt_ctf_byte_order_string(byte_order
));
2692 if (ft
->methods
->set_byte_order
) {
2693 ft
->methods
->set_byte_order(ft
, byte_order
);
2696 BT_LOGT("Set field type's byte order: addr=%p, bo=%s",
2697 ft
, bt_ctf_byte_order_string(byte_order
));
2704 enum bt_ctf_field_type_id
bt_ctf_field_type_common_get_type_id(
2705 struct bt_ctf_field_type_common
*ft
)
2707 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2712 void bt_ctf_field_type_common_freeze(struct bt_ctf_field_type_common
*ft
)
2714 if (!ft
|| ft
->frozen
) {
2718 BT_ASSERT_DBG(ft
->methods
->freeze
);
2719 ft
->methods
->freeze(ft
);
2723 struct bt_ctf_field_type_common
*
2724 bt_ctf_field_type_common_variant_borrow_field_type_signed(
2725 struct bt_ctf_field_type_common_variant
*var_ft
,
2728 struct bt_ctf_field_type_common
*field_type
= NULL
;
2729 GQuark field_name_quark
;
2731 struct bt_ctf_field_type_common_variant_choice
*choice
;
2732 struct range_overlap_query query
= {
2733 .range_start
._signed
= tag_value
,
2734 .range_end
._signed
= tag_value
,
2739 g_ptr_array_foreach(var_ft
->tag_ft
->entries
, check_ranges_overlap
,
2741 if (!query
.overlaps
) {
2745 field_name_quark
= query
.mapping_name
;
2746 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2747 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
2751 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
,
2753 field_type
= choice
->type
;
2760 struct bt_ctf_field_type_common
*
2761 bt_ctf_field_type_common_variant_borrow_field_type_unsigned(
2762 struct bt_ctf_field_type_common_variant
*var_ft
,
2765 struct bt_ctf_field_type_common
*field_type
= NULL
;
2766 GQuark field_name_quark
;
2768 struct bt_ctf_field_type_common_variant_choice
*choice
;
2769 struct range_overlap_query query
= {
2770 .range_start
._unsigned
= tag_value
,
2771 .range_end
._unsigned
= tag_value
,
2776 g_ptr_array_foreach(var_ft
->tag_ft
->entries
,
2777 check_ranges_overlap_unsigned
, &query
);
2778 if (!query
.overlaps
) {
2782 field_name_quark
= query
.mapping_name
;
2783 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2784 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
2788 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
,
2790 field_type
= choice
->type
;
2797 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_copy(
2798 struct bt_ctf_field_type_common
*ft
)
2800 struct bt_ctf_field_type_common
*ft_copy
= NULL
;
2802 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2803 BT_ASSERT_DBG(ft
->methods
->copy
);
2804 ft_copy
= ft
->methods
->copy(ft
);
2806 BT_LOGE_STR("Cannot copy field type.");
2810 ft_copy
->alignment
= ft
->alignment
;
2817 int bt_ctf_field_type_common_structure_get_field_name_index(
2818 struct bt_ctf_field_type_common
*ft
, const char *name
)
2823 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
2825 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2826 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
2827 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
2830 name_quark
= g_quark_try_string(name
);
2832 BT_LOGT("No such structure field type field name: "
2833 "ft-addr=%p, field-name=\"%s\"",
2839 if (!g_hash_table_lookup_extended(struct_ft
->field_name_to_index
,
2840 GUINT_TO_POINTER(name_quark
),
2841 NULL
, (gpointer
*) &index
)) {
2842 BT_LOGT("No such structure field type field name: "
2843 "ft-addr=%p, field-name=\"%s\"",
2856 int bt_ctf_field_type_common_variant_get_field_name_index(
2857 struct bt_ctf_field_type_common
*ft
, const char *name
)
2862 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2864 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2865 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
2866 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2868 name_quark
= g_quark_try_string(name
);
2870 BT_LOGT("No such variant field type field name: "
2871 "ft-addr=%p, field-name=\"%s\"",
2877 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2878 GUINT_TO_POINTER(name_quark
),
2879 NULL
, (gpointer
*) &index
)) {
2880 BT_LOGT("No such variant field type field name: "
2881 "ft-addr=%p, field-name=\"%s\"",
2894 int bt_ctf_field_type_common_sequence_set_length_field_path(
2895 struct bt_ctf_field_type_common
*ft
, struct bt_ctf_field_path
*path
)
2898 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2901 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2906 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2907 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2908 "addr=%p, ft-id=%s", ft
,
2909 bt_ctf_field_type_id_string(ft
->id
));
2914 bt_ctf_object_get_ref(path
);
2915 BT_CTF_OBJECT_MOVE_REF(seq_ft
->length_field_path
, path
);
2916 BT_LOGT("Set sequence field type's length field path: ft-addr=%p, "
2917 "field-path-addr=%p", ft
, path
);
2924 int bt_ctf_field_type_common_variant_set_tag_field_path(
2925 struct bt_ctf_field_type_common
*ft
,
2926 struct bt_ctf_field_path
*path
)
2929 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2932 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2937 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2938 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2939 "addr=%p, ft-id=%s", ft
,
2940 bt_ctf_field_type_id_string(ft
->id
));
2945 bt_ctf_object_get_ref(path
);
2946 BT_CTF_OBJECT_MOVE_REF(var_ft
->tag_field_path
, path
);
2947 BT_LOGT("Set variant field type's tag field path: ft-addr=%p, "
2948 "field-path-addr=%p", ft
, path
);
2955 int bt_ctf_field_type_common_variant_set_tag_field_type(
2956 struct bt_ctf_field_type_common
*ft
,
2957 struct bt_ctf_field_type_common
*tag_ft
)
2960 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2963 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
2969 BT_LOGW_STR("Invalid parameter: tag field type is NULL.");
2974 if (tag_ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
2975 BT_LOGW("Invalid parameter: tag field type is not an enumeration field type: "
2976 "addr=%p, ft-id=%s", tag_ft
,
2977 bt_ctf_field_type_id_string(tag_ft
->id
));
2982 bt_ctf_object_put_ref(var_ft
->tag_ft
);
2983 var_ft
->tag_ft
= bt_ctf_object_get_ref(tag_ft
);
2984 BT_LOGT("Set variant field type's tag field type: variant-ft-addr=%p, "
2985 "tag-ft-addr=%p", ft
, tag_ft
);
2992 void bt_ctf_field_type_common_generic_freeze(struct bt_ctf_field_type_common
*ft
)
2998 void bt_ctf_field_type_common_enumeration_freeze_recursive(
2999 struct bt_ctf_field_type_common
*ft
)
3001 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
3003 BT_LOGD("Freezing enumeration field type object: addr=%p", ft
);
3004 bt_ctf_field_type_common_enumeration_set_range_overlap(enum_ft
);
3005 bt_ctf_field_type_common_generic_freeze(ft
);
3006 BT_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p",
3007 enum_ft
->container_ft
);
3008 bt_ctf_field_type_common_freeze(BT_CTF_TO_COMMON(enum_ft
->container_ft
));
3012 void bt_ctf_field_type_common_structure_freeze_recursive(
3013 struct bt_ctf_field_type_common
*ft
)
3015 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
3018 /* Cache the alignment */
3019 BT_LOGD("Freezing structure field type object: addr=%p", ft
);
3020 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
3021 bt_ctf_field_type_common_generic_freeze(ft
);
3023 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
3024 struct bt_ctf_field_type_common_structure_field
*field
=
3025 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, i
);
3027 BT_LOGD("Freezing structure field type field: "
3028 "ft-addr=%p, name=\"%s\"",
3029 field
->type
, g_quark_to_string(field
->name
));
3030 bt_ctf_field_type_common_freeze(field
->type
);
3035 int bt_ctf_field_type_common_variant_update_choices(struct bt_ctf_field_type_common
*ft
)
3037 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3042 if (ft
->frozen
&& var_ft
->choices_up_to_date
) {
3046 BT_ASSERT_DBG(var_ft
->tag_ft
);
3047 is_signed
= !!var_ft
->tag_ft
->container_ft
->is_signed
;
3049 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
3050 struct bt_ctf_field_type_common_variant_choice
*choice
=
3051 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, i
);
3052 const char *choice_name
= g_quark_to_string(choice
->name
);
3053 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
3054 bt_ctf_field_type_common_enumeration_find_mappings_by_name(
3055 BT_CTF_TO_COMMON(var_ft
->tag_ft
), choice_name
);
3062 BT_ASSERT_DBG(choice
->ranges
);
3063 g_array_set_size(choice
->ranges
, 0);
3065 while (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
) == 0) {
3066 struct bt_ctf_field_type_common_variant_choice_range range
;
3069 ret
= bt_ctf_field_type_enumeration_mapping_iterator_signed_get(
3071 &range
.lower
.i
, &range
.upper
.i
);
3073 ret
= bt_ctf_field_type_enumeration_mapping_iterator_unsigned_get(
3075 &range
.lower
.u
, &range
.upper
.u
);
3078 BT_ASSERT_DBG(ret
== 0);
3079 g_array_append_val(choice
->ranges
, range
);
3082 bt_ctf_object_put_ref(iter
);
3085 var_ft
->choices_up_to_date
= true;
3092 void bt_ctf_field_type_common_variant_freeze_recursive(
3093 struct bt_ctf_field_type_common
*ft
)
3095 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3098 BT_LOGD("Freezing variant field type object: addr=%p", ft
);
3099 bt_ctf_field_type_common_generic_freeze(ft
);
3101 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
3102 struct bt_ctf_field_type_common_variant_choice
*choice
=
3103 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, i
);
3105 BT_LOGD("Freezing variant field type member: "
3106 "ft-addr=%p, name=\"%s\"",
3107 choice
->type
, g_quark_to_string(choice
->name
));
3108 bt_ctf_field_type_common_freeze(choice
->type
);
3113 void bt_ctf_field_type_common_array_freeze_recursive(
3114 struct bt_ctf_field_type_common
*ft
)
3116 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
3118 /* Cache the alignment */
3119 BT_LOGD("Freezing array field type object: addr=%p", ft
);
3120 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
3121 bt_ctf_field_type_common_generic_freeze(ft
);
3122 BT_LOGD("Freezing array field type object's element field type: element-ft-addr=%p",
3123 array_ft
->element_ft
);
3124 bt_ctf_field_type_common_freeze(array_ft
->element_ft
);
3128 void bt_ctf_field_type_common_sequence_freeze_recursive(
3129 struct bt_ctf_field_type_common
*ft
)
3131 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3133 /* Cache the alignment */
3134 BT_LOGD("Freezing sequence field type object: addr=%p", ft
);
3135 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
3136 bt_ctf_field_type_common_generic_freeze(ft
);
3137 BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
3138 seq_ft
->element_ft
);
3139 bt_ctf_field_type_common_freeze(seq_ft
->element_ft
);
3143 void bt_ctf_field_type_common_integer_set_byte_order(
3144 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3146 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
3148 int_ft
->user_byte_order
= byte_order
;
3152 void bt_ctf_field_type_common_enumeration_set_byte_order_recursive(
3153 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3155 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
3157 bt_ctf_field_type_common_set_byte_order(BT_CTF_TO_COMMON(enum_ft
->container_ft
),
3162 void bt_ctf_field_type_common_floating_point_set_byte_order(
3163 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3165 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
3167 flt_ft
->user_byte_order
= byte_order
;
3171 void bt_ctf_field_type_common_structure_set_byte_order_recursive(
3172 struct bt_ctf_field_type_common
*ft
,
3173 enum bt_ctf_byte_order byte_order
)
3176 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
3178 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
3179 struct bt_ctf_field_type_common_structure_field
*field
=
3180 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3182 struct bt_ctf_field_type_common
*field_type
= field
->type
;
3184 bt_ctf_field_type_common_set_byte_order(field_type
, byte_order
);
3189 void bt_ctf_field_type_common_variant_set_byte_order_recursive(
3190 struct bt_ctf_field_type_common
*ft
,
3191 enum bt_ctf_byte_order byte_order
)
3194 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3196 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
3197 struct bt_ctf_field_type_common_variant_choice
*choice
=
3198 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3200 struct bt_ctf_field_type_common
*field_type
= choice
->type
;
3202 bt_ctf_field_type_common_set_byte_order(field_type
, byte_order
);
3207 void bt_ctf_field_type_common_array_set_byte_order_recursive(
3208 struct bt_ctf_field_type_common
*ft
,
3209 enum bt_ctf_byte_order byte_order
)
3211 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
3213 bt_ctf_field_type_common_set_byte_order(array_ft
->element_ft
, byte_order
);
3217 void bt_ctf_field_type_common_sequence_set_byte_order_recursive(
3218 struct bt_ctf_field_type_common
*ft
,
3219 enum bt_ctf_byte_order byte_order
)
3221 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3223 bt_ctf_field_type_common_set_byte_order(seq_ft
->element_ft
, byte_order
);
3228 int bt_ctf_field_type_common_integer_compare(struct bt_ctf_field_type_common
*ft_a
,
3229 struct bt_ctf_field_type_common
*ft_b
)
3232 struct bt_ctf_field_type_common_integer
*int_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3233 struct bt_ctf_field_type_common_integer
*int_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3236 if (int_ft_a
->size
!= int_ft_b
->size
) {
3237 BT_LOGT("Integer field types differ: different sizes: "
3238 "ft-a-size=%u, ft-b-size=%u",
3239 int_ft_a
->size
, int_ft_b
->size
);
3244 if (int_ft_a
->user_byte_order
!= int_ft_b
->user_byte_order
) {
3245 BT_LOGT("Integer field types differ: different byte orders: "
3246 "ft-a-bo=%s, ft-b-bo=%s",
3247 bt_ctf_byte_order_string(int_ft_a
->user_byte_order
),
3248 bt_ctf_byte_order_string(int_ft_b
->user_byte_order
));
3253 if (int_ft_a
->is_signed
!= int_ft_b
->is_signed
) {
3254 BT_LOGT("Integer field types differ: different signedness: "
3255 "ft-a-is-signed=%d, ft-b-is-signed=%d",
3256 int_ft_a
->is_signed
,
3257 int_ft_b
->is_signed
);
3262 if (int_ft_a
->base
!= int_ft_b
->base
) {
3263 BT_LOGT("Integer field types differ: different bases: "
3264 "ft-a-base=%s, ft-b-base=%s",
3265 bt_ctf_integer_base_string(int_ft_a
->base
),
3266 bt_ctf_integer_base_string(int_ft_b
->base
));
3271 if (int_ft_a
->encoding
!= int_ft_b
->encoding
) {
3272 BT_LOGT("Integer field types differ: different encodings: "
3273 "ft-a-encoding=%s, ft-b-encoding=%s",
3274 bt_ctf_string_encoding_string(int_ft_a
->encoding
),
3275 bt_ctf_string_encoding_string(int_ft_b
->encoding
));
3279 /* Mapped clock class */
3280 if (int_ft_a
->mapped_clock_class
) {
3281 if (!int_ft_b
->mapped_clock_class
) {
3282 BT_LOGT_STR("Integer field types differ: field type A "
3283 "has a mapped clock class, but field type B "
3288 if (bt_ctf_clock_class_compare(int_ft_a
->mapped_clock_class
,
3289 int_ft_b
->mapped_clock_class
) != 0) {
3290 BT_LOGT_STR("Integer field types differ: different "
3291 "mapped clock classes.");
3294 if (int_ft_b
->mapped_clock_class
) {
3295 BT_LOGT_STR("Integer field types differ: field type A "
3296 "has no description, but field type B has one.");
3309 int bt_ctf_field_type_common_floating_point_compare(
3310 struct bt_ctf_field_type_common
*ft_a
,
3311 struct bt_ctf_field_type_common
*ft_b
)
3314 struct bt_ctf_field_type_common_floating_point
*flt_ft_a
=
3315 BT_CTF_FROM_COMMON(ft_a
);
3316 struct bt_ctf_field_type_common_floating_point
*flt_ft_b
=
3317 BT_CTF_FROM_COMMON(ft_b
);
3320 if (flt_ft_a
->user_byte_order
!= flt_ft_b
->user_byte_order
) {
3321 BT_LOGT("Floating point number field types differ: different byte orders: "
3322 "ft-a-bo=%s, ft-b-bo=%s",
3323 bt_ctf_byte_order_string(flt_ft_a
->user_byte_order
),
3324 bt_ctf_byte_order_string(flt_ft_b
->user_byte_order
));
3328 /* Exponent length */
3329 if (flt_ft_a
->exp_dig
!= flt_ft_b
->exp_dig
) {
3330 BT_LOGT("Floating point number field types differ: different exponent sizes: "
3331 "ft-a-exp-size=%u, ft-b-exp-size=%u",
3332 flt_ft_a
->exp_dig
, flt_ft_b
->exp_dig
);
3336 /* Mantissa length */
3337 if (flt_ft_a
->mant_dig
!= flt_ft_b
->mant_dig
) {
3338 BT_LOGT("Floating point number field types differ: different mantissa sizes: "
3339 "ft-a-mant-size=%u, ft-b-mant-size=%u",
3340 flt_ft_a
->mant_dig
, flt_ft_b
->mant_dig
);
3352 int compare_enumeration_mappings(struct bt_ctf_enumeration_mapping
*mapping_a
,
3353 struct bt_ctf_enumeration_mapping
*mapping_b
)
3358 if (mapping_a
->string
!= mapping_b
->string
) {
3359 BT_LOGT("Enumeration field type mappings differ: different names: "
3360 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
3361 g_quark_to_string(mapping_a
->string
),
3362 g_quark_to_string(mapping_b
->string
));
3367 if (mapping_a
->range_start
._unsigned
!=
3368 mapping_b
->range_start
._unsigned
) {
3369 BT_LOGT("Enumeration field type mappings differ: different starts of range: "
3370 "mapping-a-range-start-unsigned=%" PRIu64
", "
3371 "mapping-b-range-start-unsigned=%" PRIu64
,
3372 mapping_a
->range_start
._unsigned
,
3373 mapping_b
->range_start
._unsigned
);
3378 if (mapping_a
->range_end
._unsigned
!=
3379 mapping_b
->range_end
._unsigned
) {
3380 BT_LOGT("Enumeration field type mappings differ: different ends of range: "
3381 "mapping-a-range-end-unsigned=%" PRIu64
", "
3382 "mapping-b-range-end-unsigned=%" PRIu64
,
3383 mapping_a
->range_end
._unsigned
,
3384 mapping_b
->range_end
._unsigned
);
3396 int bt_ctf_field_type_common_enumeration_compare_recursive(
3397 struct bt_ctf_field_type_common
*ft_a
,
3398 struct bt_ctf_field_type_common
*ft_b
)
3402 struct bt_ctf_field_type_common_enumeration
*enum_ft_a
=
3403 BT_CTF_FROM_COMMON(ft_a
);
3404 struct bt_ctf_field_type_common_enumeration
*enum_ft_b
=
3405 BT_CTF_FROM_COMMON(ft_b
);
3407 /* Container field type */
3408 ret
= bt_ctf_field_type_common_compare(
3409 BT_CTF_TO_COMMON(enum_ft_a
->container_ft
),
3410 BT_CTF_TO_COMMON(enum_ft_b
->container_ft
));
3412 BT_LOGT("Enumeration field types differ: different container field types: "
3413 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
3414 enum_ft_a
->container_ft
, enum_ft_b
->container_ft
);
3421 if (enum_ft_a
->entries
->len
!= enum_ft_b
->entries
->len
) {
3425 for (i
= 0; i
< enum_ft_a
->entries
->len
; ++i
) {
3426 struct bt_ctf_enumeration_mapping
*mapping_a
=
3427 g_ptr_array_index(enum_ft_a
->entries
, i
);
3428 struct bt_ctf_enumeration_mapping
*mapping_b
=
3429 g_ptr_array_index(enum_ft_b
->entries
, i
);
3431 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
3432 BT_LOGT("Enumeration field types differ: different mappings: "
3433 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
3434 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
3435 mapping_a
, mapping_b
,
3436 g_quark_to_string(mapping_a
->string
),
3437 g_quark_to_string(mapping_b
->string
));
3450 int bt_ctf_field_type_common_string_compare(struct bt_ctf_field_type_common
*ft_a
,
3451 struct bt_ctf_field_type_common
*ft_b
)
3454 struct bt_ctf_field_type_common_string
*string_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3455 struct bt_ctf_field_type_common_string
*string_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3458 if (string_ft_a
->encoding
!= string_ft_b
->encoding
) {
3459 BT_LOGT("String field types differ: different encodings: "
3460 "ft-a-encoding=%s, ft-b-encoding=%s",
3461 bt_ctf_string_encoding_string(string_ft_a
->encoding
),
3462 bt_ctf_string_encoding_string(string_ft_b
->encoding
));
3474 int compare_structure_variant_members(
3475 struct bt_ctf_field_type_common
*member_a_ft
,
3476 struct bt_ctf_field_type_common
*member_b_ft
,
3477 GQuark member_a_name
, GQuark member_b_name
)
3482 if (member_a_name
!= member_b_name
) {
3483 BT_LOGT("Structure/variant field type fields differ: different names: "
3484 "field-a-name=%s, field-b-name=%s",
3485 g_quark_to_string(member_a_name
),
3486 g_quark_to_string(member_b_name
));
3491 ret
= bt_ctf_field_type_common_compare(member_a_ft
, member_b_ft
);
3493 BT_LOGT("Structure/variant field type fields differ: different field types: "
3494 "field-name=\"%s\", field-a-ft-addr=%p, field-b-ft-addr=%p",
3495 g_quark_to_string(member_a_name
),
3496 member_a_ft
, member_b_ft
);
3504 int bt_ctf_field_type_common_structure_compare_recursive(
3505 struct bt_ctf_field_type_common
*ft_a
,
3506 struct bt_ctf_field_type_common
*ft_b
)
3510 struct bt_ctf_field_type_common_structure
*struct_ft_a
=
3511 BT_CTF_FROM_COMMON(ft_a
);
3512 struct bt_ctf_field_type_common_structure
*struct_ft_b
=
3513 BT_CTF_FROM_COMMON(ft_b
);
3516 if (bt_ctf_field_type_common_get_alignment(ft_a
) !=
3517 bt_ctf_field_type_common_get_alignment(ft_b
)) {
3518 BT_LOGT("Structure field types differ: different alignments: "
3519 "ft-a-align=%u, ft-b-align=%u",
3520 bt_ctf_field_type_common_get_alignment(ft_a
),
3521 bt_ctf_field_type_common_get_alignment(ft_b
));
3526 if (struct_ft_a
->fields
->len
!= struct_ft_b
->fields
->len
) {
3527 BT_LOGT("Structure field types differ: different field counts: "
3528 "ft-a-field-count=%u, ft-b-field-count=%u",
3529 struct_ft_a
->fields
->len
, struct_ft_b
->fields
->len
);
3533 for (i
= 0; i
< struct_ft_a
->fields
->len
; ++i
) {
3534 struct bt_ctf_field_type_common_structure_field
*field_a
=
3535 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3537 struct bt_ctf_field_type_common_structure_field
*field_b
=
3538 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3541 ret
= compare_structure_variant_members(field_a
->type
,
3542 field_b
->type
, field_a
->name
, field_b
->name
);
3544 /* compare_structure_variant_members() logs what differs */
3545 BT_LOGT_STR("Structure field types differ: different fields.");
3558 int bt_ctf_field_type_common_variant_compare_recursive(
3559 struct bt_ctf_field_type_common
*ft_a
,
3560 struct bt_ctf_field_type_common
*ft_b
)
3564 struct bt_ctf_field_type_common_variant
*var_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3565 struct bt_ctf_field_type_common_variant
*var_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3568 if (strcmp(var_ft_a
->tag_name
->str
, var_ft_b
->tag_name
->str
)) {
3569 BT_LOGT("Variant field types differ: different tag field names: "
3570 "ft-a-tag-field-name=\"%s\", ft-b-tag-field-name=\"%s\"",
3571 var_ft_a
->tag_name
->str
, var_ft_b
->tag_name
->str
);
3576 ret
= bt_ctf_field_type_common_compare(BT_CTF_TO_COMMON(var_ft_a
->tag_ft
),
3577 BT_CTF_TO_COMMON(var_ft_b
->tag_ft
));
3579 BT_LOGT("Variant field types differ: different tag field types: "
3580 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
3581 var_ft_a
->tag_ft
, var_ft_b
->tag_ft
);
3588 if (var_ft_a
->choices
->len
!= var_ft_b
->choices
->len
) {
3589 BT_LOGT("Variant field types differ: different field counts: "
3590 "ft-a-field-count=%u, ft-b-field-count=%u",
3591 var_ft_a
->choices
->len
, var_ft_b
->choices
->len
);
3595 for (i
= 0; i
< var_ft_a
->choices
->len
; ++i
) {
3596 struct bt_ctf_field_type_common_variant_choice
*choice_a
=
3597 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3599 struct bt_ctf_field_type_common_variant_choice
*choice_b
=
3600 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3603 ret
= compare_structure_variant_members(choice_a
->type
,
3604 choice_b
->type
, choice_a
->name
, choice_b
->name
);
3606 /* compare_structure_variant_members() logs what differs */
3607 BT_LOGT_STR("Variant field types differ: different fields.");
3620 int bt_ctf_field_type_common_array_compare_recursive(
3621 struct bt_ctf_field_type_common
*ft_a
,
3622 struct bt_ctf_field_type_common
*ft_b
)
3625 struct bt_ctf_field_type_common_array
*array_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3626 struct bt_ctf_field_type_common_array
*array_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3629 if (array_ft_a
->length
!= array_ft_b
->length
) {
3630 BT_LOGT("Structure field types differ: different lengths: "
3631 "ft-a-length=%u, ft-b-length=%u",
3632 array_ft_a
->length
, array_ft_b
->length
);
3637 ret
= bt_ctf_field_type_common_compare(array_ft_a
->element_ft
,
3638 array_ft_b
->element_ft
);
3640 BT_LOGT("Array field types differ: different element field types: "
3641 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
3642 array_ft_a
->element_ft
, array_ft_b
->element_ft
);
3650 int bt_ctf_field_type_common_sequence_compare_recursive(
3651 struct bt_ctf_field_type_common
*ft_a
,
3652 struct bt_ctf_field_type_common
*ft_b
)
3655 struct bt_ctf_field_type_common_sequence
*seq_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3656 struct bt_ctf_field_type_common_sequence
*seq_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3659 if (strcmp(seq_ft_a
->length_field_name
->str
,
3660 seq_ft_b
->length_field_name
->str
)) {
3661 BT_LOGT("Sequence field types differ: different length field names: "
3662 "ft-a-length-field-name=\"%s\", "
3663 "ft-b-length-field-name=\"%s\"",
3664 seq_ft_a
->length_field_name
->str
,
3665 seq_ft_b
->length_field_name
->str
);
3670 ret
= bt_ctf_field_type_common_compare(seq_ft_a
->element_ft
,
3671 seq_ft_b
->element_ft
);
3673 BT_LOGT("Sequence field types differ: different element field types: "
3674 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
3675 seq_ft_a
->element_ft
, seq_ft_b
->element_ft
);
3683 int bt_ctf_field_type_common_compare(struct bt_ctf_field_type_common
*ft_a
,
3684 struct bt_ctf_field_type_common
*ft_b
)
3688 BT_CTF_ASSERT_PRE_NON_NULL(ft_a
, "Field type A");
3689 BT_CTF_ASSERT_PRE_NON_NULL(ft_b
, "Field type B");
3692 /* Same reference: equal (even if both are NULL) */
3698 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
3704 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
3709 if (ft_a
->id
!= ft_b
->id
) {
3710 /* Different type IDs */
3711 BT_LOGT("Field types differ: different IDs: "
3712 "ft-a-addr=%p, ft-b-addr=%p, "
3713 "ft-a-id=%s, ft-b-id=%s",
3715 bt_ctf_field_type_id_string(ft_a
->id
),
3716 bt_ctf_field_type_id_string(ft_b
->id
));
3720 if (ft_a
->id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
3721 /* Both have unknown type IDs */
3722 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
3726 BT_ASSERT_DBG(ft_a
->methods
->compare
);
3727 ret
= ft_a
->methods
->compare(ft_a
, ft_b
);
3729 BT_LOGT("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
3738 int64_t bt_ctf_field_type_common_get_field_count(struct bt_ctf_field_type_common
*ft
)
3740 int64_t field_count
= -1;
3743 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3745 bt_ctf_field_type_common_structure_get_field_count(ft
);
3747 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3749 bt_ctf_field_type_common_variant_get_field_count(ft
);
3751 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3752 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3754 * Array and sequence types always contain a single member
3755 * (the element type).
3767 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_borrow_field_at_index(
3768 struct bt_ctf_field_type_common
*ft
, int index
)
3770 struct bt_ctf_field_type_common
*field_type
= NULL
;
3773 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3775 int ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
3776 ft
, NULL
, &field_type
, index
);
3783 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3785 int ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
3786 ft
, NULL
, &field_type
, index
);
3793 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3795 bt_ctf_field_type_common_array_borrow_element_field_type(ft
);
3797 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3799 bt_ctf_field_type_common_sequence_borrow_element_field_type(ft
);
3810 int bt_ctf_field_type_common_get_field_index(struct bt_ctf_field_type_common
*ft
,
3813 int field_index
= -1;
3816 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3817 field_index
= bt_ctf_field_type_common_structure_get_field_name_index(
3820 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3821 field_index
= bt_ctf_field_type_common_variant_get_field_name_index(
3832 struct bt_ctf_field_path
*bt_ctf_field_type_common_variant_borrow_tag_field_path(
3833 struct bt_ctf_field_type_common
*ft
)
3835 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3837 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
3838 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
3840 return var_ft
->tag_field_path
;
3844 struct bt_ctf_field_path
*bt_ctf_field_type_common_sequence_borrow_length_field_path(
3845 struct bt_ctf_field_type_common
*ft
)
3847 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3849 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
3850 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
3852 return seq_ft
->length_field_path
;
3856 int bt_ctf_field_type_common_validate_single_clock_class(
3857 struct bt_ctf_field_type_common
*ft
,
3858 struct bt_ctf_clock_class
**expected_clock_class
)
3866 BT_ASSERT_DBG(expected_clock_class
);
3869 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
3871 struct bt_ctf_clock_class
*mapped_clock_class
=
3872 bt_ctf_field_type_common_integer_borrow_mapped_clock_class(ft
);
3874 if (!mapped_clock_class
) {
3878 if (!*expected_clock_class
) {
3879 /* Move reference to output parameter */
3880 *expected_clock_class
= bt_ctf_object_get_ref(mapped_clock_class
);
3881 mapped_clock_class
= NULL
;
3882 BT_LOGT("Setting expected clock class: "
3883 "expected-clock-class-addr=%p",
3884 *expected_clock_class
);
3886 if (mapped_clock_class
!= *expected_clock_class
) {
3887 BT_LOGW("Integer field type is not mapped to "
3888 "the expected clock class: "
3889 "mapped-clock-class-addr=%p, "
3890 "mapped-clock-class-name=\"%s\", "
3891 "expected-clock-class-addr=%p, "
3892 "expected-clock-class-name=\"%s\"",
3894 bt_ctf_clock_class_get_name(mapped_clock_class
),
3895 *expected_clock_class
,
3896 bt_ctf_clock_class_get_name(*expected_clock_class
));
3897 bt_ctf_object_put_ref(mapped_clock_class
);
3905 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3906 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3907 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3909 struct bt_ctf_field_type_common
*sub_ft
= NULL
;
3912 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3913 sub_ft
= bt_ctf_field_type_common_enumeration_borrow_container_field_type(
3916 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3917 sub_ft
= bt_ctf_field_type_common_array_borrow_element_field_type(
3920 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3921 sub_ft
= bt_ctf_field_type_common_sequence_borrow_element_field_type(
3925 BT_LOGF("Unexpected field type ID: id=%d", ft
->id
);
3929 BT_ASSERT_DBG(sub_ft
);
3930 ret
= bt_ctf_field_type_common_validate_single_clock_class(sub_ft
,
3931 expected_clock_class
);
3934 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3937 int64_t count
= bt_ctf_field_type_common_structure_get_field_count(
3940 for (i
= 0; i
< count
; i
++) {
3942 struct bt_ctf_field_type_common
*member_type
;
3944 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
3945 ft
, &name
, &member_type
, i
);
3946 BT_ASSERT_DBG(ret
== 0);
3947 ret
= bt_ctf_field_type_common_validate_single_clock_class(
3948 member_type
, expected_clock_class
);
3950 BT_LOGW("Structure field type's field's type "
3951 "is not recursively mapped to the "
3952 "expected clock class: "
3953 "field-ft-addr=%p, field-name=\"%s\"",
3960 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3963 int64_t count
= bt_ctf_field_type_common_variant_get_field_count(
3966 for (i
= 0; i
< count
; i
++) {
3968 struct bt_ctf_field_type_common
*member_type
;
3970 ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
3971 ft
, &name
, &member_type
, i
);
3972 BT_ASSERT_DBG(ret
== 0);
3973 ret
= bt_ctf_field_type_common_validate_single_clock_class(
3974 member_type
, expected_clock_class
);
3976 BT_LOGW("Variant field type's field's type "
3977 "is not recursively mapped to the "
3978 "expected clock class: "
3979 "field-ft-addr=%p, field-name=\"%s\"",
3995 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
3996 struct bt_ctf_field_type
*ft
);
3999 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy_recursive(
4000 struct bt_ctf_field_type
*ft
);
4003 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
4004 struct bt_ctf_field_type
*ft
);
4007 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy_recursive(
4008 struct bt_ctf_field_type
*ft
);
4011 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy_recursive(
4012 struct bt_ctf_field_type
*ft
);
4015 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy_recursive(
4016 struct bt_ctf_field_type
*ft
);
4019 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy_recursive(
4020 struct bt_ctf_field_type
*type
);
4023 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
4024 struct bt_ctf_field_type
*type
);
4026 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_integer_methods
= {
4027 .freeze
= bt_ctf_field_type_common_generic_freeze
,
4028 .validate
= bt_ctf_field_type_common_integer_validate
,
4029 .set_byte_order
= bt_ctf_field_type_common_integer_set_byte_order
,
4030 .copy
= (bt_ctf_field_type_common_method_copy
)
4031 bt_ctf_field_type_integer_copy
,
4032 .compare
= bt_ctf_field_type_common_integer_compare
,
4035 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_floating_point_methods
= {
4036 .freeze
= bt_ctf_field_type_common_generic_freeze
,
4038 .set_byte_order
= bt_ctf_field_type_common_floating_point_set_byte_order
,
4039 .copy
= (bt_ctf_field_type_common_method_copy
)
4040 bt_ctf_field_type_floating_point_copy
,
4041 .compare
= bt_ctf_field_type_common_floating_point_compare
,
4044 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_enumeration_methods
= {
4045 .freeze
= bt_ctf_field_type_common_enumeration_freeze_recursive
,
4046 .validate
= bt_ctf_field_type_common_enumeration_validate_recursive
,
4047 .set_byte_order
= bt_ctf_field_type_common_enumeration_set_byte_order_recursive
,
4048 .copy
= (bt_ctf_field_type_common_method_copy
)
4049 bt_ctf_field_type_enumeration_copy_recursive
,
4050 .compare
= bt_ctf_field_type_common_enumeration_compare_recursive
,
4053 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_string_methods
= {
4054 .freeze
= bt_ctf_field_type_common_generic_freeze
,
4056 .set_byte_order
= NULL
,
4057 .copy
= (bt_ctf_field_type_common_method_copy
)
4058 bt_ctf_field_type_string_copy
,
4059 .compare
= bt_ctf_field_type_common_string_compare
,
4062 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_array_methods
= {
4063 .freeze
= bt_ctf_field_type_common_array_freeze_recursive
,
4064 .validate
= bt_ctf_field_type_common_array_validate_recursive
,
4065 .set_byte_order
= bt_ctf_field_type_common_array_set_byte_order_recursive
,
4066 .copy
= (bt_ctf_field_type_common_method_copy
)
4067 bt_ctf_field_type_array_copy_recursive
,
4068 .compare
= bt_ctf_field_type_common_array_compare_recursive
,
4071 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_sequence_methods
= {
4072 .freeze
= bt_ctf_field_type_common_sequence_freeze_recursive
,
4073 .validate
= bt_ctf_field_type_common_sequence_validate_recursive
,
4074 .set_byte_order
= bt_ctf_field_type_common_sequence_set_byte_order_recursive
,
4075 .copy
= (bt_ctf_field_type_common_method_copy
)
4076 bt_ctf_field_type_sequence_copy_recursive
,
4077 .compare
= bt_ctf_field_type_common_sequence_compare_recursive
,
4080 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_structure_methods
= {
4081 .freeze
= bt_ctf_field_type_common_structure_freeze_recursive
,
4082 .validate
= bt_ctf_field_type_common_structure_validate_recursive
,
4083 .set_byte_order
= bt_ctf_field_type_common_structure_set_byte_order_recursive
,
4084 .copy
= (bt_ctf_field_type_common_method_copy
)
4085 bt_ctf_field_type_structure_copy_recursive
,
4086 .compare
= bt_ctf_field_type_common_structure_compare_recursive
,
4089 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_variant_methods
= {
4090 .freeze
= bt_ctf_field_type_common_variant_freeze_recursive
,
4091 .validate
= bt_ctf_field_type_common_variant_validate_recursive
,
4092 .set_byte_order
= bt_ctf_field_type_common_variant_set_byte_order_recursive
,
4093 .copy
= (bt_ctf_field_type_common_method_copy
)
4094 bt_ctf_field_type_variant_copy_recursive
,
4095 .compare
= bt_ctf_field_type_common_variant_compare_recursive
,
4098 typedef int (*bt_ctf_field_type_serialize_func
)(struct bt_ctf_field_type_common
*,
4099 struct metadata_context
*);
4102 int bt_ctf_field_type_serialize_recursive(struct bt_ctf_field_type
*type
,
4103 struct metadata_context
*context
)
4106 struct bt_ctf_field_type_common
*type_common
= (void *) type
;
4107 bt_ctf_field_type_serialize_func serialize_func
;
4109 BT_ASSERT_DBG(type
);
4110 BT_ASSERT_DBG(context
);
4112 /* Make sure field type is valid before serializing it */
4113 ret
= bt_ctf_field_type_common_validate((void *) type
);
4115 BT_LOGW("Cannot serialize field type's metadata: field type is invalid: "
4120 serialize_func
= type_common
->spec
.writer
.serialize_func
;
4121 ret
= serialize_func((void *) type
, context
);
4128 const char *get_encoding_string(enum bt_ctf_string_encoding encoding
)
4130 const char *encoding_string
;
4133 case BT_CTF_STRING_ENCODING_NONE
:
4134 encoding_string
= "none";
4136 case BT_CTF_STRING_ENCODING_ASCII
:
4137 encoding_string
= "ASCII";
4139 case BT_CTF_STRING_ENCODING_UTF8
:
4140 encoding_string
= "UTF8";
4143 encoding_string
= "unknown";
4147 return encoding_string
;
4151 const char *get_integer_base_string(enum bt_ctf_integer_base base
)
4153 const char *base_string
;
4156 case BT_CTF_INTEGER_BASE_DECIMAL
:
4157 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
4158 base_string
= "decimal";
4160 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
4161 base_string
= "hexadecimal";
4163 case BT_CTF_INTEGER_BASE_OCTAL
:
4164 base_string
= "octal";
4166 case BT_CTF_INTEGER_BASE_BINARY
:
4167 base_string
= "binary";
4170 base_string
= "unknown";
4178 void append_field_name(struct metadata_context
*context
,
4181 g_string_append_c(context
->string
, ' ');
4183 if (!bt_ctf_identifier_is_valid(name
) || *name
== '_') {
4184 g_string_append_c(context
->string
, '_');
4187 g_string_append(context
->string
, name
);
4191 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type_common
*type
,
4192 struct metadata_context
*context
)
4194 struct bt_ctf_field_type_common_integer
*integer
= BT_CTF_FROM_COMMON(type
);
4197 BT_LOGD("Serializing CTF writer integer field type's metadata: "
4198 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4199 g_string_append_printf(context
->string
,
4200 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
4201 integer
->size
, type
->alignment
,
4202 (integer
->is_signed
? "true" : "false"),
4203 get_encoding_string(integer
->encoding
),
4204 get_integer_base_string(integer
->base
),
4205 bt_ctf_get_byte_order_string(integer
->user_byte_order
));
4206 if (integer
->mapped_clock_class
) {
4207 const char *clock_name
= bt_ctf_clock_class_get_name(
4208 integer
->mapped_clock_class
);
4210 BT_ASSERT_DBG(clock_name
);
4211 g_string_append_printf(context
->string
,
4212 "; map = clock.%s.value", clock_name
);
4215 g_string_append(context
->string
, "; }");
4220 int bt_ctf_field_type_enumeration_serialize_recursive(
4221 struct bt_ctf_field_type_common
*type
,
4222 struct metadata_context
*context
)
4226 struct bt_ctf_field_type_common_enumeration
*enumeration
=
4227 BT_CTF_FROM_COMMON(type
);
4228 struct bt_ctf_field_type_common
*container_type
;
4229 int container_signed
;
4231 BT_LOGD("Serializing CTF writer enumeration field type's metadata: "
4232 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4234 bt_ctf_field_type_common_enumeration_borrow_container_field_type(type
);
4235 BT_ASSERT_DBG(container_type
);
4236 container_signed
= bt_ctf_field_type_common_integer_is_signed(
4238 BT_ASSERT_DBG(container_signed
>= 0);
4239 g_string_append(context
->string
, "enum : ");
4240 BT_LOGD_STR("Serializing CTF writer enumeration field type's container field type's metadata.");
4241 ret
= bt_ctf_field_type_serialize_recursive(
4242 (void *) enumeration
->container_ft
, context
);
4244 BT_LOGW("Cannot serialize CTF writer enumeration field type's container field type's metadata: "
4245 "container-ft-addr=%p", enumeration
->container_ft
);
4249 g_string_append(context
->string
, " { ");
4250 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
4251 struct bt_ctf_enumeration_mapping
*mapping
=
4252 enumeration
->entries
->pdata
[entry
];
4253 const char *label
= g_quark_to_string(mapping
->string
);
4255 g_string_append(context
->string
, "\"");
4257 if (!bt_ctf_identifier_is_valid(label
) || label
[0] == '_') {
4258 g_string_append(context
->string
, "_");
4261 g_string_append_printf(context
->string
, "%s\" = ", label
);
4263 if (container_signed
) {
4264 if (mapping
->range_start
._signed
==
4265 mapping
->range_end
._signed
) {
4266 g_string_append_printf(context
->string
,
4268 mapping
->range_start
._signed
);
4270 g_string_append_printf(context
->string
,
4271 "%" PRId64
" ... %" PRId64
,
4272 mapping
->range_start
._signed
,
4273 mapping
->range_end
._signed
);
4276 if (mapping
->range_start
._unsigned
==
4277 mapping
->range_end
._unsigned
) {
4278 g_string_append_printf(context
->string
,
4280 mapping
->range_start
._unsigned
);
4282 g_string_append_printf(context
->string
,
4283 "%" PRIu64
" ... %" PRIu64
,
4284 mapping
->range_start
._unsigned
,
4285 mapping
->range_end
._unsigned
);
4289 g_string_append(context
->string
,
4290 ((entry
!= (enumeration
->entries
->len
- 1)) ?
4294 if (context
->field_name
->len
) {
4295 append_field_name(context
,
4296 context
->field_name
->str
);
4297 g_string_assign(context
->field_name
, "");
4305 int bt_ctf_field_type_floating_point_serialize(struct bt_ctf_field_type_common
*type
,
4306 struct metadata_context
*context
)
4308 struct bt_ctf_field_type_common_floating_point
*floating_point
=
4309 BT_CTF_FROM_COMMON(type
);
4311 BT_LOGD("Serializing CTF writer floating point number field type's metadata: "
4312 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4313 g_string_append_printf(context
->string
,
4314 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
4315 floating_point
->exp_dig
,
4316 floating_point
->mant_dig
,
4317 bt_ctf_get_byte_order_string(floating_point
->user_byte_order
),
4323 int bt_ctf_field_type_structure_serialize_recursive(
4324 struct bt_ctf_field_type_common
*type
,
4325 struct metadata_context
*context
)
4328 unsigned int indent
;
4330 struct bt_ctf_field_type_common_structure
*structure
= BT_CTF_FROM_COMMON(type
);
4331 GString
*structure_field_name
= context
->field_name
;
4333 BT_LOGD("Serializing CTF writer structure field type's metadata: "
4334 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4335 context
->field_name
= g_string_new("");
4337 context
->current_indentation_level
++;
4338 g_string_append(context
->string
, "struct {\n");
4340 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4341 struct bt_ctf_field_type_common_structure_field
*field
=
4342 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
4345 BT_LOGD("Serializing CTF writer structure field type's field metadata: "
4347 "field-ft-addr=%p, field-name=\"%s\"",
4348 i
, field
, g_quark_to_string(field
->name
));
4350 for (indent
= 0; indent
< context
->current_indentation_level
;
4352 g_string_append_c(context
->string
, '\t');
4355 g_string_assign(context
->field_name
,
4356 g_quark_to_string(field
->name
));
4357 ret
= bt_ctf_field_type_serialize_recursive(
4358 (void *) field
->type
, context
);
4360 BT_LOGW("Cannot serialize CTF writer structure field type's field's metadata: "
4362 "field-ft-addr=%p, field-name=\"%s\"",
4364 g_quark_to_string(field
->name
));
4368 if (context
->field_name
->len
) {
4369 append_field_name(context
,
4370 context
->field_name
->str
);
4372 g_string_append(context
->string
, ";\n");
4375 context
->current_indentation_level
--;
4376 for (indent
= 0; indent
< context
->current_indentation_level
;
4378 g_string_append_c(context
->string
, '\t');
4381 g_string_append_printf(context
->string
, "} align(%u)",
4385 g_string_free(context
->field_name
, TRUE
);
4386 context
->field_name
= structure_field_name
;
4391 int bt_ctf_field_type_variant_serialize_recursive(
4392 struct bt_ctf_field_type_common
*type
,
4393 struct metadata_context
*context
)
4396 unsigned int indent
;
4398 struct bt_ctf_field_type_common_variant
*variant
= BT_CTF_FROM_COMMON(type
);
4399 GString
*variant_field_name
= context
->field_name
;
4401 BT_LOGD("Serializing CTF writer variant field type's metadata: "
4402 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4403 context
->field_name
= g_string_new("");
4404 if (variant
->tag_name
->len
> 0) {
4405 g_string_append(context
->string
, "variant <");
4406 append_field_name(context
, variant
->tag_name
->str
);
4407 g_string_append(context
->string
, "> {\n");
4409 g_string_append(context
->string
, "variant {\n");
4412 context
->current_indentation_level
++;
4413 for (i
= 0; i
< variant
->choices
->len
; i
++) {
4414 struct bt_ctf_field_type_common_variant_choice
*field
=
4415 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
4418 BT_LOGD("Serializing CTF writer variant field type's field metadata: "
4420 "field-ft-addr=%p, field-name=\"%s\"",
4421 i
, field
, g_quark_to_string(field
->name
));
4423 g_string_assign(context
->field_name
,
4424 g_quark_to_string(field
->name
));
4425 for (indent
= 0; indent
< context
->current_indentation_level
;
4427 g_string_append_c(context
->string
, '\t');
4430 g_string_assign(context
->field_name
,
4431 g_quark_to_string(field
->name
));
4432 ret
= bt_ctf_field_type_serialize_recursive(
4433 (void *) field
->type
, context
);
4435 BT_LOGW("Cannot serialize CTF writer variant field type's field's metadata: "
4437 "field-ft-addr=%p, field-name=\"%s\"",
4439 g_quark_to_string(field
->name
));
4443 if (context
->field_name
->len
) {
4444 append_field_name(context
,
4445 context
->field_name
->str
);
4446 g_string_append_c(context
->string
, ';');
4449 g_string_append_c(context
->string
, '\n');
4452 context
->current_indentation_level
--;
4453 for (indent
= 0; indent
< context
->current_indentation_level
;
4455 g_string_append_c(context
->string
, '\t');
4458 g_string_append(context
->string
, "}");
4461 g_string_free(context
->field_name
, TRUE
);
4462 context
->field_name
= variant_field_name
;
4467 int bt_ctf_field_type_array_serialize_recursive(
4468 struct bt_ctf_field_type_common
*type
,
4469 struct metadata_context
*context
)
4472 struct bt_ctf_field_type_common_array
*array
= BT_CTF_FROM_COMMON(type
);
4474 BT_LOGD("Serializing CTF writer array field type's metadata: "
4475 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4476 BT_LOGD_STR("Serializing CTF writer array field type's element field type's metadata.");
4477 ret
= bt_ctf_field_type_serialize_recursive(
4478 (void *) array
->element_ft
, context
);
4480 BT_LOGW("Cannot serialize CTF writer array field type's element field type's metadata: "
4481 "element-ft-addr=%p", array
->element_ft
);
4485 if (context
->field_name
->len
) {
4486 append_field_name(context
,
4487 context
->field_name
->str
);
4489 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4490 g_string_assign(context
->field_name
, "");
4492 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4500 int bt_ctf_field_type_sequence_serialize_recursive(
4501 struct bt_ctf_field_type_common
*type
,
4502 struct metadata_context
*context
)
4505 struct bt_ctf_field_type_common_sequence
*sequence
= BT_CTF_FROM_COMMON(type
);
4507 BT_LOGD("Serializing CTF writer sequence field type's metadata: "
4508 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4509 BT_LOGD_STR("Serializing CTF writer sequence field type's element field type's metadata.");
4510 ret
= bt_ctf_field_type_serialize_recursive(
4511 (void *) sequence
->element_ft
, context
);
4513 BT_LOGW("Cannot serialize CTF writer sequence field type's element field type's metadata: "
4514 "element-ft-addr=%p", sequence
->element_ft
);
4518 if (context
->field_name
->len
) {
4519 append_field_name(context
, context
->field_name
->str
);
4520 g_string_assign(context
->field_name
, "");
4522 g_string_append(context
->string
, "[");
4523 append_field_name(context
, sequence
->length_field_name
->str
);
4524 g_string_append(context
->string
, "]");
4531 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type_common
*type
,
4532 struct metadata_context
*context
)
4534 struct bt_ctf_field_type_common_string
*string
= BT_CTF_FROM_COMMON(type
);
4536 BT_LOGD("Serializing CTF writer string field type's metadata: "
4537 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4538 g_string_append_printf(context
->string
,
4539 "string { encoding = %s; }",
4540 get_encoding_string(string
->encoding
));
4544 struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(unsigned int size
)
4546 struct bt_ctf_field_type_common_integer
*integer
= NULL
;
4548 BT_LOGD("Creating CTF writer integer field type object: size=%u", size
);
4550 if (size
== 0 || size
> 64) {
4551 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
4556 integer
= g_new0(struct bt_ctf_field_type_common_integer
, 1);
4558 BT_LOGE_STR("Failed to allocate one integer field type.");
4562 bt_ctf_field_type_common_integer_initialize(BT_CTF_TO_COMMON(integer
),
4563 size
, bt_ctf_field_type_common_integer_destroy
,
4564 &bt_ctf_field_type_integer_methods
);
4565 integer
->common
.spec
.writer
.serialize_func
=
4566 bt_ctf_field_type_integer_serialize
;
4567 BT_LOGD("Created CTF writer integer field type object: addr=%p, size=%u",
4572 BT_CTF_OBJECT_PUT_REF_AND_RESET(integer
);
4575 return (void *) integer
;
4578 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type
*ft
)
4580 return bt_ctf_field_type_common_integer_get_size((void *) ft
);
4583 bt_ctf_bool
bt_ctf_field_type_integer_is_signed(struct bt_ctf_field_type
*ft
)
4585 return bt_ctf_field_type_common_integer_is_signed((void *) ft
);
4588 int bt_ctf_field_type_integer_set_is_signed(struct bt_ctf_field_type
*ft
,
4589 bt_ctf_bool is_signed
)
4591 return bt_ctf_field_type_common_integer_set_is_signed((void *) ft
,
4595 int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type
*ft
,
4598 return bt_ctf_field_type_common_integer_set_size((void *) ft
, size
);
4601 enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
4602 struct bt_ctf_field_type
*ft
)
4604 return (int) bt_ctf_field_type_common_integer_get_base((void *) ft
);
4607 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*ft
,
4608 enum bt_ctf_integer_base base
)
4610 return bt_ctf_field_type_common_integer_set_base((void *) ft
,
4614 enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
4615 struct bt_ctf_field_type
*ft
)
4617 return (int) bt_ctf_field_type_common_integer_get_encoding((void *) ft
);
4620 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type
*ft
,
4621 enum bt_ctf_string_encoding encoding
)
4623 return bt_ctf_field_type_common_integer_set_encoding((void *) ft
,
4627 struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
4628 struct bt_ctf_field_type
*ft
)
4630 return bt_ctf_object_get_ref(bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
4634 int bt_ctf_field_type_integer_set_mapped_clock_class(
4635 struct bt_ctf_field_type
*ft
,
4636 struct bt_ctf_clock_class
*clock_class
)
4638 return bt_ctf_field_type_common_integer_set_mapped_clock_class((void *) ft
,
4642 int bt_ctf_field_type_enumeration_signed_get_mapping_by_index(
4643 struct bt_ctf_field_type
*ft
, uint64_t index
,
4644 const char **mapping_name
, int64_t *range_begin
,
4647 return bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
4648 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
4651 int bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(
4652 struct bt_ctf_field_type
*ft
, uint64_t index
,
4653 const char **mapping_name
, uint64_t *range_begin
,
4654 uint64_t *range_end
)
4656 return bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
4657 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
4660 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
4661 struct bt_ctf_field_type
*container_ft
)
4663 struct bt_ctf_field_type_common_enumeration
*enumeration
= NULL
;
4664 struct bt_ctf_field_type_common
*int_ft
= (void *) container_ft
;
4666 BT_LOGD("Creating CTF writer enumeration field type object: int-ft-addr=%p",
4669 if (!container_ft
) {
4670 BT_LOGW_STR("Invalid parameter: field type is NULL.");
4674 if (int_ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
4675 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
4676 "container-ft-addr=%p, container-ft-id=%s",
4677 container_ft
, bt_ctf_field_type_id_string(int_ft
->id
));
4681 enumeration
= g_new0(struct bt_ctf_field_type_common_enumeration
, 1);
4683 BT_LOGE_STR("Failed to allocate one enumeration field type.");
4687 bt_ctf_field_type_common_enumeration_initialize(BT_CTF_TO_COMMON(enumeration
),
4688 int_ft
, bt_ctf_field_type_common_enumeration_destroy_recursive
,
4689 &bt_ctf_field_type_enumeration_methods
);
4690 enumeration
->common
.spec
.writer
.serialize_func
=
4691 bt_ctf_field_type_enumeration_serialize_recursive
;
4692 BT_LOGD("Created CTF writer enumeration field type object: addr=%p, "
4693 "int-ft-addr=%p, int-ft-size=%u",
4694 enumeration
, container_ft
,
4695 bt_ctf_field_type_integer_get_size(container_ft
));
4699 BT_CTF_OBJECT_PUT_REF_AND_RESET(enumeration
);
4702 return (void *) enumeration
;
4705 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_field_type(
4706 struct bt_ctf_field_type
*ft
)
4708 return bt_ctf_object_get_ref(
4709 bt_ctf_field_type_common_enumeration_borrow_container_field_type(
4713 int bt_ctf_field_type_enumeration_signed_add_mapping(
4714 struct bt_ctf_field_type
*ft
, const char *string
,
4715 int64_t range_start
, int64_t range_end
)
4717 return bt_ctf_field_type_common_enumeration_signed_add_mapping(
4718 (void *) ft
, string
, range_start
, range_end
);
4721 int bt_ctf_field_type_enumeration_unsigned_add_mapping(
4722 struct bt_ctf_field_type
*ft
, const char *string
,
4723 uint64_t range_start
, uint64_t range_end
)
4725 return bt_ctf_field_type_common_enumeration_unsigned_add_mapping(
4726 (void *) ft
, string
, range_start
, range_end
);
4729 int64_t bt_ctf_field_type_enumeration_get_mapping_count(
4730 struct bt_ctf_field_type
*ft
)
4732 return bt_ctf_field_type_common_enumeration_get_mapping_count((void *) ft
);
4735 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void)
4737 struct bt_ctf_field_type_common_floating_point
*floating_point
=
4738 g_new0(struct bt_ctf_field_type_common_floating_point
, 1);
4740 BT_LOGD_STR("Creating CTF writer floating point number field type object.");
4742 if (!floating_point
) {
4743 BT_LOGE_STR("Failed to allocate one floating point number field type.");
4747 bt_ctf_field_type_common_floating_point_initialize(
4748 BT_CTF_TO_COMMON(floating_point
),
4749 bt_ctf_field_type_common_floating_point_destroy
,
4750 &bt_ctf_field_type_floating_point_methods
);
4751 floating_point
->common
.spec
.writer
.serialize_func
=
4752 bt_ctf_field_type_floating_point_serialize
;
4753 BT_LOGD("Created CTF writer floating point number field type object: addr=%p, "
4754 "exp-size=%u, mant-size=%u", floating_point
,
4755 floating_point
->exp_dig
, floating_point
->mant_dig
);
4758 return (void *) floating_point
;
4761 int bt_ctf_field_type_floating_point_get_exponent_digits(
4762 struct bt_ctf_field_type
*ft
)
4764 return bt_ctf_field_type_common_floating_point_get_exponent_digits(
4768 int bt_ctf_field_type_floating_point_set_exponent_digits(
4769 struct bt_ctf_field_type
*ft
, unsigned int exponent_digits
)
4771 return bt_ctf_field_type_common_floating_point_set_exponent_digits(
4772 (void *) ft
, exponent_digits
);
4775 int bt_ctf_field_type_floating_point_get_mantissa_digits(
4776 struct bt_ctf_field_type
*ft
)
4778 return bt_ctf_field_type_common_floating_point_get_mantissa_digits(
4782 int bt_ctf_field_type_floating_point_set_mantissa_digits(
4783 struct bt_ctf_field_type
*ft
, unsigned int mantissa_digits
)
4785 return bt_ctf_field_type_common_floating_point_set_mantissa_digits(
4786 (void *) ft
, mantissa_digits
);
4789 struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void)
4791 struct bt_ctf_field_type_common_structure
*structure
=
4792 g_new0(struct bt_ctf_field_type_common_structure
, 1);
4794 BT_LOGD_STR("Creating CTF writer structure field type object.");
4797 BT_LOGE_STR("Failed to allocate one structure field type.");
4801 bt_ctf_field_type_common_structure_initialize(BT_CTF_TO_COMMON(structure
),
4802 bt_ctf_field_type_common_structure_destroy_recursive
,
4803 &bt_ctf_field_type_structure_methods
);
4804 structure
->common
.spec
.writer
.serialize_func
=
4805 bt_ctf_field_type_structure_serialize_recursive
;
4806 BT_LOGD("Created CTF writer structure field type object: addr=%p",
4811 BT_CTF_OBJECT_PUT_REF_AND_RESET(structure
);
4814 return (void *) structure
;
4817 int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type
*ft
,
4818 struct bt_ctf_field_type
*field_type
,
4819 const char *field_name
)
4821 return bt_ctf_field_type_common_structure_add_field((void *) ft
,
4822 (void *) field_type
, field_name
);
4825 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type
*ft
)
4827 return bt_ctf_field_type_common_structure_get_field_count((void *) ft
);
4830 int bt_ctf_field_type_structure_get_field_by_index(
4831 struct bt_ctf_field_type
*ft
,
4832 const char **field_name
,
4833 struct bt_ctf_field_type
**field_type
, uint64_t index
)
4835 int ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
4836 (void *) ft
, field_name
, (void *) field_type
, index
);
4838 if (ret
== 0 && field_type
) {
4839 bt_ctf_object_get_ref(*field_type
);
4845 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
4846 struct bt_ctf_field_type
*ft
, const char *name
)
4848 return bt_ctf_object_get_ref(bt_ctf_field_type_common_structure_borrow_field_type_by_name(
4849 (void *) ft
, name
));
4852 struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
4853 struct bt_ctf_field_type
*tag_ft
, const char *tag_name
)
4855 struct bt_ctf_field_type_common_variant
*var_ft
= NULL
;
4857 BT_LOGD("Creating CTF writer variant field type object: "
4858 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4861 if (tag_name
&& !bt_ctf_identifier_is_valid(tag_name
)) {
4862 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
4863 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4868 var_ft
= g_new0(struct bt_ctf_field_type_common_variant
, 1);
4870 BT_LOGE_STR("Failed to allocate one variant field type.");
4874 bt_ctf_field_type_common_variant_initialize(BT_CTF_TO_COMMON(var_ft
),
4875 (void *) tag_ft
, tag_name
,
4876 bt_ctf_field_type_common_variant_destroy_recursive
,
4877 &bt_ctf_field_type_variant_methods
);
4878 var_ft
->common
.spec
.writer
.serialize_func
=
4879 bt_ctf_field_type_variant_serialize_recursive
;
4880 BT_LOGD("Created CTF writer variant field type object: addr=%p, "
4881 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4882 var_ft
, tag_ft
, tag_name
);
4886 BT_CTF_OBJECT_PUT_REF_AND_RESET(var_ft
);
4889 return (void *) var_ft
;
4892 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_field_type(
4893 struct bt_ctf_field_type
*ft
)
4895 return bt_ctf_object_get_ref(bt_ctf_field_type_common_variant_borrow_tag_field_type(
4899 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type
*ft
)
4901 return bt_ctf_field_type_common_variant_get_tag_name((void *) ft
);
4904 int bt_ctf_field_type_variant_set_tag_name(
4905 struct bt_ctf_field_type
*ft
, const char *name
)
4907 return bt_ctf_field_type_common_variant_set_tag_name((void *) ft
, name
);
4910 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type
*ft
,
4911 struct bt_ctf_field_type
*field_type
,
4912 const char *field_name
)
4914 return bt_ctf_field_type_common_variant_add_field((void *) ft
,
4915 (void *) field_type
, field_name
);
4918 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
4919 struct bt_ctf_field_type
*ft
,
4920 const char *field_name
)
4922 return bt_ctf_object_get_ref(bt_ctf_field_type_common_variant_borrow_field_type_by_name(
4923 (void *) ft
, field_name
));
4926 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
4927 struct bt_ctf_field_type
*ft
,
4928 struct bt_ctf_field
*tag_field
)
4931 int64_t choice_index
;
4932 struct bt_ctf_field
*container
;
4933 struct bt_ctf_field_type_common_variant
*var_ft
= (void *) ft
;
4934 struct bt_ctf_field_type
*ret_ft
= NULL
;
4936 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
4937 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
4939 BT_CTF_ASSERT_PRE_NON_NULL(tag_field
, "Tag field");
4940 BT_CTF_ASSERT_PRE_CTF_FIELD_COMMON_HAS_TYPE_ID(
4941 (struct bt_ctf_field_common
*) tag_field
,
4942 BT_CTF_FIELD_TYPE_ID_ENUM
, "Tag field");
4943 BT_CTF_ASSERT_PRE_CTF_FIELD_COMMON_IS_SET((struct bt_ctf_field_common
*) tag_field
,
4946 container
= bt_ctf_field_enumeration_borrow_container(tag_field
);
4947 BT_ASSERT_DBG(container
);
4949 if (var_ft
->tag_ft
->container_ft
->is_signed
) {
4952 ret
= bt_ctf_field_integer_signed_get_value(container
,
4954 BT_ASSERT_DBG(ret
== 0);
4955 choice_index
= bt_ctf_field_type_common_variant_find_choice_index(
4956 (void *) ft
, (uint64_t) val
, true);
4960 ret
= bt_ctf_field_integer_unsigned_get_value(container
,
4962 BT_ASSERT_DBG(ret
== 0);
4963 choice_index
= bt_ctf_field_type_common_variant_find_choice_index(
4964 (void *) ft
, val
, false);
4967 if (choice_index
< 0) {
4968 BT_LOGW("Cannot find variant field type's field: "
4969 "var-ft-addr=%p, tag-field-addr=%p", ft
, tag_field
);
4973 ret
= bt_ctf_field_type_variant_get_field_by_index(ft
, NULL
,
4974 &ret_ft
, choice_index
);
4975 BT_ASSERT_DBG(ret
== 0);
4981 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type
*ft
)
4983 return bt_ctf_field_type_common_variant_get_field_count((void *) ft
);
4986 int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type
*ft
,
4987 const char **field_name
, struct bt_ctf_field_type
**field_type
,
4990 int ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
4991 (void *) ft
, field_name
, (void *) field_type
, index
);
4993 if (ret
== 0 && field_type
) {
4994 bt_ctf_object_get_ref(*field_type
);
5000 struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
5001 struct bt_ctf_field_type
*element_ft
, unsigned int length
)
5003 struct bt_ctf_field_type_common_array
*array
= NULL
;
5005 BT_LOGD("Creating CTF writer array field type object: element-ft-addr=%p, "
5006 "length=%u", element_ft
, length
);
5009 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
5014 BT_LOGW_STR("Invalid parameter: length is zero.");
5018 array
= g_new0(struct bt_ctf_field_type_common_array
, 1);
5020 BT_LOGE_STR("Failed to allocate one array field type.");
5024 bt_ctf_field_type_common_array_initialize(BT_CTF_TO_COMMON(array
),
5025 (void *) element_ft
, length
,
5026 bt_ctf_field_type_common_array_destroy_recursive
,
5027 &bt_ctf_field_type_array_methods
);
5028 array
->common
.spec
.writer
.serialize_func
=
5029 bt_ctf_field_type_array_serialize_recursive
;
5030 BT_LOGD("Created CTF writer array field type object: addr=%p, "
5031 "element-ft-addr=%p, length=%u",
5032 array
, element_ft
, length
);
5036 BT_CTF_OBJECT_PUT_REF_AND_RESET(array
);
5039 return (void *) array
;
5042 struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_field_type(
5043 struct bt_ctf_field_type
*ft
)
5045 return bt_ctf_object_get_ref(bt_ctf_field_type_common_array_borrow_element_field_type(
5049 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type
*ft
)
5051 return bt_ctf_field_type_common_array_get_length((void *) ft
);
5054 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
5055 struct bt_ctf_field_type
*element_ft
,
5056 const char *length_field_name
)
5058 struct bt_ctf_field_type_common_sequence
*sequence
= NULL
;
5060 BT_LOGD("Creating CTF writer sequence field type object: element-ft-addr=%p, "
5061 "length-field-name=\"%s\"", element_ft
, length_field_name
);
5064 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
5068 if (!bt_ctf_identifier_is_valid(length_field_name
)) {
5069 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
5070 "length-field-name=\"%s\"", length_field_name
);
5074 sequence
= g_new0(struct bt_ctf_field_type_common_sequence
, 1);
5076 BT_LOGE_STR("Failed to allocate one sequence field type.");
5080 bt_ctf_field_type_common_sequence_initialize(BT_CTF_TO_COMMON(sequence
),
5081 (void *) element_ft
, length_field_name
,
5082 bt_ctf_field_type_common_sequence_destroy_recursive
,
5083 &bt_ctf_field_type_sequence_methods
);
5084 sequence
->common
.spec
.writer
.serialize_func
=
5085 bt_ctf_field_type_sequence_serialize_recursive
;
5086 BT_LOGD("Created CTF writer sequence field type object: addr=%p, "
5087 "element-ft-addr=%p, length-field-name=\"%s\"",
5088 sequence
, element_ft
, length_field_name
);
5092 BT_CTF_OBJECT_PUT_REF_AND_RESET(sequence
);
5095 return (void *) sequence
;
5098 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_field_type(
5099 struct bt_ctf_field_type
*ft
)
5101 return bt_ctf_object_get_ref(bt_ctf_field_type_common_sequence_borrow_element_field_type(
5105 const char *bt_ctf_field_type_sequence_get_length_field_name(
5106 struct bt_ctf_field_type
*ft
)
5108 return bt_ctf_field_type_common_sequence_get_length_field_name((void *) ft
);
5111 struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void)
5113 struct bt_ctf_field_type_common_string
*string
=
5114 g_new0(struct bt_ctf_field_type_common_string
, 1);
5116 BT_LOGD_STR("Creating CTF writer string field type object.");
5119 BT_LOGE_STR("Failed to allocate one string field type.");
5123 bt_ctf_field_type_common_string_initialize(BT_CTF_TO_COMMON(string
),
5124 bt_ctf_field_type_common_string_destroy
,
5125 &bt_ctf_field_type_string_methods
);
5126 string
->common
.spec
.writer
.serialize_func
=
5127 bt_ctf_field_type_string_serialize
;
5128 BT_LOGD("Created CTF writer string field type object: addr=%p", string
);
5129 return (void *) string
;
5132 enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
5133 struct bt_ctf_field_type
*ft
)
5135 return (int) bt_ctf_field_type_common_string_get_encoding((void *) ft
);
5138 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type
*ft
,
5139 enum bt_ctf_string_encoding encoding
)
5141 return bt_ctf_field_type_common_string_set_encoding((void *) ft
,
5145 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*ft
)
5147 return bt_ctf_field_type_common_get_alignment((void *) ft
);
5150 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*ft
,
5151 unsigned int alignment
)
5153 return bt_ctf_field_type_common_set_alignment((void *) ft
, alignment
);
5156 enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
5157 struct bt_ctf_field_type
*ft
)
5159 return (int) bt_ctf_field_type_common_get_byte_order((void *) ft
);
5162 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*ft
,
5163 enum bt_ctf_byte_order byte_order
)
5165 return bt_ctf_field_type_common_set_byte_order((void *) ft
,
5169 enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
5170 struct bt_ctf_field_type
*ft
)
5172 return (int) bt_ctf_field_type_common_get_type_id((void *) ft
);
5176 struct bt_ctf_field_type
*bt_ctf_field_type_copy(struct bt_ctf_field_type
*ft
)
5178 return (void *) bt_ctf_field_type_common_copy((void *) ft
);
5182 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
5183 struct bt_ctf_field_type
*ft
)
5185 struct bt_ctf_field_type_common_integer
*int_ft
= (void *) ft
;
5186 struct bt_ctf_field_type_common_integer
*copy_ft
;
5188 BT_LOGD("Copying CTF writer integer field type's: addr=%p", ft
);
5189 copy_ft
= (void *) bt_ctf_field_type_integer_create(int_ft
->size
);
5191 BT_LOGE_STR("Cannot create CTF writer integer field type.");
5195 copy_ft
->mapped_clock_class
= bt_ctf_object_get_ref(int_ft
->mapped_clock_class
);
5196 copy_ft
->user_byte_order
= int_ft
->user_byte_order
;
5197 copy_ft
->is_signed
= int_ft
->is_signed
;
5198 copy_ft
->size
= int_ft
->size
;
5199 copy_ft
->base
= int_ft
->base
;
5200 copy_ft
->encoding
= int_ft
->encoding
;
5201 BT_LOGD("Copied CTF writer integer field type: original-ft-addr=%p, copy-ft-addr=%p",
5205 return (void *) copy_ft
;
5209 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy_recursive(
5210 struct bt_ctf_field_type
*ft
)
5213 struct bt_ctf_field_type_common_enumeration
*enum_ft
= (void *) ft
;
5214 struct bt_ctf_field_type_common_enumeration
*copy_ft
= NULL
;
5215 struct bt_ctf_field_type_common_enumeration
*container_copy_ft
;
5217 BT_LOGD("Copying CTF writer enumeration field type's: addr=%p", ft
);
5219 /* Copy the source enumeration's container */
5220 BT_LOGD_STR("Copying CTF writer enumeration field type's container field type.");
5221 container_copy_ft
= BT_CTF_FROM_COMMON(bt_ctf_field_type_common_copy(
5222 BT_CTF_TO_COMMON(enum_ft
->container_ft
)));
5223 if (!container_copy_ft
) {
5224 BT_LOGE_STR("Cannot copy CTF writer enumeration field type's container field type.");
5228 copy_ft
= (void *) bt_ctf_field_type_enumeration_create(
5229 (void *) container_copy_ft
);
5231 BT_LOGE_STR("Cannot create CTF writer enumeration field type.");
5235 /* Copy all enumaration entries */
5236 for (i
= 0; i
< enum_ft
->entries
->len
; i
++) {
5237 struct bt_ctf_enumeration_mapping
*mapping
= g_ptr_array_index(
5238 enum_ft
->entries
, i
);
5239 struct bt_ctf_enumeration_mapping
*copy_mapping
= g_new0(
5240 struct bt_ctf_enumeration_mapping
, 1);
5242 if (!copy_mapping
) {
5243 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
5247 *copy_mapping
= *mapping
;
5248 g_ptr_array_add(copy_ft
->entries
, copy_mapping
);
5251 BT_LOGD("Copied CTF writer enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
5255 bt_ctf_object_put_ref(container_copy_ft
);
5256 return (void *) copy_ft
;
5259 bt_ctf_object_put_ref(container_copy_ft
);
5260 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5261 return (void *) copy_ft
;
5265 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
5266 struct bt_ctf_field_type
*ft
)
5268 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
5269 struct bt_ctf_field_type_common_floating_point
*copy_ft
;
5271 BT_LOGD("Copying CTF writer floating point number field type's: addr=%p", ft
);
5272 copy_ft
= (void *) bt_ctf_field_type_floating_point_create();
5274 BT_LOGE_STR("Cannot create CTF writer floating point number field type.");
5278 copy_ft
->user_byte_order
= flt_ft
->user_byte_order
;
5279 copy_ft
->exp_dig
= flt_ft
->exp_dig
;
5280 copy_ft
->mant_dig
= flt_ft
->mant_dig
;
5281 BT_LOGD("Copied CTF writer floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
5285 return (void *) copy_ft
;
5289 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy_recursive(
5290 struct bt_ctf_field_type
*ft
)
5293 GHashTableIter iter
;
5294 gpointer key
, value
;
5295 struct bt_ctf_field_type_common_structure
*struct_ft
= (void *) ft
;
5296 struct bt_ctf_field_type_common_structure
*copy_ft
;
5298 BT_LOGD("Copying CTF writer structure field type's: addr=%p", ft
);
5299 copy_ft
= (void *) bt_ctf_field_type_structure_create();
5301 BT_LOGE_STR("Cannot create CTF writer structure field type.");
5305 /* Copy field_name_to_index */
5306 g_hash_table_iter_init(&iter
, struct_ft
->field_name_to_index
);
5307 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
5308 g_hash_table_insert(copy_ft
->field_name_to_index
,
5312 g_array_set_size(copy_ft
->fields
, struct_ft
->fields
->len
);
5314 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
5315 struct bt_ctf_field_type_common_structure_field
*entry
, *copy_entry
;
5316 struct bt_ctf_field_type_common
*field_ft_copy
;
5318 entry
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
5320 copy_entry
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
5322 BT_LOGD("Copying CTF writer structure field type's field: "
5323 "index=%" PRId64
", "
5324 "field-ft-addr=%p, field-name=\"%s\"",
5325 i
, entry
, g_quark_to_string(entry
->name
));
5327 field_ft_copy
= (void *) bt_ctf_field_type_copy(
5328 (void *) entry
->type
);
5329 if (!field_ft_copy
) {
5330 BT_LOGE("Cannot copy CTF writer structure field type's field: "
5331 "index=%" PRId64
", "
5332 "field-ft-addr=%p, field-name=\"%s\"",
5333 i
, entry
, g_quark_to_string(entry
->name
));
5337 copy_entry
->name
= entry
->name
;
5338 copy_entry
->type
= field_ft_copy
;
5341 BT_LOGD("Copied CTF writer structure field type: original-ft-addr=%p, copy-ft-addr=%p",
5345 return (void *) copy_ft
;
5348 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5353 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy_recursive(
5354 struct bt_ctf_field_type
*ft
)
5357 GHashTableIter iter
;
5358 gpointer key
, value
;
5359 struct bt_ctf_field_type_common
*tag_ft_copy
= NULL
;
5360 struct bt_ctf_field_type_common_variant
*var_ft
= (void *) ft
;
5361 struct bt_ctf_field_type_common_variant
*copy_ft
= NULL
;
5363 BT_LOGD("Copying CTF writer variant field type's: addr=%p", ft
);
5364 if (var_ft
->tag_ft
) {
5365 BT_LOGD_STR("Copying CTF writer variant field type's tag field type.");
5366 tag_ft_copy
= bt_ctf_field_type_common_copy(
5367 BT_CTF_TO_COMMON(var_ft
->tag_ft
));
5369 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field type.");
5374 copy_ft
= (void *) bt_ctf_field_type_variant_create(
5375 (void *) tag_ft_copy
,
5376 var_ft
->tag_name
->len
? var_ft
->tag_name
->str
: NULL
);
5378 BT_LOGE_STR("Cannot create CTF writer variant field type.");
5382 /* Copy field_name_to_index */
5383 g_hash_table_iter_init(&iter
, var_ft
->choice_name_to_index
);
5384 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
5385 g_hash_table_insert(copy_ft
->choice_name_to_index
,
5389 g_array_set_size(copy_ft
->choices
, var_ft
->choices
->len
);
5391 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
5392 struct bt_ctf_field_type_common_variant_choice
*entry
, *copy_entry
;
5393 struct bt_ctf_field_type_common
*field_ft_copy
;
5396 entry
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
, i
);
5397 copy_entry
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
5399 BT_LOGD("Copying CTF writer variant field type's field: "
5400 "index=%" PRId64
", "
5401 "field-ft-addr=%p, field-name=\"%s\"",
5402 i
, entry
, g_quark_to_string(entry
->name
));
5404 field_ft_copy
= (void *) bt_ctf_field_type_copy(
5405 (void *) entry
->type
);
5406 if (!field_ft_copy
) {
5407 BT_LOGE("Cannot copy CTF writer variant field type's field: "
5408 "index=%" PRId64
", "
5409 "field-ft-addr=%p, field-name=\"%s\"",
5410 i
, entry
, g_quark_to_string(entry
->name
));
5415 copy_entry
->name
= entry
->name
;
5416 copy_entry
->type
= field_ft_copy
;
5419 copy_entry
->ranges
= g_array_new(FALSE
, TRUE
,
5420 sizeof(struct bt_ctf_field_type_common_variant_choice_range
));
5421 BT_ASSERT_DBG(copy_entry
->ranges
);
5422 g_array_set_size(copy_entry
->ranges
, entry
->ranges
->len
);
5424 for (range_i
= 0; range_i
< entry
->ranges
->len
; range_i
++) {
5425 copy_entry
->ranges
[range_i
] = entry
->ranges
[range_i
];
5429 if (var_ft
->tag_field_path
) {
5430 BT_LOGD_STR("Copying CTF writer variant field type's tag field path.");
5431 copy_ft
->tag_field_path
= bt_ctf_field_path_copy(
5432 var_ft
->tag_field_path
);
5433 if (!copy_ft
->tag_field_path
) {
5434 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field path.");
5439 copy_ft
->choices_up_to_date
= var_ft
->choices_up_to_date
;
5440 BT_LOGD("Copied CTF writer variant field type: original-ft-addr=%p, copy-ft-addr=%p",
5444 bt_ctf_object_put_ref(tag_ft_copy
);
5445 return (void *) copy_ft
;
5448 bt_ctf_object_put_ref(tag_ft_copy
);
5449 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5454 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy_recursive(
5455 struct bt_ctf_field_type
*ft
)
5457 struct bt_ctf_field_type_common
*container_ft_copy
= NULL
;
5458 struct bt_ctf_field_type_common_array
*array_ft
= (void *) ft
;
5459 struct bt_ctf_field_type_common_array
*copy_ft
= NULL
;
5461 BT_LOGD("Copying CTF writer array field type's: addr=%p", ft
);
5462 BT_LOGD_STR("Copying CTF writer array field type's element field type.");
5463 container_ft_copy
= bt_ctf_field_type_common_copy(array_ft
->element_ft
);
5464 if (!container_ft_copy
) {
5465 BT_LOGE_STR("Cannot copy CTF writer array field type's element field type.");
5469 copy_ft
= (void *) bt_ctf_field_type_array_create(
5470 (void *) container_ft_copy
, array_ft
->length
);
5472 BT_LOGE_STR("Cannot create CTF writer array field type.");
5476 BT_LOGD("Copied CTF writer array field type: original-ft-addr=%p, copy-ft-addr=%p",
5480 bt_ctf_object_put_ref(container_ft_copy
);
5481 return (void *) copy_ft
;
5485 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy_recursive(
5486 struct bt_ctf_field_type
*ft
)
5488 struct bt_ctf_field_type_common
*container_ft_copy
= NULL
;
5489 struct bt_ctf_field_type_common_sequence
*seq_ft
= (void *) ft
;
5490 struct bt_ctf_field_type_common_sequence
*copy_ft
= NULL
;
5492 BT_LOGD("Copying CTF writer sequence field type's: addr=%p", ft
);
5493 BT_LOGD_STR("Copying CTF writer sequence field type's element field type.");
5494 container_ft_copy
= bt_ctf_field_type_common_copy(seq_ft
->element_ft
);
5495 if (!container_ft_copy
) {
5496 BT_LOGE_STR("Cannot copy CTF writer sequence field type's element field type.");
5500 copy_ft
= (void *) bt_ctf_field_type_sequence_create(
5501 (void *) container_ft_copy
,
5502 seq_ft
->length_field_name
->len
?
5503 seq_ft
->length_field_name
->str
: NULL
);
5505 BT_LOGE_STR("Cannot create CTF writer sequence field type.");
5509 if (seq_ft
->length_field_path
) {
5510 BT_LOGD_STR("Copying CTF writer sequence field type's length field path.");
5511 copy_ft
->length_field_path
= bt_ctf_field_path_copy(
5512 seq_ft
->length_field_path
);
5513 if (!copy_ft
->length_field_path
) {
5514 BT_LOGE_STR("Cannot copy CTF writer sequence field type's length field path.");
5519 BT_LOGD("Copied CTF writer sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
5523 bt_ctf_object_put_ref(container_ft_copy
);
5524 return (void *) copy_ft
;
5526 bt_ctf_object_put_ref(container_ft_copy
);
5527 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5532 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(struct bt_ctf_field_type
*ft
)
5534 struct bt_ctf_field_type_common_string
*string_ft
= (void *) ft
;
5535 struct bt_ctf_field_type_common_string
*copy_ft
= NULL
;
5537 BT_LOGD("Copying CTF writer string field type's: addr=%p", ft
);
5538 copy_ft
= (void *) bt_ctf_field_type_string_create();
5540 BT_LOGE_STR("Cannot create CTF writer string field type.");
5544 copy_ft
->encoding
= string_ft
->encoding
;
5545 BT_LOGD("Copied CTF writer string field type: original-ft-addr=%p, copy-ft-addr=%p",
5549 return (void *) copy_ft
;