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
)
39 void bt_ctf_field_type_common_initialize(struct bt_ctf_field_type_common
*ft
,
40 bool init_bo
, bt_ctf_object_release_func release_func
,
41 struct bt_ctf_field_type_common_methods
*methods
)
43 BT_ASSERT_DBG(ft
&& (ft
->id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
) &&
44 (ft
->id
< BT_CTF_FIELD_TYPE_ID_NR
));
46 bt_ctf_object_init_shared(&ft
->base
, release_func
);
47 ft
->methods
= methods
;
51 const enum bt_ctf_byte_order bo
= BT_CTF_BYTE_ORDER_NATIVE
;
53 BT_LOGD("Setting initial field type's byte order: bo=%s",
54 bt_ctf_byte_order_string(bo
));
55 ret
= bt_ctf_field_type_common_set_byte_order(ft
, bo
);
56 BT_ASSERT_DBG(ret
== 0);
62 void bt_ctf_field_type_common_integer_initialize(
63 struct bt_ctf_field_type_common
*ft
,
64 unsigned int size
, bt_ctf_object_release_func release_func
,
65 struct bt_ctf_field_type_common_methods
*methods
)
67 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
69 BT_ASSERT_DBG(size
> 0);
70 BT_LOGD("Initializing common integer field type object: size=%u",
72 ft
->id
= BT_CTF_FIELD_TYPE_ID_INTEGER
;
74 int_ft
->base
= BT_CTF_INTEGER_BASE_DECIMAL
;
75 int_ft
->encoding
= BT_CTF_STRING_ENCODING_NONE
;
76 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
77 BT_LOGD("Initialized common integer field type object: addr=%p, size=%u",
81 void bt_ctf_field_type_common_floating_point_initialize(
82 struct bt_ctf_field_type_common
*ft
,
83 bt_ctf_object_release_func release_func
,
84 struct bt_ctf_field_type_common_methods
*methods
)
86 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
88 BT_LOGD_STR("Initializing common floating point number field type object.");
89 ft
->id
= BT_CTF_FIELD_TYPE_ID_FLOAT
;
90 flt_ft
->exp_dig
= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
;
91 flt_ft
->mant_dig
= FLT_MANT_DIG
;
92 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
93 BT_LOGD("Initialized common floating point number field type object: addr=%p, "
94 "exp-size=%u, mant-size=%u", ft
, flt_ft
->exp_dig
,
98 void bt_ctf_field_type_common_enumeration_initialize(
99 struct bt_ctf_field_type_common
*ft
,
100 struct bt_ctf_field_type_common
*container_ft
,
101 bt_ctf_object_release_func release_func
,
102 struct bt_ctf_field_type_common_methods
*methods
)
104 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
106 BT_ASSERT_DBG(container_ft
);
107 BT_LOGD("Initializing common enumeration field type object: int-ft-addr=%p",
109 ft
->id
= BT_CTF_FIELD_TYPE_ID_ENUM
;
110 enum_ft
->container_ft
= bt_ctf_object_get_ref(container_ft
);
111 enum_ft
->entries
= g_ptr_array_new_with_free_func(
112 (GDestroyNotify
) destroy_enumeration_mapping
);
113 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
114 BT_LOGD("Initialized common enumeration field type object: addr=%p, "
115 "int-ft-addr=%p, int-ft-size=%u", ft
, container_ft
,
116 bt_ctf_field_type_common_integer_get_size(container_ft
));
119 void bt_ctf_field_type_common_string_initialize(
120 struct bt_ctf_field_type_common
*ft
,
121 bt_ctf_object_release_func release_func
,
122 struct bt_ctf_field_type_common_methods
*methods
)
124 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
126 BT_LOGD_STR("Initializing common string field type object.");
127 ft
->id
= BT_CTF_FIELD_TYPE_ID_STRING
;
128 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
129 string_ft
->encoding
= BT_CTF_STRING_ENCODING_UTF8
;
130 ft
->alignment
= CHAR_BIT
;
131 BT_LOGD("Initialized common string field type object: addr=%p", ft
);
134 void bt_ctf_field_type_common_structure_initialize(
135 struct bt_ctf_field_type_common
*ft
,
136 bt_ctf_object_release_func release_func
,
137 struct bt_ctf_field_type_common_methods
*methods
)
139 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
141 BT_LOGD_STR("Initializing common structure field type object.");
142 ft
->id
= BT_CTF_FIELD_TYPE_ID_STRUCT
;
143 struct_ft
->fields
= g_array_new(FALSE
, TRUE
,
144 sizeof(struct bt_ctf_field_type_common_structure_field
));
145 struct_ft
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
146 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
147 BT_LOGD("Initialized common structure field type object: addr=%p", ft
);
150 void bt_ctf_field_type_common_array_initialize(
151 struct bt_ctf_field_type_common
*ft
,
152 struct bt_ctf_field_type_common
*element_ft
,
153 unsigned int length
, bt_ctf_object_release_func release_func
,
154 struct bt_ctf_field_type_common_methods
*methods
)
156 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
158 BT_ASSERT_DBG(element_ft
);
159 BT_LOGD("Initializing common array field type object: element-ft-addr=%p, "
160 "length=%u", element_ft
, length
);
161 ft
->id
= BT_CTF_FIELD_TYPE_ID_ARRAY
;
162 array_ft
->element_ft
= bt_ctf_object_get_ref(element_ft
);
163 array_ft
->length
= length
;
164 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
165 BT_LOGD("Initialized common array field type object: addr=%p, "
166 "element-ft-addr=%p, length=%u", ft
, element_ft
, length
);
169 void bt_ctf_field_type_common_sequence_initialize(
170 struct bt_ctf_field_type_common
*ft
,
171 struct bt_ctf_field_type_common
*element_ft
,
172 const char *length_field_name
,
173 bt_ctf_object_release_func release_func
,
174 struct bt_ctf_field_type_common_methods
*methods
)
176 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
178 BT_ASSERT_DBG(element_ft
);
179 BT_ASSERT_DBG(length_field_name
);
180 BT_ASSERT_DBG(bt_ctf_identifier_is_valid(length_field_name
));
181 BT_LOGD("Initializing common sequence field type object: element-ft-addr=%p, "
182 "length-field-name=\"%s\"", element_ft
, length_field_name
);
183 ft
->id
= BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
184 seq_ft
->element_ft
= bt_ctf_object_get_ref(element_ft
);
185 seq_ft
->length_field_name
= g_string_new(length_field_name
);
186 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
187 BT_LOGD("Initialized common sequence field type object: addr=%p, "
188 "element-ft-addr=%p, length-field-name=\"%s\"",
189 ft
, element_ft
, length_field_name
);
192 void bt_ctf_field_type_common_variant_initialize(
193 struct bt_ctf_field_type_common
*ft
,
194 struct bt_ctf_field_type_common
*tag_ft
,
195 const char *tag_name
,
196 bt_ctf_object_release_func release_func
,
197 struct bt_ctf_field_type_common_methods
*methods
)
199 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
201 BT_ASSERT_DBG(!tag_name
|| bt_ctf_identifier_is_valid(tag_name
));
202 BT_LOGD("Initializing common variant field type object: "
203 "tag-ft-addr=%p, tag-field-name=\"%s\"",
205 ft
->id
= BT_CTF_FIELD_TYPE_ID_VARIANT
;
206 var_ft
->tag_name
= g_string_new(tag_name
);
207 var_ft
->choice_name_to_index
= g_hash_table_new(NULL
, NULL
);
208 var_ft
->choices
= g_array_new(FALSE
, TRUE
,
209 sizeof(struct bt_ctf_field_type_common_variant_choice
));
212 var_ft
->tag_ft
= bt_ctf_object_get_ref(tag_ft
);
215 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
216 /* A variant's alignment is undefined */
218 BT_LOGD("Initialized common variant field type object: addr=%p, "
219 "tag-ft-addr=%p, tag-field-name=\"%s\"",
220 ft
, tag_ft
, tag_name
);
223 void bt_ctf_field_type_common_integer_destroy(struct bt_ctf_object
*obj
)
225 struct bt_ctf_field_type_common_integer
*ft
= (void *) obj
;
231 BT_LOGD("Destroying integer field type object: addr=%p", ft
);
232 BT_LOGD_STR("Putting mapped clock class.");
233 bt_ctf_object_put_ref(ft
->mapped_clock_class
);
237 void bt_ctf_field_type_common_floating_point_destroy(struct bt_ctf_object
*obj
)
239 struct bt_ctf_field_type_common_floating_point
*ft
= (void *) obj
;
245 BT_LOGD("Destroying floating point number field type object: addr=%p", ft
);
249 void bt_ctf_field_type_common_enumeration_destroy_recursive(struct bt_ctf_object
*obj
)
251 struct bt_ctf_field_type_common_enumeration
*ft
= (void *) obj
;
257 BT_LOGD("Destroying enumeration field type object: addr=%p", ft
);
258 g_ptr_array_free(ft
->entries
, TRUE
);
259 BT_LOGD_STR("Putting container field type.");
260 bt_ctf_object_put_ref(ft
->container_ft
);
264 void bt_ctf_field_type_common_string_destroy(struct bt_ctf_object
*obj
)
266 struct bt_ctf_field_type_common_string
*ft
= (void *) obj
;
272 BT_LOGD("Destroying string field type object: addr=%p", ft
);
277 void bt_ctf_field_type_common_structure_field_finalize(
278 struct bt_ctf_field_type_common_structure_field
*field
)
284 BT_LOGD("Finalizing structure field type's field: "
285 "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
286 field
, field
->type
, g_quark_to_string(field
->name
));
287 BT_LOGD_STR("Putting field type.");
288 bt_ctf_object_put_ref(field
->type
);
291 void bt_ctf_field_type_common_structure_destroy_recursive(struct bt_ctf_object
*obj
)
293 struct bt_ctf_field_type_common_structure
*ft
= (void *) obj
;
300 BT_LOGD("Destroying structure field type object: addr=%p", ft
);
303 for (i
= 0; i
< ft
->fields
->len
; i
++) {
304 bt_ctf_field_type_common_structure_field_finalize(
305 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
309 g_array_free(ft
->fields
, TRUE
);
312 if (ft
->field_name_to_index
) {
313 g_hash_table_destroy(ft
->field_name_to_index
);
319 void bt_ctf_field_type_common_array_destroy_recursive(struct bt_ctf_object
*obj
)
321 struct bt_ctf_field_type_common_array
*ft
= (void *) obj
;
327 BT_LOGD("Destroying array field type object: addr=%p", ft
);
328 BT_LOGD_STR("Putting element field type.");
329 bt_ctf_object_put_ref(ft
->element_ft
);
333 void bt_ctf_field_type_common_sequence_destroy_recursive(struct bt_ctf_object
*obj
)
335 struct bt_ctf_field_type_common_sequence
*ft
= (void *) obj
;
341 BT_LOGD("Destroying sequence field type object: addr=%p", ft
);
342 BT_LOGD_STR("Putting element field type.");
343 bt_ctf_object_put_ref(ft
->element_ft
);
344 g_string_free(ft
->length_field_name
, TRUE
);
345 BT_LOGD_STR("Putting length field path.");
346 bt_ctf_object_put_ref(ft
->length_field_path
);
351 void bt_ctf_field_type_common_variant_choice_finalize(
352 struct bt_ctf_field_type_common_variant_choice
*choice
)
358 BT_LOGD("Finalizing variant field type's choice: "
359 "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
360 choice
, choice
->type
, g_quark_to_string(choice
->name
));
361 BT_LOGD_STR("Putting field type.");
362 bt_ctf_object_put_ref(choice
->type
);
364 if (choice
->ranges
) {
365 g_array_free(choice
->ranges
, TRUE
);
369 void bt_ctf_field_type_common_variant_destroy_recursive(struct bt_ctf_object
*obj
)
371 struct bt_ctf_field_type_common_variant
*ft
= (void *) obj
;
378 BT_LOGD("Destroying variant field type object: addr=%p", ft
);
381 for (i
= 0; i
< ft
->choices
->len
; i
++) {
382 bt_ctf_field_type_common_variant_choice_finalize(
383 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
387 g_array_free(ft
->choices
, TRUE
);
390 if (ft
->choice_name_to_index
) {
391 g_hash_table_destroy(ft
->choice_name_to_index
);
395 g_string_free(ft
->tag_name
, TRUE
);
398 BT_LOGD_STR("Putting tag field type.");
399 bt_ctf_object_put_ref(ft
->tag_ft
);
400 BT_LOGD_STR("Putting tag field path.");
401 bt_ctf_object_put_ref(ft
->tag_field_path
);
405 struct range_overlap_query
{
420 void check_ranges_overlap(gpointer element
, gpointer query
)
422 struct bt_ctf_enumeration_mapping
*mapping
= element
;
423 struct range_overlap_query
*overlap_query
= query
;
425 if (mapping
->range_start
._signed
<= overlap_query
->range_end
._signed
426 && overlap_query
->range_start
._signed
<=
427 mapping
->range_end
._signed
) {
428 overlap_query
->overlaps
= 1;
429 overlap_query
->mapping_name
= mapping
->string
;
432 overlap_query
->overlaps
|=
433 mapping
->string
== overlap_query
->mapping_name
;
435 if (overlap_query
->overlaps
) {
436 BT_LOGT("Overlapping enumeration field type mappings: "
437 "mapping-name=\"%s\", "
438 "mapping-a-range-start=%" PRId64
", "
439 "mapping-a-range-end=%" PRId64
", "
440 "mapping-b-range-start=%" PRId64
", "
441 "mapping-b-range-end=%" PRId64
,
442 g_quark_to_string(mapping
->string
),
443 mapping
->range_start
._signed
,
444 mapping
->range_end
._signed
,
445 overlap_query
->range_start
._signed
,
446 overlap_query
->range_end
._signed
);
451 void check_ranges_overlap_unsigned(gpointer element
, gpointer query
)
453 struct bt_ctf_enumeration_mapping
*mapping
= element
;
454 struct range_overlap_query
*overlap_query
= query
;
456 if (mapping
->range_start
._unsigned
<= overlap_query
->range_end
._unsigned
457 && overlap_query
->range_start
._unsigned
<=
458 mapping
->range_end
._unsigned
) {
459 overlap_query
->overlaps
= 1;
460 overlap_query
->mapping_name
= mapping
->string
;
463 overlap_query
->overlaps
|=
464 mapping
->string
== overlap_query
->mapping_name
;
466 if (overlap_query
->overlaps
) {
467 BT_LOGW("Overlapping enumeration field type mappings: "
468 "mapping-name=\"%s\", "
469 "mapping-a-range-start=%" PRIu64
", "
470 "mapping-a-range-end=%" PRIu64
", "
471 "mapping-b-range-start=%" PRIu64
", "
472 "mapping-b-range-end=%" PRIu64
,
473 g_quark_to_string(mapping
->string
),
474 mapping
->range_start
._unsigned
,
475 mapping
->range_end
._unsigned
,
476 overlap_query
->range_start
._unsigned
,
477 overlap_query
->range_end
._unsigned
);
482 gint
compare_enumeration_mappings_signed(struct bt_ctf_enumeration_mapping
**a
,
483 struct bt_ctf_enumeration_mapping
**b
)
485 return ((*a
)->range_start
._signed
< (*b
)->range_start
._signed
) ? -1 : 1;
489 gint
compare_enumeration_mappings_unsigned(struct bt_ctf_enumeration_mapping
**a
,
490 struct bt_ctf_enumeration_mapping
**b
)
492 return ((*a
)->range_start
._unsigned
< (*b
)->range_start
._unsigned
) ? -1 : 1;
496 int add_structure_variant_member(GArray
*members
,
497 GHashTable
*field_name_to_index
,
498 struct bt_ctf_field_type_common
*field_type
, const char *field_name
,
502 GQuark name_quark
= g_quark_from_string(field_name
);
503 struct bt_ctf_field_type_common
**member_ft
;
506 /* Make sure structure does not contain a field of the same name */
507 if (g_hash_table_lookup_extended(field_name_to_index
,
508 GUINT_TO_POINTER(name_quark
), NULL
, NULL
)) {
509 BT_LOGW("Structure or variant field type already contains a field type with this name: "
510 "field-name=\"%s\"", field_name
);
515 g_array_set_size(members
, members
->len
+ 1);
518 struct bt_ctf_field_type_common_variant_choice
*choice
=
519 &bt_g_array_index(members
,
520 struct bt_ctf_field_type_common_variant_choice
,
523 member_ft
= &choice
->type
;
524 member_name
= &choice
->name
;
525 BT_ASSERT_DBG(!choice
->ranges
);
526 choice
->ranges
= g_array_new(FALSE
, TRUE
,
527 sizeof(struct bt_ctf_field_type_common_variant_choice_range
));
528 BT_ASSERT_DBG(choice
->ranges
);
530 struct bt_ctf_field_type_common_structure_field
*field
=
531 &bt_g_array_index(members
,
532 struct bt_ctf_field_type_common_structure_field
,
535 member_ft
= &field
->type
;
536 member_name
= &field
->name
;
539 *member_name
= name_quark
;
540 *member_ft
= bt_ctf_object_get_ref(field_type
);
541 g_hash_table_insert(field_name_to_index
,
542 GUINT_TO_POINTER(name_quark
),
543 GUINT_TO_POINTER(members
->len
- 1));
544 BT_LOGT("Added structure/variant field type member: member-ft-addr=%p, "
545 "member-name=\"%s\"", field_type
, field_name
);
551 int bt_ctf_field_type_common_integer_validate(struct bt_ctf_field_type_common
*ft
)
554 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
556 if (int_ft
->mapped_clock_class
&& int_ft
->is_signed
) {
557 BT_LOGW("Invalid integer field type: cannot be signed and have a mapped clock class: "
558 "ft-addr=%p, clock-class-addr=%p, clock-class-name=\"%s\"",
559 ft
, int_ft
->mapped_clock_class
,
560 bt_ctf_clock_class_get_name(int_ft
->mapped_clock_class
));
570 void bt_ctf_field_type_enum_iter_destroy(struct bt_ctf_object
*obj
)
572 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
574 struct bt_ctf_field_type_enumeration_mapping_iterator
,
577 BT_LOGD("Destroying enumeration field type mapping iterator: addr=%p",
579 BT_LOGD_STR("Putting parent enumeration field type.");
580 bt_ctf_object_put_ref(iter
->enumeration_ft
);
585 struct bt_ctf_field_type_enumeration_mapping_iterator
*
586 bt_ctf_field_type_common_enumeration_find_mappings_type(
587 struct bt_ctf_field_type_common
*ft
,
588 enum bt_ctf_field_type_enumeration_mapping_iterator_type iterator_type
)
590 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
592 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
593 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
,
595 iter
= g_new0(struct bt_ctf_field_type_enumeration_mapping_iterator
, 1);
597 BT_LOGE_STR("Failed to allocate one enumeration field type mapping.");
601 bt_ctf_object_init_shared(&iter
->base
, bt_ctf_field_type_enum_iter_destroy
);
602 iter
->enumeration_ft
= bt_ctf_object_get_ref(ft
);
604 iter
->type
= iterator_type
;
610 struct bt_ctf_field_type_enumeration_mapping_iterator
*
611 bt_ctf_field_type_common_enumeration_find_mappings_by_name(
612 struct bt_ctf_field_type_common
*ft
, const char *name
)
614 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
616 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
617 ft
, CTF_ITERATOR_BY_NAME
);
619 BT_LOGW("Cannot create enumeration field type mapping iterator: "
620 "ft-addr=%p, mapping-name=\"%s\"", ft
, name
);
624 iter
->u
.name_quark
= g_quark_try_string(name
);
625 if (!iter
->u
.name_quark
) {
627 * No results are possible, set the iterator's position at the
630 iter
->index
= iter
->enumeration_ft
->entries
->len
;
636 bt_ctf_object_put_ref(iter
);
641 struct bt_ctf_enumeration_mapping
*bt_ctf_field_type_common_enumeration_get_mapping_by_index(
642 struct bt_ctf_field_type_common
*ft
, uint64_t index
)
644 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
645 struct bt_ctf_enumeration_mapping
*mapping
= NULL
;
647 if (index
>= enum_ft
->entries
->len
) {
648 BT_LOGW("Invalid parameter: index is out of bounds: "
649 "addr=%p, index=%" PRIu64
", count=%u",
650 ft
, index
, enum_ft
->entries
->len
);
654 mapping
= g_ptr_array_index(enum_ft
->entries
, index
);
660 int bt_ctf_field_type_enumeration_mapping_iterator_next(
661 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
)
663 struct bt_ctf_field_type_common_enumeration
*enum_ft
= iter
->enumeration_ft
;
666 BT_CTF_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
667 len
= enum_ft
->entries
->len
;
668 for (i
= iter
->index
+ 1; i
< len
; i
++) {
669 struct bt_ctf_enumeration_mapping
*mapping
=
670 bt_ctf_field_type_common_enumeration_get_mapping_by_index(
671 BT_CTF_TO_COMMON(enum_ft
), i
);
673 switch (iter
->type
) {
674 case CTF_ITERATOR_BY_NAME
:
675 if (mapping
->string
== iter
->u
.name_quark
) {
680 case CTF_ITERATOR_BY_SIGNED_VALUE
:
682 int64_t value
= iter
->u
.signed_value
;
684 if (value
>= mapping
->range_start
._signed
&&
685 value
<= mapping
->range_end
._signed
) {
691 case CTF_ITERATOR_BY_UNSIGNED_VALUE
:
693 uint64_t value
= iter
->u
.unsigned_value
;
695 if (value
>= mapping
->range_start
._unsigned
&&
696 value
<= mapping
->range_end
._unsigned
) {
703 BT_LOGF("Invalid enumeration field type mapping iterator type: "
704 "type=%d", iter
->type
);
715 struct bt_ctf_field_type_enumeration_mapping_iterator
*
716 bt_ctf_field_type_common_enumeration_signed_find_mappings_by_value(
717 struct bt_ctf_field_type_common
*ft
, int64_t value
)
719 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
721 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
722 ft
, CTF_ITERATOR_BY_SIGNED_VALUE
);
724 BT_LOGW("Cannot create enumeration field type mapping iterator: "
725 "ft-addr=%p, value=%" PRId64
, ft
, value
);
729 if (bt_ctf_field_type_common_integer_is_signed(
730 BT_CTF_TO_COMMON(iter
->enumeration_ft
->container_ft
)) != 1) {
731 BT_LOGW("Invalid parameter: enumeration field type is unsigned: "
732 "enum-ft-addr=%p, int-ft-addr=%p",
733 ft
, iter
->enumeration_ft
->container_ft
);
737 iter
->u
.signed_value
= value
;
741 bt_ctf_object_put_ref(iter
);
745 struct bt_ctf_field_type_enumeration_mapping_iterator
*
746 bt_ctf_field_type_common_enumeration_unsigned_find_mappings_by_value(
747 struct bt_ctf_field_type_common
*ft
, uint64_t value
)
749 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
751 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
752 ft
, CTF_ITERATOR_BY_UNSIGNED_VALUE
);
754 BT_LOGW("Cannot create enumeration field type mapping iterator: "
755 "ft-addr=%p, value=%" PRIu64
, ft
, value
);
759 if (bt_ctf_field_type_common_integer_is_signed(
760 BT_CTF_TO_COMMON(iter
->enumeration_ft
->container_ft
)) != 0) {
761 BT_LOGW("Invalid parameter: enumeration field type is signed: "
762 "enum-ft-addr=%p, int-ft-addr=%p",
763 ft
, iter
->enumeration_ft
->container_ft
);
767 iter
->u
.unsigned_value
= value
;
771 bt_ctf_object_put_ref(iter
);
775 int bt_ctf_field_type_enumeration_mapping_iterator_signed_get(
776 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
777 const char **mapping_name
, int64_t *range_begin
,
780 BT_CTF_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
781 BT_CTF_ASSERT_PRE(iter
->index
!= -1,
782 "Invalid enumeration field type mapping iterator access: "
783 "addr=%p, position=-1", iter
);
784 return bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
785 (void *) iter
->enumeration_ft
, iter
->index
,
786 mapping_name
, range_begin
, range_end
);
789 int bt_ctf_field_type_enumeration_mapping_iterator_unsigned_get(
790 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
791 const char **mapping_name
, uint64_t *range_begin
,
794 BT_CTF_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
795 BT_CTF_ASSERT_PRE(iter
->index
!= -1,
796 "Invalid enumeration field type mapping iterator access: "
797 "addr=%p, position=-1", iter
);
798 return bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
799 (void *) iter
->enumeration_ft
, iter
->index
,
800 mapping_name
, range_begin
, range_end
);
804 * Note: This algorithm is O(n^2) vs number of enumeration mappings.
805 * Only used when freezing an enumeration.
808 void bt_ctf_field_type_common_enumeration_set_range_overlap(
809 struct bt_ctf_field_type_common_enumeration
*ft
)
814 BT_LOGT("Setting enumeration field type's overlap flag: addr=%p",
816 len
= ft
->entries
->len
;
817 is_signed
= bt_ctf_field_type_common_integer_is_signed(
818 BT_CTF_TO_COMMON(ft
->container_ft
));
820 for (i
= 0; i
< len
; i
++) {
821 for (j
= i
+ 1; j
< len
; j
++) {
822 struct bt_ctf_enumeration_mapping
*mapping
[2];
824 mapping
[0] = bt_ctf_field_type_common_enumeration_get_mapping_by_index(
825 BT_CTF_TO_COMMON(ft
), i
);
826 mapping
[1] = bt_ctf_field_type_common_enumeration_get_mapping_by_index(
827 BT_CTF_TO_COMMON(ft
), j
);
829 if (mapping
[0]->range_start
._signed
830 <= mapping
[1]->range_end
._signed
831 && mapping
[0]->range_end
._signed
832 >= mapping
[1]->range_start
._signed
) {
833 ft
->has_overlapping_ranges
= BT_CTF_TRUE
;
837 if (mapping
[0]->range_start
._unsigned
838 <= mapping
[1]->range_end
._unsigned
839 && mapping
[0]->range_end
._unsigned
840 >= mapping
[1]->range_start
._unsigned
) {
841 ft
->has_overlapping_ranges
= BT_CTF_TRUE
;
849 if (ft
->has_overlapping_ranges
) {
850 BT_LOGT_STR("Enumeration field type has overlapping ranges.");
852 BT_LOGT_STR("Enumeration field type has no overlapping ranges.");
856 int bt_ctf_field_type_common_enumeration_validate_recursive(
857 struct bt_ctf_field_type_common
*ft
)
860 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
862 ret
= bt_ctf_field_type_common_integer_validate(
863 BT_CTF_TO_COMMON(enum_ft
->container_ft
));
865 BT_LOGW("Invalid enumeration field type: container type is invalid: "
866 "enum-ft-addr=%p, int-ft-addr=%p",
867 ft
, enum_ft
->container_ft
);
871 /* Ensure enum has entries */
872 if (enum_ft
->entries
->len
== 0) {
873 BT_LOGW("Invalid enumeration field type: no entries: "
883 int bt_ctf_field_type_common_sequence_validate_recursive(
884 struct bt_ctf_field_type_common
*ft
)
887 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
889 /* Length field name should be set at this point */
890 if (seq_ft
->length_field_name
->len
== 0) {
891 BT_LOGW("Invalid sequence field type: no length field name: "
897 ret
= bt_ctf_field_type_common_validate(seq_ft
->element_ft
);
899 BT_LOGW("Invalid sequence field type: invalid element field type: "
900 "seq-ft-addr=%p, element-ft-add=%p",
901 ft
, seq_ft
->element_ft
);
908 int bt_ctf_field_type_common_array_validate_recursive(
909 struct bt_ctf_field_type_common
*ft
)
912 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
914 ret
= bt_ctf_field_type_common_validate(array_ft
->element_ft
);
916 BT_LOGW("Invalid array field type: invalid element field type: "
917 "array-ft-addr=%p, element-ft-add=%p",
918 ft
, array_ft
->element_ft
);
924 int bt_ctf_field_type_common_structure_validate_recursive(
925 struct bt_ctf_field_type_common
*ft
)
928 struct bt_ctf_field_type_common
*child_ft
= NULL
;
929 int64_t field_count
=
930 bt_ctf_field_type_common_structure_get_field_count(ft
);
933 BT_ASSERT_DBG(field_count
>= 0);
935 for (i
= 0; i
< field_count
; ++i
) {
936 const char *field_name
;
938 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(ft
,
939 &field_name
, &child_ft
, i
);
940 BT_ASSERT_DBG(ret
== 0);
941 ret
= bt_ctf_field_type_common_validate(child_ft
);
943 BT_LOGW("Invalid structure field type: "
944 "a contained field type is invalid: "
945 "struct-ft-addr=%p, field-ft-addr=%p, "
946 "field-name=\"%s\", field-index=%" PRId64
,
947 ft
, child_ft
, field_name
, i
);
957 bt_ctf_bool
bt_ctf_field_type_common_enumeration_has_overlapping_ranges(
958 struct bt_ctf_field_type_common_enumeration
*enum_ft
)
960 if (!enum_ft
->common
.frozen
) {
961 bt_ctf_field_type_common_enumeration_set_range_overlap(enum_ft
);
964 return enum_ft
->has_overlapping_ranges
;
967 int bt_ctf_field_type_common_variant_validate_recursive(
968 struct bt_ctf_field_type_common
*ft
)
972 struct bt_ctf_field_type_common
*child_ft
= NULL
;
973 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
976 if (var_ft
->tag_name
->len
== 0) {
977 BT_LOGW("Invalid variant field type: no tag field name: "
983 if (!var_ft
->tag_ft
) {
984 BT_LOGW("Invalid variant field type: no tag field type: "
985 "addr=%p, tag-field-name=\"%s\"", var_ft
,
986 var_ft
->tag_name
->str
);
991 if (bt_ctf_field_type_common_enumeration_has_overlapping_ranges(var_ft
->tag_ft
)) {
992 BT_LOGW("Invalid variant field type: enumeration tag field type has overlapping ranges: "
993 "variant-ft-addr=%p, tag-field-name=\"%s\", "
994 "enum-ft-addr=%p", ft
, var_ft
->tag_name
->str
,
1001 * It is valid to have a variant field type which does not have
1002 * the fields corresponding to each label in the associated
1005 * It is also valid to have variant field type fields which
1006 * cannot be selected because the variant field type tag has no
1007 * mapping named as such. This scenario, while not ideal, cannot
1010 * If a non-existing field happens to be selected by an
1011 * enumeration while reading a variant field, an error will be
1012 * generated at that point (while reading the stream).
1014 field_count
= bt_ctf_field_type_common_variant_get_field_count(ft
);
1015 if (field_count
< 0) {
1016 BT_LOGW("Invalid variant field type: no fields: "
1017 "addr=%p, tag-field-name=\"%s\"",
1018 ft
, var_ft
->tag_name
->str
);
1023 for (i
= 0; i
< field_count
; ++i
) {
1024 const char *field_name
;
1026 ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(ft
,
1027 &field_name
, &child_ft
, i
);
1028 BT_ASSERT_DBG(ret
== 0);
1029 ret
= bt_ctf_field_type_common_validate(child_ft
);
1031 BT_LOGW("Invalid variant field type: "
1032 "a contained field type is invalid: "
1033 "variant-ft-addr=%p, tag-field-name=\"%s\", "
1034 "field-ft-addr=%p, field-name=\"%s\", "
1035 "field-index=%" PRId64
,
1036 ft
, var_ft
->tag_name
->str
, child_ft
,
1047 * This function validates a given field type without considering
1048 * where this field type is located. It only validates the properties
1049 * of the given field type and the properties of its children if
1052 int bt_ctf_field_type_common_validate(struct bt_ctf_field_type_common
*ft
)
1059 /* Already marked as valid */
1063 if (ft
->methods
->validate
) {
1064 ret
= ft
->methods
->validate(ft
);
1067 if (ret
== 0 && ft
->frozen
) {
1068 /* Field type is valid */
1069 BT_LOGT("Marking field type as valid: addr=%p", ft
);
1077 int bt_ctf_field_type_common_integer_get_size(struct bt_ctf_field_type_common
*ft
)
1079 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1081 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1082 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1084 return (int) int_ft
->size
;
1087 bt_ctf_bool
bt_ctf_field_type_common_integer_is_signed(struct bt_ctf_field_type_common
*ft
)
1089 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1091 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1092 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1094 return int_ft
->is_signed
;
1097 int bt_ctf_field_type_common_integer_set_is_signed(struct bt_ctf_field_type_common
*ft
,
1098 bt_ctf_bool is_signed
)
1101 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1104 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1110 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1116 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1117 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1118 "addr=%p, ft-id=%s", ft
,
1119 bt_ctf_field_type_id_string(ft
->id
));
1124 int_ft
->is_signed
= !!is_signed
;
1125 BT_LOGT("Set integer field type's signedness: addr=%p, is-signed=%d",
1132 int bt_ctf_field_type_common_integer_set_size(struct bt_ctf_field_type_common
*ft
,
1136 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1139 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1145 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1151 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1152 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1153 "addr=%p, ft-id=%s", ft
,
1154 bt_ctf_field_type_id_string(ft
->id
));
1159 if (size
== 0 || size
> 64) {
1160 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
1161 "addr=%p, size=%u", ft
, size
);
1166 int_ft
->size
= size
;
1167 BT_LOGT("Set integer field type's size: addr=%p, size=%u",
1174 enum bt_ctf_integer_base
bt_ctf_field_type_common_integer_get_base(
1175 struct bt_ctf_field_type_common
*ft
)
1177 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1179 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1180 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1182 return int_ft
->base
;
1185 int bt_ctf_field_type_common_integer_set_base(struct bt_ctf_field_type_common
*ft
,
1186 enum bt_ctf_integer_base base
)
1189 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1192 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1198 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1204 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1205 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1206 "addr=%p, ft-id=%s", ft
,
1207 bt_ctf_field_type_id_string(ft
->id
));
1213 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
1214 case BT_CTF_INTEGER_BASE_BINARY
:
1215 case BT_CTF_INTEGER_BASE_OCTAL
:
1216 case BT_CTF_INTEGER_BASE_DECIMAL
:
1217 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
1219 int_ft
->base
= base
;
1223 BT_LOGW("Invalid parameter: unknown integer field type base: "
1224 "addr=%p, base=%d", ft
, base
);
1228 BT_LOGT("Set integer field type's base: addr=%p, base=%s",
1229 ft
, bt_ctf_integer_base_string(base
));
1235 enum bt_ctf_string_encoding
bt_ctf_field_type_common_integer_get_encoding(
1236 struct bt_ctf_field_type_common
*ft
)
1238 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1240 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1241 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1243 return int_ft
->encoding
;
1246 int bt_ctf_field_type_common_integer_set_encoding(struct bt_ctf_field_type_common
*ft
,
1247 enum bt_ctf_string_encoding encoding
)
1250 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1253 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1259 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1265 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1266 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1267 "addr=%p, ft-id=%s", ft
,
1268 bt_ctf_field_type_id_string(ft
->id
));
1273 if (encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
1274 encoding
!= BT_CTF_STRING_ENCODING_ASCII
&&
1275 encoding
!= BT_CTF_STRING_ENCODING_NONE
) {
1276 BT_LOGW("Invalid parameter: unknown string encoding: "
1277 "addr=%p, encoding=%d", ft
, encoding
);
1282 int_ft
->encoding
= encoding
;
1283 BT_LOGT("Set integer field type's encoding: addr=%p, encoding=%s",
1284 ft
, bt_ctf_string_encoding_string(encoding
));
1290 struct bt_ctf_clock_class
*bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
1291 struct bt_ctf_field_type_common
*ft
)
1293 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1295 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1296 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1298 return int_ft
->mapped_clock_class
;
1301 int bt_ctf_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
1302 struct bt_ctf_field_type_common
*ft
,
1303 struct bt_ctf_clock_class
*clock_class
)
1305 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1309 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
1314 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1315 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1316 "addr=%p, ft-id=%s", ft
,
1317 bt_ctf_field_type_id_string(ft
->id
));
1321 if (!bt_ctf_clock_class_is_valid(clock_class
)) {
1322 BT_LOGW("Invalid parameter: clock class is invalid: ft-addr=%p"
1323 "clock-class-addr=%p, clock-class-name=\"%s\"",
1325 bt_ctf_clock_class_get_name(clock_class
));
1330 bt_ctf_object_put_ref(int_ft
->mapped_clock_class
);
1331 int_ft
->mapped_clock_class
= bt_ctf_object_get_ref(clock_class
);
1332 BT_LOGT("Set integer field type's mapped clock class: ft-addr=%p, "
1333 "clock-class-addr=%p, clock-class-name=\"%s\"",
1334 ft
, clock_class
, bt_ctf_clock_class_get_name(clock_class
));
1340 int bt_ctf_field_type_common_integer_set_mapped_clock_class(
1341 struct bt_ctf_field_type_common
*ft
,
1342 struct bt_ctf_clock_class
*clock_class
)
1347 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1353 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1359 ret
= bt_ctf_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
1366 int bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
1367 struct bt_ctf_field_type_common
*ft
, uint64_t index
,
1368 const char **mapping_name
, int64_t *range_begin
,
1372 struct bt_ctf_enumeration_mapping
*mapping
;
1374 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1375 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
,
1376 BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1377 mapping
= bt_ctf_field_type_common_enumeration_get_mapping_by_index(ft
,
1380 /* bt_ctf_field_type_common_enumeration_get_mapping_by_index() logs errors */
1386 *mapping_name
= g_quark_to_string(mapping
->string
);
1387 BT_ASSERT_DBG(*mapping_name
);
1391 *range_begin
= mapping
->range_start
._signed
;
1395 *range_end
= mapping
->range_end
._signed
;
1402 int bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
1403 struct bt_ctf_field_type_common
*ft
, uint64_t index
,
1404 const char **mapping_name
, uint64_t *range_begin
,
1405 uint64_t *range_end
)
1408 struct bt_ctf_enumeration_mapping
*mapping
;
1410 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1411 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1412 mapping
= bt_ctf_field_type_common_enumeration_get_mapping_by_index(
1415 /* bt_ctf_field_type_common_enumeration_get_mapping_by_index() reports any error */
1421 *mapping_name
= g_quark_to_string(mapping
->string
);
1422 BT_ASSERT_DBG(*mapping_name
);
1426 *range_begin
= mapping
->range_start
._unsigned
;
1430 *range_end
= mapping
->range_end
._unsigned
;
1437 struct bt_ctf_field_type_common
*
1438 bt_ctf_field_type_common_enumeration_borrow_container_field_type(
1439 struct bt_ctf_field_type_common
*ft
)
1441 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1443 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1444 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1445 return BT_CTF_TO_COMMON(enum_ft
->container_ft
);
1448 int bt_ctf_field_type_common_enumeration_signed_add_mapping(
1449 struct bt_ctf_field_type_common
*ft
, const char *string
,
1450 int64_t range_start
, int64_t range_end
)
1453 GQuark mapping_name
;
1454 struct bt_ctf_enumeration_mapping
*mapping
;
1455 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1456 char *escaped_string
;
1459 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1465 BT_LOGW_STR("Invalid parameter: string is NULL.");
1471 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1477 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1478 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1479 "addr=%p, ft-id=%s", ft
,
1480 bt_ctf_field_type_id_string(ft
->id
));
1485 if (range_end
< range_start
) {
1486 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1487 "addr=%p, range-start=%" PRId64
", range-end=%" PRId64
,
1488 ft
, range_start
, range_end
);
1493 if (strlen(string
) == 0) {
1494 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1495 "enum-ft-addr=%p, mapping-name-addr=%p", ft
,
1501 escaped_string
= g_strescape(string
, NULL
);
1502 if (!escaped_string
) {
1503 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1504 "mapping-name-addr=%p, mapping-name=\"%s\"",
1505 ft
, string
, string
);
1510 mapping
= g_new(struct bt_ctf_enumeration_mapping
, 1);
1512 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1516 mapping_name
= g_quark_from_string(escaped_string
);
1517 *mapping
= (struct bt_ctf_enumeration_mapping
) {
1518 .range_start
._signed
= range_start
,
1519 .range_end
._signed
= range_end
,
1520 .string
= mapping_name
,
1522 g_ptr_array_add(enum_ft
->entries
, mapping
);
1523 g_ptr_array_sort(enum_ft
->entries
,
1524 (GCompareFunc
) compare_enumeration_mappings_signed
);
1525 BT_LOGT("Added mapping to signed enumeration field type: addr=%p, "
1526 "name=\"%s\", range-start=%" PRId64
", "
1527 "range-end=%" PRId64
,
1528 ft
, string
, range_start
, range_end
);
1531 free(escaped_string
);
1537 int bt_ctf_field_type_common_enumeration_unsigned_add_mapping(
1538 struct bt_ctf_field_type_common
*ft
, const char *string
,
1539 uint64_t range_start
, uint64_t range_end
)
1542 GQuark mapping_name
;
1543 struct bt_ctf_enumeration_mapping
*mapping
;
1544 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1545 char *escaped_string
;
1548 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1554 BT_LOGW_STR("Invalid parameter: string is NULL.");
1560 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1566 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1567 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1568 "addr=%p, ft-id=%s", ft
,
1569 bt_ctf_field_type_id_string(ft
->id
));
1574 if (range_end
< range_start
) {
1575 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1576 "addr=%p, range-start=%" PRIu64
", range-end=%" PRIu64
,
1577 ft
, range_start
, range_end
);
1582 if (strlen(string
) == 0) {
1583 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1584 "enum-ft-addr=%p, mapping-name-addr=%p", ft
,
1590 escaped_string
= g_strescape(string
, NULL
);
1591 if (!escaped_string
) {
1592 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1593 "mapping-name-addr=%p, mapping-name=\"%s\"",
1594 ft
, string
, string
);
1599 mapping
= g_new(struct bt_ctf_enumeration_mapping
, 1);
1601 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1605 mapping_name
= g_quark_from_string(escaped_string
);
1606 *mapping
= (struct bt_ctf_enumeration_mapping
) {
1607 .range_start
._unsigned
= range_start
,
1608 .range_end
._unsigned
= range_end
,
1609 .string
= mapping_name
,
1611 g_ptr_array_add(enum_ft
->entries
, mapping
);
1612 g_ptr_array_sort(enum_ft
->entries
,
1613 (GCompareFunc
) compare_enumeration_mappings_unsigned
);
1614 BT_LOGT("Added mapping to unsigned enumeration field type: addr=%p, "
1615 "name=\"%s\", range-start=%" PRIu64
", "
1616 "range-end=%" PRIu64
,
1617 ft
, string
, range_start
, range_end
);
1620 free(escaped_string
);
1626 int64_t bt_ctf_field_type_common_enumeration_get_mapping_count(
1627 struct bt_ctf_field_type_common
*ft
)
1629 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1631 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1632 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1633 return (int64_t) enum_ft
->entries
->len
;
1636 int bt_ctf_field_type_common_floating_point_get_exponent_digits(
1637 struct bt_ctf_field_type_common
*ft
)
1639 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1641 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1642 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_FLOAT
,
1644 return (int) flt_ft
->exp_dig
;
1647 int bt_ctf_field_type_common_floating_point_set_exponent_digits(
1648 struct bt_ctf_field_type_common
*ft
,
1649 unsigned int exponent_digits
)
1652 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1655 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1661 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1667 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1668 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1669 "addr=%p, ft-id=%s", ft
,
1670 bt_ctf_field_type_id_string(ft
->id
));
1675 if ((exponent_digits
!= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
) &&
1676 (exponent_digits
!= sizeof(double) * CHAR_BIT
- DBL_MANT_DIG
) &&
1678 sizeof(long double) * CHAR_BIT
- LDBL_MANT_DIG
)) {
1679 BT_LOGW("Invalid parameter: invalid exponent size: "
1680 "addr=%p, exp-size=%u", ft
, exponent_digits
);
1685 flt_ft
->exp_dig
= exponent_digits
;
1686 BT_LOGT("Set floating point number field type's exponent size: addr=%p, "
1687 "exp-size=%u", ft
, exponent_digits
);
1693 int bt_ctf_field_type_common_floating_point_get_mantissa_digits(
1694 struct bt_ctf_field_type_common
*ft
)
1696 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1698 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1699 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_FLOAT
,
1701 return (int) flt_ft
->mant_dig
;
1704 int bt_ctf_field_type_common_floating_point_set_mantissa_digits(
1705 struct bt_ctf_field_type_common
*ft
, unsigned int mantissa_digits
)
1708 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1711 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1717 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1723 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1724 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1725 "addr=%p, ft-id=%s", ft
,
1726 bt_ctf_field_type_id_string(ft
->id
));
1731 if ((mantissa_digits
!= FLT_MANT_DIG
) &&
1732 (mantissa_digits
!= DBL_MANT_DIG
) &&
1733 (mantissa_digits
!= LDBL_MANT_DIG
)) {
1734 BT_LOGW("Invalid parameter: invalid mantissa size: "
1735 "addr=%p, mant-size=%u", ft
, mantissa_digits
);
1740 flt_ft
->mant_dig
= mantissa_digits
;
1741 BT_LOGT("Set floating point number field type's mantissa size: addr=%p, "
1742 "mant-size=%u", ft
, mantissa_digits
);
1748 int bt_ctf_field_type_common_structure_replace_field(
1749 struct bt_ctf_field_type_common
*ft
,
1750 const char *field_name
,
1751 struct bt_ctf_field_type_common
*field_type
)
1754 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1759 BT_ASSERT_DBG(field_name
);
1760 BT_ASSERT_DBG(field_type
);
1761 BT_ASSERT_DBG(ft
->id
== BT_CTF_FIELD_TYPE_ID_STRUCT
);
1762 name_quark
= g_quark_from_string(field_name
);
1764 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
1765 struct bt_ctf_field_type_common_structure_field
*field
=
1766 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, i
);
1768 if (field
->name
== name_quark
) {
1769 bt_ctf_object_put_ref(field
->type
);
1770 field
->type
= bt_ctf_object_get_ref(field_type
);
1777 int bt_ctf_field_type_common_structure_add_field(struct bt_ctf_field_type_common
*ft
,
1778 struct bt_ctf_field_type_common
*field_type
,
1779 const char *field_name
)
1782 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1785 * TODO: check that `field_type` does not contain `type`,
1789 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1795 BT_LOGW_STR("Invalid parameter: field name is NULL.");
1801 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1807 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
1808 BT_LOGW("Invalid parameter: field type is not a structure field type: "
1809 "addr=%p, ft-id=%s", ft
,
1810 bt_ctf_field_type_id_string(ft
->id
));
1815 if (ft
== field_type
) {
1816 BT_LOGW("Invalid parameter: structure field type and field type to add are the same: "
1822 if (add_structure_variant_member(struct_ft
->fields
,
1823 struct_ft
->field_name_to_index
, field_type
, field_name
,
1825 BT_LOGW("Cannot add field to structure field type: "
1826 "struct-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
1827 ft
, field_type
, field_name
);
1832 BT_LOGT("Added structure field type field: struct-ft-addr=%p, "
1833 "field-ft-addr=%p, field-name=\"%s\"", ft
,
1834 field_type
, field_name
);
1840 int64_t bt_ctf_field_type_common_structure_get_field_count(
1841 struct bt_ctf_field_type_common
*ft
)
1843 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1845 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1846 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1848 return (int64_t) struct_ft
->fields
->len
;
1851 int bt_ctf_field_type_common_structure_borrow_field_by_index(
1852 struct bt_ctf_field_type_common
*ft
,
1853 const char **field_name
,
1854 struct bt_ctf_field_type_common
**field_type
, uint64_t index
)
1856 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1857 struct bt_ctf_field_type_common_structure_field
*field
;
1859 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1860 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1862 BT_CTF_ASSERT_PRE(index
< struct_ft
->fields
->len
,
1863 "Index is out of bounds: index=%" PRIu64
", "
1864 "count=%u, ft-addr=%p",
1865 index
, struct_ft
->fields
->len
, ft
);
1866 field
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(struct_ft
, index
);
1869 *field_type
= field
->type
;
1873 *field_name
= g_quark_to_string(field
->name
);
1874 BT_ASSERT_DBG(*field_name
);
1880 struct bt_ctf_field_type_common
*
1881 bt_ctf_field_type_common_structure_borrow_field_type_by_name(
1882 struct bt_ctf_field_type_common
*ft
, const char *name
)
1886 struct bt_ctf_field_type_common_structure_field
*field
;
1887 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1888 struct bt_ctf_field_type_common
*field_type
= NULL
;
1890 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1891 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
1892 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1894 name_quark
= g_quark_try_string(name
);
1896 BT_LOGT("No such structure field type field name: "
1897 "ft-addr=%p, field-name=\"%s\"",
1902 if (!g_hash_table_lookup_extended(struct_ft
->field_name_to_index
,
1903 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*) &index
)) {
1904 BT_LOGT("No such structure field type field name: "
1905 "ft-addr=%p, field-name=\"%s\"",
1910 field
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, index
);
1911 field_type
= field
->type
;
1917 struct bt_ctf_field_type_common
*
1918 bt_ctf_field_type_common_variant_borrow_tag_field_type(
1919 struct bt_ctf_field_type_common
*ft
)
1921 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
1922 struct bt_ctf_field_type_common
*tag_ft
= NULL
;
1924 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1925 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
1928 if (!var_ft
->tag_ft
) {
1929 BT_LOGT("Variant field type has no tag field type: "
1934 tag_ft
= BT_CTF_TO_COMMON(var_ft
->tag_ft
);
1940 const char *bt_ctf_field_type_common_variant_get_tag_name(
1941 struct bt_ctf_field_type_common
*ft
)
1943 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
1944 const char *tag_name
= NULL
;
1946 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1947 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
1950 if (var_ft
->tag_name
->len
== 0) {
1951 BT_LOGT("Variant field type has no tag field name: "
1956 tag_name
= var_ft
->tag_name
->str
;
1962 int bt_ctf_field_type_common_variant_set_tag_name(
1963 struct bt_ctf_field_type_common
*ft
, const char *name
)
1966 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
1969 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1975 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1981 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
1982 BT_LOGW("Invalid parameter: field type is not a variant field type: "
1983 "addr=%p, ft-id=%s", ft
, bt_ctf_field_type_id_string(ft
->id
));
1988 if (!bt_ctf_identifier_is_valid(name
)) {
1989 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
1990 "variant-ft-addr=%p, tag-field-name=\"%s\"",
1996 g_string_assign(var_ft
->tag_name
, name
);
1997 BT_LOGT("Set variant field type's tag field name: addr=%p, "
1998 "tag-field-name=\"%s\"", ft
, name
);
2004 int bt_ctf_field_type_common_variant_add_field(struct bt_ctf_field_type_common
*ft
,
2005 struct bt_ctf_field_type_common
*field_type
,
2006 const char *field_name
)
2010 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2011 GQuark field_name_quark
= g_quark_from_string(field_name
);
2014 * TODO: check that `field_type` does not contain `type`,
2018 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2024 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2030 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2031 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2032 "addr=%p, ft-id=%s", ft
,
2033 bt_ctf_field_type_id_string(ft
->id
));
2038 if (ft
== field_type
) {
2039 BT_LOGW("Invalid parameter: variant field type and field type to add are the same: "
2045 /* The user has explicitly provided a tag; validate against it. */
2046 if (var_ft
->tag_ft
) {
2049 /* Make sure this name is present in the enum tag */
2050 for (i
= 0; i
< var_ft
->tag_ft
->entries
->len
; i
++) {
2051 struct bt_ctf_enumeration_mapping
*mapping
=
2052 g_ptr_array_index(var_ft
->tag_ft
->entries
, i
);
2054 if (mapping
->string
== field_name_quark
) {
2061 /* Validation failed */
2062 BT_LOGW("Invalid parameter: field name does not name a tag field type's mapping: "
2063 "variant-ft-addr=%p, tag-ft-addr=%p, "
2064 "tag-field-name=\"%s\""
2065 "field-ft-addr=%p, field-name=\"%s\"",
2066 ft
, var_ft
->tag_ft
, var_ft
->tag_name
->str
,
2067 field_type
, field_name
);
2073 if (add_structure_variant_member(var_ft
->choices
,
2074 var_ft
->choice_name_to_index
, field_type
,
2075 field_name
, true)) {
2076 BT_LOGW("Cannot add field to variant field type: "
2077 "variant-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2078 ft
, field_type
, field_name
);
2083 BT_LOGT("Added variant field type field: variant-ft-addr=%p, "
2084 "field-ft-addr=%p, field-name=\"%s\"", ft
,
2085 field_type
, field_name
);
2091 struct bt_ctf_field_type_common
*
2092 bt_ctf_field_type_common_variant_borrow_field_type_by_name(
2093 struct bt_ctf_field_type_common
*ft
,
2094 const char *field_name
)
2098 struct bt_ctf_field_type_common_variant_choice
*choice
;
2099 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2100 struct bt_ctf_field_type_common
*field_type
= NULL
;
2102 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2103 BT_CTF_ASSERT_PRE_NON_NULL(field_name
, "Name");
2104 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2106 name_quark
= g_quark_try_string(field_name
);
2108 BT_LOGT("No such variant field type field name: "
2109 "ft-addr=%p, field-name=\"%s\"",
2114 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2115 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*) &index
)) {
2116 BT_LOGT("No such variant field type field name: "
2117 "ft-addr=%p, field-name=\"%s\"",
2122 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, index
);
2123 field_type
= choice
->type
;
2129 int64_t bt_ctf_field_type_common_variant_get_field_count(
2130 struct bt_ctf_field_type_common
*ft
)
2132 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2134 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Variant field type");
2135 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2137 return (int64_t) var_ft
->choices
->len
;
2140 int bt_ctf_field_type_common_variant_borrow_field_by_index(
2141 struct bt_ctf_field_type_common
*ft
,
2142 const char **field_name
,
2143 struct bt_ctf_field_type_common
**field_type
, uint64_t index
)
2145 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2146 struct bt_ctf_field_type_common_variant_choice
*choice
;
2148 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2149 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2151 BT_CTF_ASSERT_PRE(index
< var_ft
->choices
->len
,
2152 "Index is out of bounds: index=%" PRIu64
", "
2153 "count=%u, ft-addr=%p",
2154 index
, var_ft
->choices
->len
, ft
);
2155 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, index
);
2158 *field_type
= choice
->type
;
2162 *field_name
= g_quark_to_string(choice
->name
);
2163 BT_ASSERT_DBG(*field_name
);
2169 int64_t bt_ctf_field_type_common_variant_find_choice_index(
2170 struct bt_ctf_field_type_common
*ft
, uint64_t uval
,
2175 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2178 BT_ASSERT_DBG(ft
->id
== BT_CTF_FIELD_TYPE_ID_VARIANT
);
2180 if (bt_ctf_field_type_common_variant_update_choices(ft
)) {
2185 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
2187 struct bt_ctf_field_type_common_variant_choice
*choice
=
2188 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
2191 for (range_i
= 0; range_i
< choice
->ranges
->len
; range_i
++) {
2192 struct bt_ctf_field_type_common_variant_choice_range
*range
=
2195 struct bt_ctf_field_type_common_variant_choice_range
,
2199 int64_t tag_ival
= (int64_t) uval
;
2201 if (tag_ival
>= range
->lower
.i
&&
2202 tag_ival
<= range
->upper
.i
) {
2206 if (uval
>= range
->lower
.u
&&
2207 uval
<= range
->upper
.u
) {
2214 /* Range not found */
2225 struct bt_ctf_field_type_common
*
2226 bt_ctf_field_type_common_array_borrow_element_field_type(
2227 struct bt_ctf_field_type_common
*ft
)
2229 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2231 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2232 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ARRAY
,
2234 BT_ASSERT_DBG(array_ft
&& array_ft
->element_ft
);
2235 return array_ft
->element_ft
;
2238 int bt_ctf_field_type_common_array_set_element_field_type(
2239 struct bt_ctf_field_type_common
*ft
,
2240 struct bt_ctf_field_type_common
*element_ft
)
2243 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2246 BT_LOGW_STR("Invalid parameter: array field type is NULL.");
2252 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2257 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2258 BT_LOGW("Invalid parameter: field type is not an array field type: "
2259 "addr=%p, ft-id=%s", ft
,
2260 bt_ctf_field_type_id_string(ft
->id
));
2265 if (array_ft
->element_ft
) {
2266 BT_CTF_OBJECT_PUT_REF_AND_RESET(array_ft
->element_ft
);
2269 array_ft
->element_ft
= bt_ctf_object_get_ref(element_ft
);
2270 BT_LOGT("Set array field type's element field type: array-ft-addr=%p, "
2271 "element-ft-addr=%p", ft
, element_ft
);
2277 int64_t bt_ctf_field_type_common_array_get_length(struct bt_ctf_field_type_common
*ft
)
2279 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2281 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2282 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ARRAY
,
2284 return (int64_t) array_ft
->length
;
2287 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_sequence_borrow_element_field_type(
2288 struct bt_ctf_field_type_common
*ft
)
2290 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2292 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2293 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
2295 return seq_ft
->element_ft
;
2298 int bt_ctf_field_type_common_sequence_set_element_field_type(
2299 struct bt_ctf_field_type_common
*ft
,
2300 struct bt_ctf_field_type_common
*element_ft
)
2303 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2306 BT_LOGW_STR("Invalid parameter: sequence field type is NULL.");
2312 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2317 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2318 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2319 "addr=%p, ft-id=%s", ft
,
2320 bt_ctf_field_type_id_string(ft
->id
));
2325 if (seq_ft
->element_ft
) {
2326 BT_CTF_OBJECT_PUT_REF_AND_RESET(seq_ft
->element_ft
);
2329 seq_ft
->element_ft
= element_ft
;
2330 bt_ctf_object_get_ref(seq_ft
->element_ft
);
2331 BT_LOGT("Set sequence field type's element field type: sequence-ft-addr=%p, "
2332 "element-ft-addr=%p", ft
, element_ft
);
2338 const char *bt_ctf_field_type_common_sequence_get_length_field_name(
2339 struct bt_ctf_field_type_common
*ft
)
2341 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2343 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2344 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
2346 return seq_ft
->length_field_name
?
2347 seq_ft
->length_field_name
->str
: NULL
;
2350 enum bt_ctf_string_encoding
bt_ctf_field_type_common_string_get_encoding(
2351 struct bt_ctf_field_type_common
*ft
)
2353 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
2355 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2356 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRING
,
2358 return string_ft
->encoding
;
2361 int bt_ctf_field_type_common_string_set_encoding(struct bt_ctf_field_type_common
*ft
,
2362 enum bt_ctf_string_encoding encoding
)
2365 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
2368 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2373 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2374 BT_LOGW("Invalid parameter: field type is not a string field type: "
2375 "addr=%p, ft-id=%s", ft
,
2376 bt_ctf_field_type_id_string(ft
->id
));
2381 if (encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
2382 encoding
!= BT_CTF_STRING_ENCODING_ASCII
) {
2383 BT_LOGW("Invalid parameter: unknown string encoding: "
2384 "addr=%p, encoding=%d", ft
, encoding
);
2389 string_ft
->encoding
= encoding
;
2390 BT_LOGT("Set string field type's encoding: addr=%p, encoding=%s",
2391 ft
, bt_ctf_string_encoding_string(encoding
));
2397 int bt_ctf_field_type_common_get_alignment(struct bt_ctf_field_type_common
*ft
)
2400 enum bt_ctf_field_type_id type_id
;
2402 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2405 ret
= (int) ft
->alignment
;
2409 type_id
= bt_ctf_field_type_common_get_type_id(ft
);
2411 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
2413 struct bt_ctf_field_type_common
*element_ft
=
2414 bt_ctf_field_type_common_sequence_borrow_element_field_type(ft
);
2416 BT_ASSERT_DBG(element_ft
);
2417 ret
= bt_ctf_field_type_common_get_alignment(element_ft
);
2420 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
2422 struct bt_ctf_field_type_common
*element_ft
=
2423 bt_ctf_field_type_common_array_borrow_element_field_type(ft
);
2425 BT_ASSERT_DBG(element_ft
);
2426 ret
= bt_ctf_field_type_common_get_alignment(element_ft
);
2429 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
2431 int64_t i
, element_count
;
2433 element_count
= bt_ctf_field_type_common_structure_get_field_count(
2435 BT_ASSERT_DBG(element_count
>= 0);
2437 for (i
= 0; i
< element_count
; i
++) {
2438 struct bt_ctf_field_type_common
*field
= NULL
;
2439 int field_alignment
;
2441 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
2442 ft
, NULL
, &field
, i
);
2443 BT_ASSERT_DBG(ret
== 0);
2444 BT_ASSERT_DBG(field
);
2445 field_alignment
= bt_ctf_field_type_common_get_alignment(
2447 if (field_alignment
< 0) {
2448 ret
= field_alignment
;
2452 ft
->alignment
= MAX(field_alignment
, ft
->alignment
);
2454 ret
= (int) ft
->alignment
;
2457 case BT_CTF_FIELD_TYPE_ID_UNKNOWN
:
2458 BT_LOGW("Invalid parameter: unknown field type ID: "
2459 "addr=%p, ft-id=%d", ft
, type_id
);
2463 ret
= (int) ft
->alignment
;
2472 int is_power_of_two(unsigned int value
)
2474 return ((value
& (value
- 1)) == 0) && value
> 0;
2477 int bt_ctf_field_type_common_set_alignment(struct bt_ctf_field_type_common
*ft
,
2478 unsigned int alignment
)
2481 enum bt_ctf_field_type_id type_id
;
2483 /* Alignment must be a power of two */
2485 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2491 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2497 if (!is_power_of_two(alignment
)) {
2498 BT_LOGW("Invalid parameter: alignment is not a power of two: "
2499 "addr=%p, align=%u", ft
, alignment
);
2504 type_id
= bt_ctf_field_type_common_get_type_id(ft
);
2505 if (type_id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
2506 BT_LOGW("Invalid parameter: unknown field type ID: "
2507 "addr=%p, ft-id=%d", ft
, type_id
);
2512 if (ft
->id
== BT_CTF_FIELD_TYPE_ID_STRING
&& alignment
!= CHAR_BIT
) {
2513 BT_LOGW("Invalid parameter: alignment must be %u for a string field type: "
2514 "addr=%p, align=%u", CHAR_BIT
, ft
, alignment
);
2519 if (type_id
== BT_CTF_FIELD_TYPE_ID_VARIANT
||
2520 type_id
== BT_CTF_FIELD_TYPE_ID_SEQUENCE
||
2521 type_id
== BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2522 /* Setting an alignment on these types makes no sense */
2523 BT_LOGW("Invalid parameter: cannot set the alignment of this field type: "
2524 "addr=%p, ft-id=%s", ft
,
2525 bt_ctf_field_type_id_string(ft
->id
));
2530 ft
->alignment
= alignment
;
2532 BT_LOGT("Set field type's alignment: addr=%p, align=%u",
2539 enum bt_ctf_byte_order
bt_ctf_field_type_common_get_byte_order(
2540 struct bt_ctf_field_type_common
*ft
)
2542 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
2544 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2547 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
2549 struct bt_ctf_field_type_common_integer
*integer
=
2550 BT_CTF_FROM_COMMON(ft
);
2552 ret
= integer
->user_byte_order
;
2555 case BT_CTF_FIELD_TYPE_ID_ENUM
:
2557 struct bt_ctf_field_type_common_enumeration
*enum_ft
=
2558 BT_CTF_FROM_COMMON(ft
);
2560 ret
= bt_ctf_field_type_common_get_byte_order(
2561 BT_CTF_TO_COMMON(enum_ft
->container_ft
));
2564 case BT_CTF_FIELD_TYPE_ID_FLOAT
:
2566 struct bt_ctf_field_type_common_floating_point
*floating_point
=
2567 BT_CTF_FROM_COMMON(ft
);
2568 ret
= floating_point
->user_byte_order
;
2572 BT_LOGW("Invalid parameter: cannot get the byte order of this field type: "
2573 "addr=%p, ft-id=%s", ft
,
2574 bt_ctf_field_type_id_string(ft
->id
));
2578 BT_ASSERT_DBG(ret
== BT_CTF_BYTE_ORDER_NATIVE
||
2579 ret
== BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
||
2580 ret
== BT_CTF_BYTE_ORDER_BIG_ENDIAN
||
2581 ret
== BT_CTF_BYTE_ORDER_NETWORK
);
2587 int bt_ctf_field_type_common_set_byte_order(struct bt_ctf_field_type_common
*ft
,
2588 enum bt_ctf_byte_order byte_order
)
2593 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2599 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2605 if (byte_order
!= BT_CTF_BYTE_ORDER_NATIVE
&&
2606 byte_order
!= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
&&
2607 byte_order
!= BT_CTF_BYTE_ORDER_BIG_ENDIAN
&&
2608 byte_order
!= BT_CTF_BYTE_ORDER_NETWORK
) {
2609 BT_LOGW("Invalid parameter: invalid byte order: "
2610 "addr=%p, bo=%s", ft
,
2611 bt_ctf_byte_order_string(byte_order
));
2616 if (ft
->methods
->set_byte_order
) {
2617 ft
->methods
->set_byte_order(ft
, byte_order
);
2620 BT_LOGT("Set field type's byte order: addr=%p, bo=%s",
2621 ft
, bt_ctf_byte_order_string(byte_order
));
2627 enum bt_ctf_field_type_id
bt_ctf_field_type_common_get_type_id(
2628 struct bt_ctf_field_type_common
*ft
)
2630 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2634 void bt_ctf_field_type_common_freeze(struct bt_ctf_field_type_common
*ft
)
2636 if (!ft
|| ft
->frozen
) {
2640 BT_ASSERT_DBG(ft
->methods
->freeze
);
2641 ft
->methods
->freeze(ft
);
2644 struct bt_ctf_field_type_common
*
2645 bt_ctf_field_type_common_variant_borrow_field_type_signed(
2646 struct bt_ctf_field_type_common_variant
*var_ft
,
2649 struct bt_ctf_field_type_common
*field_type
= NULL
;
2650 GQuark field_name_quark
;
2652 struct bt_ctf_field_type_common_variant_choice
*choice
;
2653 struct range_overlap_query query
= {
2654 .range_start
._signed
= tag_value
,
2655 .range_end
._signed
= tag_value
,
2660 g_ptr_array_foreach(var_ft
->tag_ft
->entries
, check_ranges_overlap
,
2662 if (!query
.overlaps
) {
2666 field_name_quark
= query
.mapping_name
;
2667 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2668 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
2672 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
,
2674 field_type
= choice
->type
;
2680 struct bt_ctf_field_type_common
*
2681 bt_ctf_field_type_common_variant_borrow_field_type_unsigned(
2682 struct bt_ctf_field_type_common_variant
*var_ft
,
2685 struct bt_ctf_field_type_common
*field_type
= NULL
;
2686 GQuark field_name_quark
;
2688 struct bt_ctf_field_type_common_variant_choice
*choice
;
2689 struct range_overlap_query query
= {
2690 .range_start
._unsigned
= tag_value
,
2691 .range_end
._unsigned
= tag_value
,
2696 g_ptr_array_foreach(var_ft
->tag_ft
->entries
,
2697 check_ranges_overlap_unsigned
, &query
);
2698 if (!query
.overlaps
) {
2702 field_name_quark
= query
.mapping_name
;
2703 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2704 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
2708 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
,
2710 field_type
= choice
->type
;
2716 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_copy(
2717 struct bt_ctf_field_type_common
*ft
)
2719 struct bt_ctf_field_type_common
*ft_copy
= NULL
;
2721 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2722 BT_ASSERT_DBG(ft
->methods
->copy
);
2723 ft_copy
= ft
->methods
->copy(ft
);
2725 BT_LOGE_STR("Cannot copy field type.");
2729 ft_copy
->alignment
= ft
->alignment
;
2735 int bt_ctf_field_type_common_structure_get_field_name_index(
2736 struct bt_ctf_field_type_common
*ft
, const char *name
)
2741 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
2743 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2744 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
2745 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
2748 name_quark
= g_quark_try_string(name
);
2750 BT_LOGT("No such structure field type field name: "
2751 "ft-addr=%p, field-name=\"%s\"",
2757 if (!g_hash_table_lookup_extended(struct_ft
->field_name_to_index
,
2758 GUINT_TO_POINTER(name_quark
),
2759 NULL
, (gpointer
*) &index
)) {
2760 BT_LOGT("No such structure field type field name: "
2761 "ft-addr=%p, field-name=\"%s\"",
2773 int bt_ctf_field_type_common_variant_get_field_name_index(
2774 struct bt_ctf_field_type_common
*ft
, const char *name
)
2779 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2781 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2782 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
2783 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2785 name_quark
= g_quark_try_string(name
);
2787 BT_LOGT("No such variant field type field name: "
2788 "ft-addr=%p, field-name=\"%s\"",
2794 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2795 GUINT_TO_POINTER(name_quark
),
2796 NULL
, (gpointer
*) &index
)) {
2797 BT_LOGT("No such variant field type field name: "
2798 "ft-addr=%p, field-name=\"%s\"",
2810 int bt_ctf_field_type_common_sequence_set_length_field_path(
2811 struct bt_ctf_field_type_common
*ft
, struct bt_ctf_field_path
*path
)
2814 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2817 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2822 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2823 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2824 "addr=%p, ft-id=%s", ft
,
2825 bt_ctf_field_type_id_string(ft
->id
));
2830 bt_ctf_object_get_ref(path
);
2831 BT_CTF_OBJECT_MOVE_REF(seq_ft
->length_field_path
, path
);
2832 BT_LOGT("Set sequence field type's length field path: ft-addr=%p, "
2833 "field-path-addr=%p", ft
, path
);
2839 int bt_ctf_field_type_common_variant_set_tag_field_path(
2840 struct bt_ctf_field_type_common
*ft
,
2841 struct bt_ctf_field_path
*path
)
2844 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2847 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2852 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2853 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2854 "addr=%p, ft-id=%s", ft
,
2855 bt_ctf_field_type_id_string(ft
->id
));
2860 bt_ctf_object_get_ref(path
);
2861 BT_CTF_OBJECT_MOVE_REF(var_ft
->tag_field_path
, path
);
2862 BT_LOGT("Set variant field type's tag field path: ft-addr=%p, "
2863 "field-path-addr=%p", ft
, path
);
2869 int bt_ctf_field_type_common_variant_set_tag_field_type(
2870 struct bt_ctf_field_type_common
*ft
,
2871 struct bt_ctf_field_type_common
*tag_ft
)
2874 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2877 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
2883 BT_LOGW_STR("Invalid parameter: tag field type is NULL.");
2888 if (tag_ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
2889 BT_LOGW("Invalid parameter: tag field type is not an enumeration field type: "
2890 "addr=%p, ft-id=%s", tag_ft
,
2891 bt_ctf_field_type_id_string(tag_ft
->id
));
2896 bt_ctf_object_put_ref(var_ft
->tag_ft
);
2897 var_ft
->tag_ft
= bt_ctf_object_get_ref(tag_ft
);
2898 BT_LOGT("Set variant field type's tag field type: variant-ft-addr=%p, "
2899 "tag-ft-addr=%p", ft
, tag_ft
);
2905 void bt_ctf_field_type_common_generic_freeze(struct bt_ctf_field_type_common
*ft
)
2910 void bt_ctf_field_type_common_enumeration_freeze_recursive(
2911 struct bt_ctf_field_type_common
*ft
)
2913 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
2915 BT_LOGD("Freezing enumeration field type object: addr=%p", ft
);
2916 bt_ctf_field_type_common_enumeration_set_range_overlap(enum_ft
);
2917 bt_ctf_field_type_common_generic_freeze(ft
);
2918 BT_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p",
2919 enum_ft
->container_ft
);
2920 bt_ctf_field_type_common_freeze(BT_CTF_TO_COMMON(enum_ft
->container_ft
));
2923 void bt_ctf_field_type_common_structure_freeze_recursive(
2924 struct bt_ctf_field_type_common
*ft
)
2926 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
2929 /* Cache the alignment */
2930 BT_LOGD("Freezing structure field type object: addr=%p", ft
);
2931 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
2932 bt_ctf_field_type_common_generic_freeze(ft
);
2934 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
2935 struct bt_ctf_field_type_common_structure_field
*field
=
2936 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, i
);
2938 BT_LOGD("Freezing structure field type field: "
2939 "ft-addr=%p, name=\"%s\"",
2940 field
->type
, g_quark_to_string(field
->name
));
2941 bt_ctf_field_type_common_freeze(field
->type
);
2945 int bt_ctf_field_type_common_variant_update_choices(struct bt_ctf_field_type_common
*ft
)
2947 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2952 if (ft
->frozen
&& var_ft
->choices_up_to_date
) {
2956 BT_ASSERT_DBG(var_ft
->tag_ft
);
2957 is_signed
= !!var_ft
->tag_ft
->container_ft
->is_signed
;
2959 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
2960 struct bt_ctf_field_type_common_variant_choice
*choice
=
2961 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, i
);
2962 const char *choice_name
= g_quark_to_string(choice
->name
);
2963 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
2964 bt_ctf_field_type_common_enumeration_find_mappings_by_name(
2965 BT_CTF_TO_COMMON(var_ft
->tag_ft
), choice_name
);
2972 BT_ASSERT_DBG(choice
->ranges
);
2973 g_array_set_size(choice
->ranges
, 0);
2975 while (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
) == 0) {
2976 struct bt_ctf_field_type_common_variant_choice_range range
;
2979 ret
= bt_ctf_field_type_enumeration_mapping_iterator_signed_get(
2981 &range
.lower
.i
, &range
.upper
.i
);
2983 ret
= bt_ctf_field_type_enumeration_mapping_iterator_unsigned_get(
2985 &range
.lower
.u
, &range
.upper
.u
);
2988 BT_ASSERT_DBG(ret
== 0);
2989 g_array_append_val(choice
->ranges
, range
);
2992 bt_ctf_object_put_ref(iter
);
2995 var_ft
->choices_up_to_date
= true;
3001 void bt_ctf_field_type_common_variant_freeze_recursive(
3002 struct bt_ctf_field_type_common
*ft
)
3004 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3007 BT_LOGD("Freezing variant field type object: addr=%p", ft
);
3008 bt_ctf_field_type_common_generic_freeze(ft
);
3010 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
3011 struct bt_ctf_field_type_common_variant_choice
*choice
=
3012 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, i
);
3014 BT_LOGD("Freezing variant field type member: "
3015 "ft-addr=%p, name=\"%s\"",
3016 choice
->type
, g_quark_to_string(choice
->name
));
3017 bt_ctf_field_type_common_freeze(choice
->type
);
3021 void bt_ctf_field_type_common_array_freeze_recursive(
3022 struct bt_ctf_field_type_common
*ft
)
3024 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
3026 /* Cache the alignment */
3027 BT_LOGD("Freezing array field type object: addr=%p", ft
);
3028 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
3029 bt_ctf_field_type_common_generic_freeze(ft
);
3030 BT_LOGD("Freezing array field type object's element field type: element-ft-addr=%p",
3031 array_ft
->element_ft
);
3032 bt_ctf_field_type_common_freeze(array_ft
->element_ft
);
3035 void bt_ctf_field_type_common_sequence_freeze_recursive(
3036 struct bt_ctf_field_type_common
*ft
)
3038 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3040 /* Cache the alignment */
3041 BT_LOGD("Freezing sequence field type object: addr=%p", ft
);
3042 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
3043 bt_ctf_field_type_common_generic_freeze(ft
);
3044 BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
3045 seq_ft
->element_ft
);
3046 bt_ctf_field_type_common_freeze(seq_ft
->element_ft
);
3049 void bt_ctf_field_type_common_integer_set_byte_order(
3050 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3052 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
3054 int_ft
->user_byte_order
= byte_order
;
3057 void bt_ctf_field_type_common_enumeration_set_byte_order_recursive(
3058 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3060 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
3062 bt_ctf_field_type_common_set_byte_order(BT_CTF_TO_COMMON(enum_ft
->container_ft
),
3066 void bt_ctf_field_type_common_floating_point_set_byte_order(
3067 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3069 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
3071 flt_ft
->user_byte_order
= byte_order
;
3074 void bt_ctf_field_type_common_structure_set_byte_order_recursive(
3075 struct bt_ctf_field_type_common
*ft
,
3076 enum bt_ctf_byte_order byte_order
)
3079 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
3081 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
3082 struct bt_ctf_field_type_common_structure_field
*field
=
3083 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3085 struct bt_ctf_field_type_common
*field_type
= field
->type
;
3087 bt_ctf_field_type_common_set_byte_order(field_type
, byte_order
);
3091 void bt_ctf_field_type_common_variant_set_byte_order_recursive(
3092 struct bt_ctf_field_type_common
*ft
,
3093 enum bt_ctf_byte_order byte_order
)
3096 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3098 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
3099 struct bt_ctf_field_type_common_variant_choice
*choice
=
3100 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3102 struct bt_ctf_field_type_common
*field_type
= choice
->type
;
3104 bt_ctf_field_type_common_set_byte_order(field_type
, byte_order
);
3108 void bt_ctf_field_type_common_array_set_byte_order_recursive(
3109 struct bt_ctf_field_type_common
*ft
,
3110 enum bt_ctf_byte_order byte_order
)
3112 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
3114 bt_ctf_field_type_common_set_byte_order(array_ft
->element_ft
, byte_order
);
3117 void bt_ctf_field_type_common_sequence_set_byte_order_recursive(
3118 struct bt_ctf_field_type_common
*ft
,
3119 enum bt_ctf_byte_order byte_order
)
3121 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3123 bt_ctf_field_type_common_set_byte_order(seq_ft
->element_ft
, byte_order
);
3127 int bt_ctf_field_type_common_integer_compare(struct bt_ctf_field_type_common
*ft_a
,
3128 struct bt_ctf_field_type_common
*ft_b
)
3131 struct bt_ctf_field_type_common_integer
*int_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3132 struct bt_ctf_field_type_common_integer
*int_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3135 if (int_ft_a
->size
!= int_ft_b
->size
) {
3136 BT_LOGT("Integer field types differ: different sizes: "
3137 "ft-a-size=%u, ft-b-size=%u",
3138 int_ft_a
->size
, int_ft_b
->size
);
3143 if (int_ft_a
->user_byte_order
!= int_ft_b
->user_byte_order
) {
3144 BT_LOGT("Integer field types differ: different byte orders: "
3145 "ft-a-bo=%s, ft-b-bo=%s",
3146 bt_ctf_byte_order_string(int_ft_a
->user_byte_order
),
3147 bt_ctf_byte_order_string(int_ft_b
->user_byte_order
));
3152 if (int_ft_a
->is_signed
!= int_ft_b
->is_signed
) {
3153 BT_LOGT("Integer field types differ: different signedness: "
3154 "ft-a-is-signed=%d, ft-b-is-signed=%d",
3155 int_ft_a
->is_signed
,
3156 int_ft_b
->is_signed
);
3161 if (int_ft_a
->base
!= int_ft_b
->base
) {
3162 BT_LOGT("Integer field types differ: different bases: "
3163 "ft-a-base=%s, ft-b-base=%s",
3164 bt_ctf_integer_base_string(int_ft_a
->base
),
3165 bt_ctf_integer_base_string(int_ft_b
->base
));
3170 if (int_ft_a
->encoding
!= int_ft_b
->encoding
) {
3171 BT_LOGT("Integer field types differ: different encodings: "
3172 "ft-a-encoding=%s, ft-b-encoding=%s",
3173 bt_ctf_string_encoding_string(int_ft_a
->encoding
),
3174 bt_ctf_string_encoding_string(int_ft_b
->encoding
));
3178 /* Mapped clock class */
3179 if (int_ft_a
->mapped_clock_class
) {
3180 if (!int_ft_b
->mapped_clock_class
) {
3181 BT_LOGT_STR("Integer field types differ: field type A "
3182 "has a mapped clock class, but field type B "
3187 if (bt_ctf_clock_class_compare(int_ft_a
->mapped_clock_class
,
3188 int_ft_b
->mapped_clock_class
) != 0) {
3189 BT_LOGT_STR("Integer field types differ: different "
3190 "mapped clock classes.");
3193 if (int_ft_b
->mapped_clock_class
) {
3194 BT_LOGT_STR("Integer field types differ: field type A "
3195 "has no description, but field type B has one.");
3207 int bt_ctf_field_type_common_floating_point_compare(
3208 struct bt_ctf_field_type_common
*ft_a
,
3209 struct bt_ctf_field_type_common
*ft_b
)
3212 struct bt_ctf_field_type_common_floating_point
*flt_ft_a
=
3213 BT_CTF_FROM_COMMON(ft_a
);
3214 struct bt_ctf_field_type_common_floating_point
*flt_ft_b
=
3215 BT_CTF_FROM_COMMON(ft_b
);
3218 if (flt_ft_a
->user_byte_order
!= flt_ft_b
->user_byte_order
) {
3219 BT_LOGT("Floating point number field types differ: different byte orders: "
3220 "ft-a-bo=%s, ft-b-bo=%s",
3221 bt_ctf_byte_order_string(flt_ft_a
->user_byte_order
),
3222 bt_ctf_byte_order_string(flt_ft_b
->user_byte_order
));
3226 /* Exponent length */
3227 if (flt_ft_a
->exp_dig
!= flt_ft_b
->exp_dig
) {
3228 BT_LOGT("Floating point number field types differ: different exponent sizes: "
3229 "ft-a-exp-size=%u, ft-b-exp-size=%u",
3230 flt_ft_a
->exp_dig
, flt_ft_b
->exp_dig
);
3234 /* Mantissa length */
3235 if (flt_ft_a
->mant_dig
!= flt_ft_b
->mant_dig
) {
3236 BT_LOGT("Floating point number field types differ: different mantissa sizes: "
3237 "ft-a-mant-size=%u, ft-b-mant-size=%u",
3238 flt_ft_a
->mant_dig
, flt_ft_b
->mant_dig
);
3250 int compare_enumeration_mappings(struct bt_ctf_enumeration_mapping
*mapping_a
,
3251 struct bt_ctf_enumeration_mapping
*mapping_b
)
3256 if (mapping_a
->string
!= mapping_b
->string
) {
3257 BT_LOGT("Enumeration field type mappings differ: different names: "
3258 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
3259 g_quark_to_string(mapping_a
->string
),
3260 g_quark_to_string(mapping_b
->string
));
3265 if (mapping_a
->range_start
._unsigned
!=
3266 mapping_b
->range_start
._unsigned
) {
3267 BT_LOGT("Enumeration field type mappings differ: different starts of range: "
3268 "mapping-a-range-start-unsigned=%" PRIu64
", "
3269 "mapping-b-range-start-unsigned=%" PRIu64
,
3270 mapping_a
->range_start
._unsigned
,
3271 mapping_b
->range_start
._unsigned
);
3276 if (mapping_a
->range_end
._unsigned
!=
3277 mapping_b
->range_end
._unsigned
) {
3278 BT_LOGT("Enumeration field type mappings differ: different ends of range: "
3279 "mapping-a-range-end-unsigned=%" PRIu64
", "
3280 "mapping-b-range-end-unsigned=%" PRIu64
,
3281 mapping_a
->range_end
._unsigned
,
3282 mapping_b
->range_end
._unsigned
);
3293 int bt_ctf_field_type_common_enumeration_compare_recursive(
3294 struct bt_ctf_field_type_common
*ft_a
,
3295 struct bt_ctf_field_type_common
*ft_b
)
3299 struct bt_ctf_field_type_common_enumeration
*enum_ft_a
=
3300 BT_CTF_FROM_COMMON(ft_a
);
3301 struct bt_ctf_field_type_common_enumeration
*enum_ft_b
=
3302 BT_CTF_FROM_COMMON(ft_b
);
3304 /* Container field type */
3305 ret
= bt_ctf_field_type_common_compare(
3306 BT_CTF_TO_COMMON(enum_ft_a
->container_ft
),
3307 BT_CTF_TO_COMMON(enum_ft_b
->container_ft
));
3309 BT_LOGT("Enumeration field types differ: different container field types: "
3310 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
3311 enum_ft_a
->container_ft
, enum_ft_b
->container_ft
);
3318 if (enum_ft_a
->entries
->len
!= enum_ft_b
->entries
->len
) {
3322 for (i
= 0; i
< enum_ft_a
->entries
->len
; ++i
) {
3323 struct bt_ctf_enumeration_mapping
*mapping_a
=
3324 g_ptr_array_index(enum_ft_a
->entries
, i
);
3325 struct bt_ctf_enumeration_mapping
*mapping_b
=
3326 g_ptr_array_index(enum_ft_b
->entries
, i
);
3328 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
3329 BT_LOGT("Enumeration field types differ: different mappings: "
3330 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
3331 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
3332 mapping_a
, mapping_b
,
3333 g_quark_to_string(mapping_a
->string
),
3334 g_quark_to_string(mapping_b
->string
));
3346 int bt_ctf_field_type_common_string_compare(struct bt_ctf_field_type_common
*ft_a
,
3347 struct bt_ctf_field_type_common
*ft_b
)
3350 struct bt_ctf_field_type_common_string
*string_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3351 struct bt_ctf_field_type_common_string
*string_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3354 if (string_ft_a
->encoding
!= string_ft_b
->encoding
) {
3355 BT_LOGT("String field types differ: different encodings: "
3356 "ft-a-encoding=%s, ft-b-encoding=%s",
3357 bt_ctf_string_encoding_string(string_ft_a
->encoding
),
3358 bt_ctf_string_encoding_string(string_ft_b
->encoding
));
3370 int compare_structure_variant_members(
3371 struct bt_ctf_field_type_common
*member_a_ft
,
3372 struct bt_ctf_field_type_common
*member_b_ft
,
3373 GQuark member_a_name
, GQuark member_b_name
)
3378 if (member_a_name
!= member_b_name
) {
3379 BT_LOGT("Structure/variant field type fields differ: different names: "
3380 "field-a-name=%s, field-b-name=%s",
3381 g_quark_to_string(member_a_name
),
3382 g_quark_to_string(member_b_name
));
3387 ret
= bt_ctf_field_type_common_compare(member_a_ft
, member_b_ft
);
3389 BT_LOGT("Structure/variant field type fields differ: different field types: "
3390 "field-name=\"%s\", field-a-ft-addr=%p, field-b-ft-addr=%p",
3391 g_quark_to_string(member_a_name
),
3392 member_a_ft
, member_b_ft
);
3399 int bt_ctf_field_type_common_structure_compare_recursive(
3400 struct bt_ctf_field_type_common
*ft_a
,
3401 struct bt_ctf_field_type_common
*ft_b
)
3405 struct bt_ctf_field_type_common_structure
*struct_ft_a
=
3406 BT_CTF_FROM_COMMON(ft_a
);
3407 struct bt_ctf_field_type_common_structure
*struct_ft_b
=
3408 BT_CTF_FROM_COMMON(ft_b
);
3411 if (bt_ctf_field_type_common_get_alignment(ft_a
) !=
3412 bt_ctf_field_type_common_get_alignment(ft_b
)) {
3413 BT_LOGT("Structure field types differ: different alignments: "
3414 "ft-a-align=%u, ft-b-align=%u",
3415 bt_ctf_field_type_common_get_alignment(ft_a
),
3416 bt_ctf_field_type_common_get_alignment(ft_b
));
3421 if (struct_ft_a
->fields
->len
!= struct_ft_b
->fields
->len
) {
3422 BT_LOGT("Structure field types differ: different field counts: "
3423 "ft-a-field-count=%u, ft-b-field-count=%u",
3424 struct_ft_a
->fields
->len
, struct_ft_b
->fields
->len
);
3428 for (i
= 0; i
< struct_ft_a
->fields
->len
; ++i
) {
3429 struct bt_ctf_field_type_common_structure_field
*field_a
=
3430 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3432 struct bt_ctf_field_type_common_structure_field
*field_b
=
3433 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3436 ret
= compare_structure_variant_members(field_a
->type
,
3437 field_b
->type
, field_a
->name
, field_b
->name
);
3439 /* compare_structure_variant_members() logs what differs */
3440 BT_LOGT_STR("Structure field types differ: different fields.");
3452 int bt_ctf_field_type_common_variant_compare_recursive(
3453 struct bt_ctf_field_type_common
*ft_a
,
3454 struct bt_ctf_field_type_common
*ft_b
)
3458 struct bt_ctf_field_type_common_variant
*var_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3459 struct bt_ctf_field_type_common_variant
*var_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3462 if (strcmp(var_ft_a
->tag_name
->str
, var_ft_b
->tag_name
->str
)) {
3463 BT_LOGT("Variant field types differ: different tag field names: "
3464 "ft-a-tag-field-name=\"%s\", ft-b-tag-field-name=\"%s\"",
3465 var_ft_a
->tag_name
->str
, var_ft_b
->tag_name
->str
);
3470 ret
= bt_ctf_field_type_common_compare(BT_CTF_TO_COMMON(var_ft_a
->tag_ft
),
3471 BT_CTF_TO_COMMON(var_ft_b
->tag_ft
));
3473 BT_LOGT("Variant field types differ: different tag field types: "
3474 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
3475 var_ft_a
->tag_ft
, var_ft_b
->tag_ft
);
3482 if (var_ft_a
->choices
->len
!= var_ft_b
->choices
->len
) {
3483 BT_LOGT("Variant field types differ: different field counts: "
3484 "ft-a-field-count=%u, ft-b-field-count=%u",
3485 var_ft_a
->choices
->len
, var_ft_b
->choices
->len
);
3489 for (i
= 0; i
< var_ft_a
->choices
->len
; ++i
) {
3490 struct bt_ctf_field_type_common_variant_choice
*choice_a
=
3491 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3493 struct bt_ctf_field_type_common_variant_choice
*choice_b
=
3494 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3497 ret
= compare_structure_variant_members(choice_a
->type
,
3498 choice_b
->type
, choice_a
->name
, choice_b
->name
);
3500 /* compare_structure_variant_members() logs what differs */
3501 BT_LOGT_STR("Variant field types differ: different fields.");
3513 int bt_ctf_field_type_common_array_compare_recursive(
3514 struct bt_ctf_field_type_common
*ft_a
,
3515 struct bt_ctf_field_type_common
*ft_b
)
3518 struct bt_ctf_field_type_common_array
*array_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3519 struct bt_ctf_field_type_common_array
*array_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3522 if (array_ft_a
->length
!= array_ft_b
->length
) {
3523 BT_LOGT("Structure field types differ: different lengths: "
3524 "ft-a-length=%u, ft-b-length=%u",
3525 array_ft_a
->length
, array_ft_b
->length
);
3530 ret
= bt_ctf_field_type_common_compare(array_ft_a
->element_ft
,
3531 array_ft_b
->element_ft
);
3533 BT_LOGT("Array field types differ: different element field types: "
3534 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
3535 array_ft_a
->element_ft
, array_ft_b
->element_ft
);
3542 int bt_ctf_field_type_common_sequence_compare_recursive(
3543 struct bt_ctf_field_type_common
*ft_a
,
3544 struct bt_ctf_field_type_common
*ft_b
)
3547 struct bt_ctf_field_type_common_sequence
*seq_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3548 struct bt_ctf_field_type_common_sequence
*seq_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3551 if (strcmp(seq_ft_a
->length_field_name
->str
,
3552 seq_ft_b
->length_field_name
->str
)) {
3553 BT_LOGT("Sequence field types differ: different length field names: "
3554 "ft-a-length-field-name=\"%s\", "
3555 "ft-b-length-field-name=\"%s\"",
3556 seq_ft_a
->length_field_name
->str
,
3557 seq_ft_b
->length_field_name
->str
);
3562 ret
= bt_ctf_field_type_common_compare(seq_ft_a
->element_ft
,
3563 seq_ft_b
->element_ft
);
3565 BT_LOGT("Sequence field types differ: different element field types: "
3566 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
3567 seq_ft_a
->element_ft
, seq_ft_b
->element_ft
);
3574 int bt_ctf_field_type_common_compare(struct bt_ctf_field_type_common
*ft_a
,
3575 struct bt_ctf_field_type_common
*ft_b
)
3579 BT_CTF_ASSERT_PRE_NON_NULL(ft_a
, "Field type A");
3580 BT_CTF_ASSERT_PRE_NON_NULL(ft_b
, "Field type B");
3583 /* Same reference: equal (even if both are NULL) */
3589 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
3595 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
3600 if (ft_a
->id
!= ft_b
->id
) {
3601 /* Different type IDs */
3602 BT_LOGT("Field types differ: different IDs: "
3603 "ft-a-addr=%p, ft-b-addr=%p, "
3604 "ft-a-id=%s, ft-b-id=%s",
3606 bt_ctf_field_type_id_string(ft_a
->id
),
3607 bt_ctf_field_type_id_string(ft_b
->id
));
3611 if (ft_a
->id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
3612 /* Both have unknown type IDs */
3613 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
3617 BT_ASSERT_DBG(ft_a
->methods
->compare
);
3618 ret
= ft_a
->methods
->compare(ft_a
, ft_b
);
3620 BT_LOGT("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
3628 int64_t bt_ctf_field_type_common_get_field_count(struct bt_ctf_field_type_common
*ft
)
3630 int64_t field_count
= -1;
3633 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3635 bt_ctf_field_type_common_structure_get_field_count(ft
);
3637 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3639 bt_ctf_field_type_common_variant_get_field_count(ft
);
3641 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3642 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3644 * Array and sequence types always contain a single member
3645 * (the element type).
3656 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_borrow_field_at_index(
3657 struct bt_ctf_field_type_common
*ft
, int index
)
3659 struct bt_ctf_field_type_common
*field_type
= NULL
;
3662 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3664 int ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
3665 ft
, NULL
, &field_type
, index
);
3672 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3674 int ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
3675 ft
, NULL
, &field_type
, index
);
3682 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3684 bt_ctf_field_type_common_array_borrow_element_field_type(ft
);
3686 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3688 bt_ctf_field_type_common_sequence_borrow_element_field_type(ft
);
3698 int bt_ctf_field_type_common_get_field_index(struct bt_ctf_field_type_common
*ft
,
3701 int field_index
= -1;
3704 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3705 field_index
= bt_ctf_field_type_common_structure_get_field_name_index(
3708 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3709 field_index
= bt_ctf_field_type_common_variant_get_field_name_index(
3719 struct bt_ctf_field_path
*bt_ctf_field_type_common_variant_borrow_tag_field_path(
3720 struct bt_ctf_field_type_common
*ft
)
3722 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3724 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
3725 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
3727 return var_ft
->tag_field_path
;
3730 struct bt_ctf_field_path
*bt_ctf_field_type_common_sequence_borrow_length_field_path(
3731 struct bt_ctf_field_type_common
*ft
)
3733 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3735 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
3736 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
3738 return seq_ft
->length_field_path
;
3741 int bt_ctf_field_type_common_validate_single_clock_class(
3742 struct bt_ctf_field_type_common
*ft
,
3743 struct bt_ctf_clock_class
**expected_clock_class
)
3751 BT_ASSERT_DBG(expected_clock_class
);
3754 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
3756 struct bt_ctf_clock_class
*mapped_clock_class
=
3757 bt_ctf_field_type_common_integer_borrow_mapped_clock_class(ft
);
3759 if (!mapped_clock_class
) {
3763 if (!*expected_clock_class
) {
3764 /* Move reference to output parameter */
3765 *expected_clock_class
= bt_ctf_object_get_ref(mapped_clock_class
);
3766 mapped_clock_class
= NULL
;
3767 BT_LOGT("Setting expected clock class: "
3768 "expected-clock-class-addr=%p",
3769 *expected_clock_class
);
3771 if (mapped_clock_class
!= *expected_clock_class
) {
3772 BT_LOGW("Integer field type is not mapped to "
3773 "the expected clock class: "
3774 "mapped-clock-class-addr=%p, "
3775 "mapped-clock-class-name=\"%s\", "
3776 "expected-clock-class-addr=%p, "
3777 "expected-clock-class-name=\"%s\"",
3779 bt_ctf_clock_class_get_name(mapped_clock_class
),
3780 *expected_clock_class
,
3781 bt_ctf_clock_class_get_name(*expected_clock_class
));
3782 bt_ctf_object_put_ref(mapped_clock_class
);
3790 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3791 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3792 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3794 struct bt_ctf_field_type_common
*sub_ft
= NULL
;
3797 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3798 sub_ft
= bt_ctf_field_type_common_enumeration_borrow_container_field_type(
3801 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3802 sub_ft
= bt_ctf_field_type_common_array_borrow_element_field_type(
3805 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3806 sub_ft
= bt_ctf_field_type_common_sequence_borrow_element_field_type(
3810 BT_LOGF("Unexpected field type ID: id=%d", ft
->id
);
3814 BT_ASSERT_DBG(sub_ft
);
3815 ret
= bt_ctf_field_type_common_validate_single_clock_class(sub_ft
,
3816 expected_clock_class
);
3819 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3822 int64_t count
= bt_ctf_field_type_common_structure_get_field_count(
3825 for (i
= 0; i
< count
; i
++) {
3827 struct bt_ctf_field_type_common
*member_type
;
3829 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
3830 ft
, &name
, &member_type
, i
);
3831 BT_ASSERT_DBG(ret
== 0);
3832 ret
= bt_ctf_field_type_common_validate_single_clock_class(
3833 member_type
, expected_clock_class
);
3835 BT_LOGW("Structure field type's field's type "
3836 "is not recursively mapped to the "
3837 "expected clock class: "
3838 "field-ft-addr=%p, field-name=\"%s\"",
3845 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3848 int64_t count
= bt_ctf_field_type_common_variant_get_field_count(
3851 for (i
= 0; i
< count
; i
++) {
3853 struct bt_ctf_field_type_common
*member_type
;
3855 ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
3856 ft
, &name
, &member_type
, i
);
3857 BT_ASSERT_DBG(ret
== 0);
3858 ret
= bt_ctf_field_type_common_validate_single_clock_class(
3859 member_type
, expected_clock_class
);
3861 BT_LOGW("Variant field type's field's type "
3862 "is not recursively mapped to the "
3863 "expected clock class: "
3864 "field-ft-addr=%p, field-name=\"%s\"",
3880 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
3881 struct bt_ctf_field_type
*ft
);
3884 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy_recursive(
3885 struct bt_ctf_field_type
*ft
);
3888 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
3889 struct bt_ctf_field_type
*ft
);
3892 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy_recursive(
3893 struct bt_ctf_field_type
*ft
);
3896 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy_recursive(
3897 struct bt_ctf_field_type
*ft
);
3900 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy_recursive(
3901 struct bt_ctf_field_type
*ft
);
3904 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy_recursive(
3905 struct bt_ctf_field_type
*type
);
3908 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
3909 struct bt_ctf_field_type
*type
);
3911 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_integer_methods
= {
3912 .freeze
= bt_ctf_field_type_common_generic_freeze
,
3913 .validate
= bt_ctf_field_type_common_integer_validate
,
3914 .set_byte_order
= bt_ctf_field_type_common_integer_set_byte_order
,
3915 .copy
= (bt_ctf_field_type_common_method_copy
)
3916 bt_ctf_field_type_integer_copy
,
3917 .compare
= bt_ctf_field_type_common_integer_compare
,
3920 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_floating_point_methods
= {
3921 .freeze
= bt_ctf_field_type_common_generic_freeze
,
3923 .set_byte_order
= bt_ctf_field_type_common_floating_point_set_byte_order
,
3924 .copy
= (bt_ctf_field_type_common_method_copy
)
3925 bt_ctf_field_type_floating_point_copy
,
3926 .compare
= bt_ctf_field_type_common_floating_point_compare
,
3929 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_enumeration_methods
= {
3930 .freeze
= bt_ctf_field_type_common_enumeration_freeze_recursive
,
3931 .validate
= bt_ctf_field_type_common_enumeration_validate_recursive
,
3932 .set_byte_order
= bt_ctf_field_type_common_enumeration_set_byte_order_recursive
,
3933 .copy
= (bt_ctf_field_type_common_method_copy
)
3934 bt_ctf_field_type_enumeration_copy_recursive
,
3935 .compare
= bt_ctf_field_type_common_enumeration_compare_recursive
,
3938 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_string_methods
= {
3939 .freeze
= bt_ctf_field_type_common_generic_freeze
,
3941 .set_byte_order
= NULL
,
3942 .copy
= (bt_ctf_field_type_common_method_copy
)
3943 bt_ctf_field_type_string_copy
,
3944 .compare
= bt_ctf_field_type_common_string_compare
,
3947 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_array_methods
= {
3948 .freeze
= bt_ctf_field_type_common_array_freeze_recursive
,
3949 .validate
= bt_ctf_field_type_common_array_validate_recursive
,
3950 .set_byte_order
= bt_ctf_field_type_common_array_set_byte_order_recursive
,
3951 .copy
= (bt_ctf_field_type_common_method_copy
)
3952 bt_ctf_field_type_array_copy_recursive
,
3953 .compare
= bt_ctf_field_type_common_array_compare_recursive
,
3956 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_sequence_methods
= {
3957 .freeze
= bt_ctf_field_type_common_sequence_freeze_recursive
,
3958 .validate
= bt_ctf_field_type_common_sequence_validate_recursive
,
3959 .set_byte_order
= bt_ctf_field_type_common_sequence_set_byte_order_recursive
,
3960 .copy
= (bt_ctf_field_type_common_method_copy
)
3961 bt_ctf_field_type_sequence_copy_recursive
,
3962 .compare
= bt_ctf_field_type_common_sequence_compare_recursive
,
3965 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_structure_methods
= {
3966 .freeze
= bt_ctf_field_type_common_structure_freeze_recursive
,
3967 .validate
= bt_ctf_field_type_common_structure_validate_recursive
,
3968 .set_byte_order
= bt_ctf_field_type_common_structure_set_byte_order_recursive
,
3969 .copy
= (bt_ctf_field_type_common_method_copy
)
3970 bt_ctf_field_type_structure_copy_recursive
,
3971 .compare
= bt_ctf_field_type_common_structure_compare_recursive
,
3974 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_variant_methods
= {
3975 .freeze
= bt_ctf_field_type_common_variant_freeze_recursive
,
3976 .validate
= bt_ctf_field_type_common_variant_validate_recursive
,
3977 .set_byte_order
= bt_ctf_field_type_common_variant_set_byte_order_recursive
,
3978 .copy
= (bt_ctf_field_type_common_method_copy
)
3979 bt_ctf_field_type_variant_copy_recursive
,
3980 .compare
= bt_ctf_field_type_common_variant_compare_recursive
,
3983 typedef int (*bt_ctf_field_type_serialize_func
)(struct bt_ctf_field_type_common
*,
3984 struct metadata_context
*);
3986 int bt_ctf_field_type_serialize_recursive(struct bt_ctf_field_type
*type
,
3987 struct metadata_context
*context
)
3990 struct bt_ctf_field_type_common
*type_common
= (void *) type
;
3991 bt_ctf_field_type_serialize_func serialize_func
;
3993 BT_ASSERT_DBG(type
);
3994 BT_ASSERT_DBG(context
);
3996 /* Make sure field type is valid before serializing it */
3997 ret
= bt_ctf_field_type_common_validate((void *) type
);
3999 BT_LOGW("Cannot serialize field type's metadata: field type is invalid: "
4004 serialize_func
= type_common
->spec
.writer
.serialize_func
;
4005 ret
= serialize_func((void *) type
, context
);
4012 const char *get_encoding_string(enum bt_ctf_string_encoding encoding
)
4014 const char *encoding_string
;
4017 case BT_CTF_STRING_ENCODING_NONE
:
4018 encoding_string
= "none";
4020 case BT_CTF_STRING_ENCODING_ASCII
:
4021 encoding_string
= "ASCII";
4023 case BT_CTF_STRING_ENCODING_UTF8
:
4024 encoding_string
= "UTF8";
4027 encoding_string
= "unknown";
4031 return encoding_string
;
4035 const char *get_integer_base_string(enum bt_ctf_integer_base base
)
4037 const char *base_string
;
4040 case BT_CTF_INTEGER_BASE_DECIMAL
:
4041 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
4042 base_string
= "decimal";
4044 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
4045 base_string
= "hexadecimal";
4047 case BT_CTF_INTEGER_BASE_OCTAL
:
4048 base_string
= "octal";
4050 case BT_CTF_INTEGER_BASE_BINARY
:
4051 base_string
= "binary";
4054 base_string
= "unknown";
4062 void append_field_name(struct metadata_context
*context
,
4065 g_string_append_c(context
->string
, ' ');
4067 if (!bt_ctf_identifier_is_valid(name
) || *name
== '_') {
4068 g_string_append_c(context
->string
, '_');
4071 g_string_append(context
->string
, name
);
4075 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type_common
*type
,
4076 struct metadata_context
*context
)
4078 struct bt_ctf_field_type_common_integer
*integer
= BT_CTF_FROM_COMMON(type
);
4081 BT_LOGD("Serializing CTF writer integer field type's metadata: "
4082 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4083 g_string_append_printf(context
->string
,
4084 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
4085 integer
->size
, type
->alignment
,
4086 (integer
->is_signed
? "true" : "false"),
4087 get_encoding_string(integer
->encoding
),
4088 get_integer_base_string(integer
->base
),
4089 bt_ctf_get_byte_order_string(integer
->user_byte_order
));
4090 if (integer
->mapped_clock_class
) {
4091 const char *clock_name
= bt_ctf_clock_class_get_name(
4092 integer
->mapped_clock_class
);
4094 BT_ASSERT_DBG(clock_name
);
4095 g_string_append_printf(context
->string
,
4096 "; map = clock.%s.value", clock_name
);
4099 g_string_append(context
->string
, "; }");
4104 int bt_ctf_field_type_enumeration_serialize_recursive(
4105 struct bt_ctf_field_type_common
*type
,
4106 struct metadata_context
*context
)
4110 struct bt_ctf_field_type_common_enumeration
*enumeration
=
4111 BT_CTF_FROM_COMMON(type
);
4112 struct bt_ctf_field_type_common
*container_type
;
4113 int container_signed
;
4115 BT_LOGD("Serializing CTF writer enumeration field type's metadata: "
4116 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4118 bt_ctf_field_type_common_enumeration_borrow_container_field_type(type
);
4119 BT_ASSERT_DBG(container_type
);
4120 container_signed
= bt_ctf_field_type_common_integer_is_signed(
4122 BT_ASSERT_DBG(container_signed
>= 0);
4123 g_string_append(context
->string
, "enum : ");
4124 BT_LOGD_STR("Serializing CTF writer enumeration field type's container field type's metadata.");
4125 ret
= bt_ctf_field_type_serialize_recursive(
4126 (void *) enumeration
->container_ft
, context
);
4128 BT_LOGW("Cannot serialize CTF writer enumeration field type's container field type's metadata: "
4129 "container-ft-addr=%p", enumeration
->container_ft
);
4133 g_string_append(context
->string
, " { ");
4134 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
4135 struct bt_ctf_enumeration_mapping
*mapping
=
4136 enumeration
->entries
->pdata
[entry
];
4137 const char *label
= g_quark_to_string(mapping
->string
);
4139 g_string_append(context
->string
, "\"");
4141 if (!bt_ctf_identifier_is_valid(label
) || label
[0] == '_') {
4142 g_string_append(context
->string
, "_");
4145 g_string_append_printf(context
->string
, "%s\" = ", label
);
4147 if (container_signed
) {
4148 if (mapping
->range_start
._signed
==
4149 mapping
->range_end
._signed
) {
4150 g_string_append_printf(context
->string
,
4152 mapping
->range_start
._signed
);
4154 g_string_append_printf(context
->string
,
4155 "%" PRId64
" ... %" PRId64
,
4156 mapping
->range_start
._signed
,
4157 mapping
->range_end
._signed
);
4160 if (mapping
->range_start
._unsigned
==
4161 mapping
->range_end
._unsigned
) {
4162 g_string_append_printf(context
->string
,
4164 mapping
->range_start
._unsigned
);
4166 g_string_append_printf(context
->string
,
4167 "%" PRIu64
" ... %" PRIu64
,
4168 mapping
->range_start
._unsigned
,
4169 mapping
->range_end
._unsigned
);
4173 g_string_append(context
->string
,
4174 ((entry
!= (enumeration
->entries
->len
- 1)) ?
4178 if (context
->field_name
->len
) {
4179 append_field_name(context
,
4180 context
->field_name
->str
);
4181 g_string_assign(context
->field_name
, "");
4189 int bt_ctf_field_type_floating_point_serialize(struct bt_ctf_field_type_common
*type
,
4190 struct metadata_context
*context
)
4192 struct bt_ctf_field_type_common_floating_point
*floating_point
=
4193 BT_CTF_FROM_COMMON(type
);
4195 BT_LOGD("Serializing CTF writer floating point number field type's metadata: "
4196 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4197 g_string_append_printf(context
->string
,
4198 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
4199 floating_point
->exp_dig
,
4200 floating_point
->mant_dig
,
4201 bt_ctf_get_byte_order_string(floating_point
->user_byte_order
),
4207 int bt_ctf_field_type_structure_serialize_recursive(
4208 struct bt_ctf_field_type_common
*type
,
4209 struct metadata_context
*context
)
4212 unsigned int indent
;
4214 struct bt_ctf_field_type_common_structure
*structure
= BT_CTF_FROM_COMMON(type
);
4215 GString
*structure_field_name
= context
->field_name
;
4217 BT_LOGD("Serializing CTF writer structure field type's metadata: "
4218 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4219 context
->field_name
= g_string_new("");
4221 context
->current_indentation_level
++;
4222 g_string_append(context
->string
, "struct {\n");
4224 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4225 struct bt_ctf_field_type_common_structure_field
*field
=
4226 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
4229 BT_LOGD("Serializing CTF writer structure field type's field metadata: "
4231 "field-ft-addr=%p, field-name=\"%s\"",
4232 i
, field
, g_quark_to_string(field
->name
));
4234 for (indent
= 0; indent
< context
->current_indentation_level
;
4236 g_string_append_c(context
->string
, '\t');
4239 g_string_assign(context
->field_name
,
4240 g_quark_to_string(field
->name
));
4241 ret
= bt_ctf_field_type_serialize_recursive(
4242 (void *) field
->type
, context
);
4244 BT_LOGW("Cannot serialize CTF writer structure field type's field's metadata: "
4246 "field-ft-addr=%p, field-name=\"%s\"",
4248 g_quark_to_string(field
->name
));
4252 if (context
->field_name
->len
) {
4253 append_field_name(context
,
4254 context
->field_name
->str
);
4256 g_string_append(context
->string
, ";\n");
4259 context
->current_indentation_level
--;
4260 for (indent
= 0; indent
< context
->current_indentation_level
;
4262 g_string_append_c(context
->string
, '\t');
4265 g_string_append_printf(context
->string
, "} align(%u)",
4269 g_string_free(context
->field_name
, TRUE
);
4270 context
->field_name
= structure_field_name
;
4275 int bt_ctf_field_type_variant_serialize_recursive(
4276 struct bt_ctf_field_type_common
*type
,
4277 struct metadata_context
*context
)
4280 unsigned int indent
;
4282 struct bt_ctf_field_type_common_variant
*variant
= BT_CTF_FROM_COMMON(type
);
4283 GString
*variant_field_name
= context
->field_name
;
4285 BT_LOGD("Serializing CTF writer variant field type's metadata: "
4286 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4287 context
->field_name
= g_string_new("");
4288 if (variant
->tag_name
->len
> 0) {
4289 g_string_append(context
->string
, "variant <");
4290 append_field_name(context
, variant
->tag_name
->str
);
4291 g_string_append(context
->string
, "> {\n");
4293 g_string_append(context
->string
, "variant {\n");
4296 context
->current_indentation_level
++;
4297 for (i
= 0; i
< variant
->choices
->len
; i
++) {
4298 struct bt_ctf_field_type_common_variant_choice
*field
=
4299 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
4302 BT_LOGD("Serializing CTF writer variant field type's field metadata: "
4304 "field-ft-addr=%p, field-name=\"%s\"",
4305 i
, field
, g_quark_to_string(field
->name
));
4307 g_string_assign(context
->field_name
,
4308 g_quark_to_string(field
->name
));
4309 for (indent
= 0; indent
< context
->current_indentation_level
;
4311 g_string_append_c(context
->string
, '\t');
4314 g_string_assign(context
->field_name
,
4315 g_quark_to_string(field
->name
));
4316 ret
= bt_ctf_field_type_serialize_recursive(
4317 (void *) field
->type
, context
);
4319 BT_LOGW("Cannot serialize CTF writer variant field type's field's metadata: "
4321 "field-ft-addr=%p, field-name=\"%s\"",
4323 g_quark_to_string(field
->name
));
4327 if (context
->field_name
->len
) {
4328 append_field_name(context
,
4329 context
->field_name
->str
);
4330 g_string_append_c(context
->string
, ';');
4333 g_string_append_c(context
->string
, '\n');
4336 context
->current_indentation_level
--;
4337 for (indent
= 0; indent
< context
->current_indentation_level
;
4339 g_string_append_c(context
->string
, '\t');
4342 g_string_append(context
->string
, "}");
4345 g_string_free(context
->field_name
, TRUE
);
4346 context
->field_name
= variant_field_name
;
4351 int bt_ctf_field_type_array_serialize_recursive(
4352 struct bt_ctf_field_type_common
*type
,
4353 struct metadata_context
*context
)
4356 struct bt_ctf_field_type_common_array
*array
= BT_CTF_FROM_COMMON(type
);
4358 BT_LOGD("Serializing CTF writer array field type's metadata: "
4359 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4360 BT_LOGD_STR("Serializing CTF writer array field type's element field type's metadata.");
4361 ret
= bt_ctf_field_type_serialize_recursive(
4362 (void *) array
->element_ft
, context
);
4364 BT_LOGW("Cannot serialize CTF writer array field type's element field type's metadata: "
4365 "element-ft-addr=%p", array
->element_ft
);
4369 if (context
->field_name
->len
) {
4370 append_field_name(context
,
4371 context
->field_name
->str
);
4373 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4374 g_string_assign(context
->field_name
, "");
4376 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4384 int bt_ctf_field_type_sequence_serialize_recursive(
4385 struct bt_ctf_field_type_common
*type
,
4386 struct metadata_context
*context
)
4389 struct bt_ctf_field_type_common_sequence
*sequence
= BT_CTF_FROM_COMMON(type
);
4391 BT_LOGD("Serializing CTF writer sequence field type's metadata: "
4392 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4393 BT_LOGD_STR("Serializing CTF writer sequence field type's element field type's metadata.");
4394 ret
= bt_ctf_field_type_serialize_recursive(
4395 (void *) sequence
->element_ft
, context
);
4397 BT_LOGW("Cannot serialize CTF writer sequence field type's element field type's metadata: "
4398 "element-ft-addr=%p", sequence
->element_ft
);
4402 if (context
->field_name
->len
) {
4403 append_field_name(context
, context
->field_name
->str
);
4404 g_string_assign(context
->field_name
, "");
4406 g_string_append(context
->string
, "[");
4407 append_field_name(context
, sequence
->length_field_name
->str
);
4408 g_string_append(context
->string
, "]");
4415 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type_common
*type
,
4416 struct metadata_context
*context
)
4418 struct bt_ctf_field_type_common_string
*string
= BT_CTF_FROM_COMMON(type
);
4420 BT_LOGD("Serializing CTF writer string field type's metadata: "
4421 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4422 g_string_append_printf(context
->string
,
4423 "string { encoding = %s; }",
4424 get_encoding_string(string
->encoding
));
4429 struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(unsigned int size
)
4431 struct bt_ctf_field_type_common_integer
*integer
= NULL
;
4433 BT_LOGD("Creating CTF writer integer field type object: size=%u", size
);
4435 if (size
== 0 || size
> 64) {
4436 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
4441 integer
= g_new0(struct bt_ctf_field_type_common_integer
, 1);
4443 BT_LOGE_STR("Failed to allocate one integer field type.");
4447 bt_ctf_field_type_common_integer_initialize(BT_CTF_TO_COMMON(integer
),
4448 size
, bt_ctf_field_type_common_integer_destroy
,
4449 &bt_ctf_field_type_integer_methods
);
4450 integer
->common
.spec
.writer
.serialize_func
=
4451 bt_ctf_field_type_integer_serialize
;
4452 BT_LOGD("Created CTF writer integer field type object: addr=%p, size=%u",
4457 BT_CTF_OBJECT_PUT_REF_AND_RESET(integer
);
4460 return (void *) integer
;
4464 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type
*ft
)
4466 return bt_ctf_field_type_common_integer_get_size((void *) ft
);
4470 bt_ctf_bool
bt_ctf_field_type_integer_is_signed(struct bt_ctf_field_type
*ft
)
4472 return bt_ctf_field_type_common_integer_is_signed((void *) ft
);
4476 int bt_ctf_field_type_integer_set_is_signed(struct bt_ctf_field_type
*ft
,
4477 bt_ctf_bool is_signed
)
4479 return bt_ctf_field_type_common_integer_set_is_signed((void *) ft
,
4484 int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type
*ft
,
4487 return bt_ctf_field_type_common_integer_set_size((void *) ft
, size
);
4491 enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
4492 struct bt_ctf_field_type
*ft
)
4494 return (int) bt_ctf_field_type_common_integer_get_base((void *) ft
);
4498 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*ft
,
4499 enum bt_ctf_integer_base base
)
4501 return bt_ctf_field_type_common_integer_set_base((void *) ft
,
4506 enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
4507 struct bt_ctf_field_type
*ft
)
4509 return (int) bt_ctf_field_type_common_integer_get_encoding((void *) ft
);
4513 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type
*ft
,
4514 enum bt_ctf_string_encoding encoding
)
4516 return bt_ctf_field_type_common_integer_set_encoding((void *) ft
,
4521 struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
4522 struct bt_ctf_field_type
*ft
)
4524 return bt_ctf_object_get_ref(bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
4529 int bt_ctf_field_type_integer_set_mapped_clock_class(
4530 struct bt_ctf_field_type
*ft
,
4531 struct bt_ctf_clock_class
*clock_class
)
4533 return bt_ctf_field_type_common_integer_set_mapped_clock_class((void *) ft
,
4538 int bt_ctf_field_type_enumeration_signed_get_mapping_by_index(
4539 struct bt_ctf_field_type
*ft
, uint64_t index
,
4540 const char **mapping_name
, int64_t *range_begin
,
4543 return bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
4544 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
4548 int bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(
4549 struct bt_ctf_field_type
*ft
, uint64_t index
,
4550 const char **mapping_name
, uint64_t *range_begin
,
4551 uint64_t *range_end
)
4553 return bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
4554 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
4558 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
4559 struct bt_ctf_field_type
*container_ft
)
4561 struct bt_ctf_field_type_common_enumeration
*enumeration
= NULL
;
4562 struct bt_ctf_field_type_common
*int_ft
= (void *) container_ft
;
4564 BT_LOGD("Creating CTF writer enumeration field type object: int-ft-addr=%p",
4567 if (!container_ft
) {
4568 BT_LOGW_STR("Invalid parameter: field type is NULL.");
4572 if (int_ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
4573 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
4574 "container-ft-addr=%p, container-ft-id=%s",
4575 container_ft
, bt_ctf_field_type_id_string(int_ft
->id
));
4579 enumeration
= g_new0(struct bt_ctf_field_type_common_enumeration
, 1);
4581 BT_LOGE_STR("Failed to allocate one enumeration field type.");
4585 bt_ctf_field_type_common_enumeration_initialize(BT_CTF_TO_COMMON(enumeration
),
4586 int_ft
, bt_ctf_field_type_common_enumeration_destroy_recursive
,
4587 &bt_ctf_field_type_enumeration_methods
);
4588 enumeration
->common
.spec
.writer
.serialize_func
=
4589 bt_ctf_field_type_enumeration_serialize_recursive
;
4590 BT_LOGD("Created CTF writer enumeration field type object: addr=%p, "
4591 "int-ft-addr=%p, int-ft-size=%u",
4592 enumeration
, container_ft
,
4593 bt_ctf_field_type_integer_get_size(container_ft
));
4597 BT_CTF_OBJECT_PUT_REF_AND_RESET(enumeration
);
4600 return (void *) enumeration
;
4604 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_field_type(
4605 struct bt_ctf_field_type
*ft
)
4607 return bt_ctf_object_get_ref(
4608 bt_ctf_field_type_common_enumeration_borrow_container_field_type(
4613 int bt_ctf_field_type_enumeration_signed_add_mapping(
4614 struct bt_ctf_field_type
*ft
, const char *string
,
4615 int64_t range_start
, int64_t range_end
)
4617 return bt_ctf_field_type_common_enumeration_signed_add_mapping(
4618 (void *) ft
, string
, range_start
, range_end
);
4622 int bt_ctf_field_type_enumeration_unsigned_add_mapping(
4623 struct bt_ctf_field_type
*ft
, const char *string
,
4624 uint64_t range_start
, uint64_t range_end
)
4626 return bt_ctf_field_type_common_enumeration_unsigned_add_mapping(
4627 (void *) ft
, string
, range_start
, range_end
);
4631 int64_t bt_ctf_field_type_enumeration_get_mapping_count(
4632 struct bt_ctf_field_type
*ft
)
4634 return bt_ctf_field_type_common_enumeration_get_mapping_count((void *) ft
);
4638 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void)
4640 struct bt_ctf_field_type_common_floating_point
*floating_point
=
4641 g_new0(struct bt_ctf_field_type_common_floating_point
, 1);
4643 BT_LOGD_STR("Creating CTF writer floating point number field type object.");
4645 if (!floating_point
) {
4646 BT_LOGE_STR("Failed to allocate one floating point number field type.");
4650 bt_ctf_field_type_common_floating_point_initialize(
4651 BT_CTF_TO_COMMON(floating_point
),
4652 bt_ctf_field_type_common_floating_point_destroy
,
4653 &bt_ctf_field_type_floating_point_methods
);
4654 floating_point
->common
.spec
.writer
.serialize_func
=
4655 bt_ctf_field_type_floating_point_serialize
;
4656 BT_LOGD("Created CTF writer floating point number field type object: addr=%p, "
4657 "exp-size=%u, mant-size=%u", floating_point
,
4658 floating_point
->exp_dig
, floating_point
->mant_dig
);
4661 return (void *) floating_point
;
4665 int bt_ctf_field_type_floating_point_get_exponent_digits(
4666 struct bt_ctf_field_type
*ft
)
4668 return bt_ctf_field_type_common_floating_point_get_exponent_digits(
4673 int bt_ctf_field_type_floating_point_set_exponent_digits(
4674 struct bt_ctf_field_type
*ft
, unsigned int exponent_digits
)
4676 return bt_ctf_field_type_common_floating_point_set_exponent_digits(
4677 (void *) ft
, exponent_digits
);
4681 int bt_ctf_field_type_floating_point_get_mantissa_digits(
4682 struct bt_ctf_field_type
*ft
)
4684 return bt_ctf_field_type_common_floating_point_get_mantissa_digits(
4689 int bt_ctf_field_type_floating_point_set_mantissa_digits(
4690 struct bt_ctf_field_type
*ft
, unsigned int mantissa_digits
)
4692 return bt_ctf_field_type_common_floating_point_set_mantissa_digits(
4693 (void *) ft
, mantissa_digits
);
4697 struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void)
4699 struct bt_ctf_field_type_common_structure
*structure
=
4700 g_new0(struct bt_ctf_field_type_common_structure
, 1);
4702 BT_LOGD_STR("Creating CTF writer structure field type object.");
4705 BT_LOGE_STR("Failed to allocate one structure field type.");
4709 bt_ctf_field_type_common_structure_initialize(BT_CTF_TO_COMMON(structure
),
4710 bt_ctf_field_type_common_structure_destroy_recursive
,
4711 &bt_ctf_field_type_structure_methods
);
4712 structure
->common
.spec
.writer
.serialize_func
=
4713 bt_ctf_field_type_structure_serialize_recursive
;
4714 BT_LOGD("Created CTF writer structure field type object: addr=%p",
4719 BT_CTF_OBJECT_PUT_REF_AND_RESET(structure
);
4722 return (void *) structure
;
4726 int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type
*ft
,
4727 struct bt_ctf_field_type
*field_type
,
4728 const char *field_name
)
4730 return bt_ctf_field_type_common_structure_add_field((void *) ft
,
4731 (void *) field_type
, field_name
);
4735 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type
*ft
)
4737 return bt_ctf_field_type_common_structure_get_field_count((void *) ft
);
4741 int bt_ctf_field_type_structure_get_field_by_index(
4742 struct bt_ctf_field_type
*ft
,
4743 const char **field_name
,
4744 struct bt_ctf_field_type
**field_type
, uint64_t index
)
4746 int ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
4747 (void *) ft
, field_name
, (void *) field_type
, index
);
4749 if (ret
== 0 && field_type
) {
4750 bt_ctf_object_get_ref(*field_type
);
4757 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
4758 struct bt_ctf_field_type
*ft
, const char *name
)
4760 return bt_ctf_object_get_ref(bt_ctf_field_type_common_structure_borrow_field_type_by_name(
4761 (void *) ft
, name
));
4765 struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
4766 struct bt_ctf_field_type
*tag_ft
, const char *tag_name
)
4768 struct bt_ctf_field_type_common_variant
*var_ft
= NULL
;
4770 BT_LOGD("Creating CTF writer variant field type object: "
4771 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4774 if (tag_name
&& !bt_ctf_identifier_is_valid(tag_name
)) {
4775 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
4776 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4781 var_ft
= g_new0(struct bt_ctf_field_type_common_variant
, 1);
4783 BT_LOGE_STR("Failed to allocate one variant field type.");
4787 bt_ctf_field_type_common_variant_initialize(BT_CTF_TO_COMMON(var_ft
),
4788 (void *) tag_ft
, tag_name
,
4789 bt_ctf_field_type_common_variant_destroy_recursive
,
4790 &bt_ctf_field_type_variant_methods
);
4791 var_ft
->common
.spec
.writer
.serialize_func
=
4792 bt_ctf_field_type_variant_serialize_recursive
;
4793 BT_LOGD("Created CTF writer variant field type object: addr=%p, "
4794 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4795 var_ft
, tag_ft
, tag_name
);
4799 BT_CTF_OBJECT_PUT_REF_AND_RESET(var_ft
);
4802 return (void *) var_ft
;
4806 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_field_type(
4807 struct bt_ctf_field_type
*ft
)
4809 return bt_ctf_object_get_ref(bt_ctf_field_type_common_variant_borrow_tag_field_type(
4814 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type
*ft
)
4816 return bt_ctf_field_type_common_variant_get_tag_name((void *) ft
);
4820 int bt_ctf_field_type_variant_set_tag_name(
4821 struct bt_ctf_field_type
*ft
, const char *name
)
4823 return bt_ctf_field_type_common_variant_set_tag_name((void *) ft
, name
);
4827 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type
*ft
,
4828 struct bt_ctf_field_type
*field_type
,
4829 const char *field_name
)
4831 return bt_ctf_field_type_common_variant_add_field((void *) ft
,
4832 (void *) field_type
, field_name
);
4836 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
4837 struct bt_ctf_field_type
*ft
,
4838 const char *field_name
)
4840 return bt_ctf_object_get_ref(bt_ctf_field_type_common_variant_borrow_field_type_by_name(
4841 (void *) ft
, field_name
));
4845 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
4846 struct bt_ctf_field_type
*ft
,
4847 struct bt_ctf_field
*tag_field
)
4850 int64_t choice_index
;
4851 struct bt_ctf_field
*container
;
4852 struct bt_ctf_field_type_common_variant
*var_ft
= (void *) ft
;
4853 struct bt_ctf_field_type
*ret_ft
= NULL
;
4855 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
4856 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
4858 BT_CTF_ASSERT_PRE_NON_NULL(tag_field
, "Tag field");
4859 BT_CTF_ASSERT_PRE_CTF_FIELD_COMMON_HAS_TYPE_ID(
4860 (struct bt_ctf_field_common
*) tag_field
,
4861 BT_CTF_FIELD_TYPE_ID_ENUM
, "Tag field");
4862 BT_CTF_ASSERT_PRE_CTF_FIELD_COMMON_IS_SET((struct bt_ctf_field_common
*) tag_field
,
4865 container
= bt_ctf_field_enumeration_borrow_container(tag_field
);
4866 BT_ASSERT_DBG(container
);
4868 if (var_ft
->tag_ft
->container_ft
->is_signed
) {
4871 ret
= bt_ctf_field_integer_signed_get_value(container
,
4873 BT_ASSERT_DBG(ret
== 0);
4874 choice_index
= bt_ctf_field_type_common_variant_find_choice_index(
4875 (void *) ft
, (uint64_t) val
, true);
4879 ret
= bt_ctf_field_integer_unsigned_get_value(container
,
4881 BT_ASSERT_DBG(ret
== 0);
4882 choice_index
= bt_ctf_field_type_common_variant_find_choice_index(
4883 (void *) ft
, val
, false);
4886 if (choice_index
< 0) {
4887 BT_LOGW("Cannot find variant field type's field: "
4888 "var-ft-addr=%p, tag-field-addr=%p", ft
, tag_field
);
4892 ret
= bt_ctf_field_type_variant_get_field_by_index(ft
, NULL
,
4893 &ret_ft
, choice_index
);
4894 BT_ASSERT_DBG(ret
== 0);
4901 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type
*ft
)
4903 return bt_ctf_field_type_common_variant_get_field_count((void *) ft
);
4907 int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type
*ft
,
4908 const char **field_name
, struct bt_ctf_field_type
**field_type
,
4911 int ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
4912 (void *) ft
, field_name
, (void *) field_type
, index
);
4914 if (ret
== 0 && field_type
) {
4915 bt_ctf_object_get_ref(*field_type
);
4922 struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
4923 struct bt_ctf_field_type
*element_ft
, unsigned int length
)
4925 struct bt_ctf_field_type_common_array
*array
= NULL
;
4927 BT_LOGD("Creating CTF writer array field type object: element-ft-addr=%p, "
4928 "length=%u", element_ft
, length
);
4931 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
4936 BT_LOGW_STR("Invalid parameter: length is zero.");
4940 array
= g_new0(struct bt_ctf_field_type_common_array
, 1);
4942 BT_LOGE_STR("Failed to allocate one array field type.");
4946 bt_ctf_field_type_common_array_initialize(BT_CTF_TO_COMMON(array
),
4947 (void *) element_ft
, length
,
4948 bt_ctf_field_type_common_array_destroy_recursive
,
4949 &bt_ctf_field_type_array_methods
);
4950 array
->common
.spec
.writer
.serialize_func
=
4951 bt_ctf_field_type_array_serialize_recursive
;
4952 BT_LOGD("Created CTF writer array field type object: addr=%p, "
4953 "element-ft-addr=%p, length=%u",
4954 array
, element_ft
, length
);
4958 BT_CTF_OBJECT_PUT_REF_AND_RESET(array
);
4961 return (void *) array
;
4965 struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_field_type(
4966 struct bt_ctf_field_type
*ft
)
4968 return bt_ctf_object_get_ref(bt_ctf_field_type_common_array_borrow_element_field_type(
4973 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type
*ft
)
4975 return bt_ctf_field_type_common_array_get_length((void *) ft
);
4979 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
4980 struct bt_ctf_field_type
*element_ft
,
4981 const char *length_field_name
)
4983 struct bt_ctf_field_type_common_sequence
*sequence
= NULL
;
4985 BT_LOGD("Creating CTF writer sequence field type object: element-ft-addr=%p, "
4986 "length-field-name=\"%s\"", element_ft
, length_field_name
);
4989 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
4993 if (!bt_ctf_identifier_is_valid(length_field_name
)) {
4994 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
4995 "length-field-name=\"%s\"", length_field_name
);
4999 sequence
= g_new0(struct bt_ctf_field_type_common_sequence
, 1);
5001 BT_LOGE_STR("Failed to allocate one sequence field type.");
5005 bt_ctf_field_type_common_sequence_initialize(BT_CTF_TO_COMMON(sequence
),
5006 (void *) element_ft
, length_field_name
,
5007 bt_ctf_field_type_common_sequence_destroy_recursive
,
5008 &bt_ctf_field_type_sequence_methods
);
5009 sequence
->common
.spec
.writer
.serialize_func
=
5010 bt_ctf_field_type_sequence_serialize_recursive
;
5011 BT_LOGD("Created CTF writer sequence field type object: addr=%p, "
5012 "element-ft-addr=%p, length-field-name=\"%s\"",
5013 sequence
, element_ft
, length_field_name
);
5017 BT_CTF_OBJECT_PUT_REF_AND_RESET(sequence
);
5020 return (void *) sequence
;
5024 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_field_type(
5025 struct bt_ctf_field_type
*ft
)
5027 return bt_ctf_object_get_ref(bt_ctf_field_type_common_sequence_borrow_element_field_type(
5032 const char *bt_ctf_field_type_sequence_get_length_field_name(
5033 struct bt_ctf_field_type
*ft
)
5035 return bt_ctf_field_type_common_sequence_get_length_field_name((void *) ft
);
5039 struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void)
5041 struct bt_ctf_field_type_common_string
*string
=
5042 g_new0(struct bt_ctf_field_type_common_string
, 1);
5044 BT_LOGD_STR("Creating CTF writer string field type object.");
5047 BT_LOGE_STR("Failed to allocate one string field type.");
5051 bt_ctf_field_type_common_string_initialize(BT_CTF_TO_COMMON(string
),
5052 bt_ctf_field_type_common_string_destroy
,
5053 &bt_ctf_field_type_string_methods
);
5054 string
->common
.spec
.writer
.serialize_func
=
5055 bt_ctf_field_type_string_serialize
;
5056 BT_LOGD("Created CTF writer string field type object: addr=%p", string
);
5057 return (void *) string
;
5061 enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
5062 struct bt_ctf_field_type
*ft
)
5064 return (int) bt_ctf_field_type_common_string_get_encoding((void *) ft
);
5068 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type
*ft
,
5069 enum bt_ctf_string_encoding encoding
)
5071 return bt_ctf_field_type_common_string_set_encoding((void *) ft
,
5076 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*ft
)
5078 return bt_ctf_field_type_common_get_alignment((void *) ft
);
5082 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*ft
,
5083 unsigned int alignment
)
5085 return bt_ctf_field_type_common_set_alignment((void *) ft
, alignment
);
5089 enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
5090 struct bt_ctf_field_type
*ft
)
5092 return (int) bt_ctf_field_type_common_get_byte_order((void *) ft
);
5096 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*ft
,
5097 enum bt_ctf_byte_order byte_order
)
5099 return bt_ctf_field_type_common_set_byte_order((void *) ft
,
5104 enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
5105 struct bt_ctf_field_type
*ft
)
5107 return (int) bt_ctf_field_type_common_get_type_id((void *) ft
);
5110 struct bt_ctf_field_type
*bt_ctf_field_type_copy(struct bt_ctf_field_type
*ft
)
5112 return (void *) bt_ctf_field_type_common_copy((void *) ft
);
5116 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
5117 struct bt_ctf_field_type
*ft
)
5119 struct bt_ctf_field_type_common_integer
*int_ft
= (void *) ft
;
5120 struct bt_ctf_field_type_common_integer
*copy_ft
;
5122 BT_LOGD("Copying CTF writer integer field type's: addr=%p", ft
);
5123 copy_ft
= (void *) bt_ctf_field_type_integer_create(int_ft
->size
);
5125 BT_LOGE_STR("Cannot create CTF writer integer field type.");
5129 copy_ft
->mapped_clock_class
= bt_ctf_object_get_ref(int_ft
->mapped_clock_class
);
5130 copy_ft
->user_byte_order
= int_ft
->user_byte_order
;
5131 copy_ft
->is_signed
= int_ft
->is_signed
;
5132 copy_ft
->size
= int_ft
->size
;
5133 copy_ft
->base
= int_ft
->base
;
5134 copy_ft
->encoding
= int_ft
->encoding
;
5135 BT_LOGD("Copied CTF writer integer field type: original-ft-addr=%p, copy-ft-addr=%p",
5139 return (void *) copy_ft
;
5143 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy_recursive(
5144 struct bt_ctf_field_type
*ft
)
5147 struct bt_ctf_field_type_common_enumeration
*enum_ft
= (void *) ft
;
5148 struct bt_ctf_field_type_common_enumeration
*copy_ft
= NULL
;
5149 struct bt_ctf_field_type_common_enumeration
*container_copy_ft
;
5151 BT_LOGD("Copying CTF writer enumeration field type's: addr=%p", ft
);
5153 /* Copy the source enumeration's container */
5154 BT_LOGD_STR("Copying CTF writer enumeration field type's container field type.");
5155 container_copy_ft
= BT_CTF_FROM_COMMON(bt_ctf_field_type_common_copy(
5156 BT_CTF_TO_COMMON(enum_ft
->container_ft
)));
5157 if (!container_copy_ft
) {
5158 BT_LOGE_STR("Cannot copy CTF writer enumeration field type's container field type.");
5162 copy_ft
= (void *) bt_ctf_field_type_enumeration_create(
5163 (void *) container_copy_ft
);
5165 BT_LOGE_STR("Cannot create CTF writer enumeration field type.");
5169 /* Copy all enumaration entries */
5170 for (i
= 0; i
< enum_ft
->entries
->len
; i
++) {
5171 struct bt_ctf_enumeration_mapping
*mapping
= g_ptr_array_index(
5172 enum_ft
->entries
, i
);
5173 struct bt_ctf_enumeration_mapping
*copy_mapping
= g_new0(
5174 struct bt_ctf_enumeration_mapping
, 1);
5176 if (!copy_mapping
) {
5177 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
5181 *copy_mapping
= *mapping
;
5182 g_ptr_array_add(copy_ft
->entries
, copy_mapping
);
5185 BT_LOGD("Copied CTF writer enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
5189 bt_ctf_object_put_ref(container_copy_ft
);
5190 return (void *) copy_ft
;
5193 bt_ctf_object_put_ref(container_copy_ft
);
5194 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5195 return (void *) copy_ft
;
5199 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
5200 struct bt_ctf_field_type
*ft
)
5202 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
5203 struct bt_ctf_field_type_common_floating_point
*copy_ft
;
5205 BT_LOGD("Copying CTF writer floating point number field type's: addr=%p", ft
);
5206 copy_ft
= (void *) bt_ctf_field_type_floating_point_create();
5208 BT_LOGE_STR("Cannot create CTF writer floating point number field type.");
5212 copy_ft
->user_byte_order
= flt_ft
->user_byte_order
;
5213 copy_ft
->exp_dig
= flt_ft
->exp_dig
;
5214 copy_ft
->mant_dig
= flt_ft
->mant_dig
;
5215 BT_LOGD("Copied CTF writer floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
5219 return (void *) copy_ft
;
5223 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy_recursive(
5224 struct bt_ctf_field_type
*ft
)
5227 GHashTableIter iter
;
5228 gpointer key
, value
;
5229 struct bt_ctf_field_type_common_structure
*struct_ft
= (void *) ft
;
5230 struct bt_ctf_field_type_common_structure
*copy_ft
;
5232 BT_LOGD("Copying CTF writer structure field type's: addr=%p", ft
);
5233 copy_ft
= (void *) bt_ctf_field_type_structure_create();
5235 BT_LOGE_STR("Cannot create CTF writer structure field type.");
5239 /* Copy field_name_to_index */
5240 g_hash_table_iter_init(&iter
, struct_ft
->field_name_to_index
);
5241 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
5242 g_hash_table_insert(copy_ft
->field_name_to_index
,
5246 g_array_set_size(copy_ft
->fields
, struct_ft
->fields
->len
);
5248 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
5249 struct bt_ctf_field_type_common_structure_field
*entry
, *copy_entry
;
5250 struct bt_ctf_field_type_common
*field_ft_copy
;
5252 entry
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
5254 copy_entry
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
5256 BT_LOGD("Copying CTF writer structure field type's field: "
5257 "index=%" PRId64
", "
5258 "field-ft-addr=%p, field-name=\"%s\"",
5259 i
, entry
, g_quark_to_string(entry
->name
));
5261 field_ft_copy
= (void *) bt_ctf_field_type_copy(
5262 (void *) entry
->type
);
5263 if (!field_ft_copy
) {
5264 BT_LOGE("Cannot copy CTF writer structure field type's field: "
5265 "index=%" PRId64
", "
5266 "field-ft-addr=%p, field-name=\"%s\"",
5267 i
, entry
, g_quark_to_string(entry
->name
));
5271 copy_entry
->name
= entry
->name
;
5272 copy_entry
->type
= field_ft_copy
;
5275 BT_LOGD("Copied CTF writer structure field type: original-ft-addr=%p, copy-ft-addr=%p",
5279 return (void *) copy_ft
;
5282 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5287 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy_recursive(
5288 struct bt_ctf_field_type
*ft
)
5291 GHashTableIter iter
;
5292 gpointer key
, value
;
5293 struct bt_ctf_field_type_common
*tag_ft_copy
= NULL
;
5294 struct bt_ctf_field_type_common_variant
*var_ft
= (void *) ft
;
5295 struct bt_ctf_field_type_common_variant
*copy_ft
= NULL
;
5297 BT_LOGD("Copying CTF writer variant field type's: addr=%p", ft
);
5298 if (var_ft
->tag_ft
) {
5299 BT_LOGD_STR("Copying CTF writer variant field type's tag field type.");
5300 tag_ft_copy
= bt_ctf_field_type_common_copy(
5301 BT_CTF_TO_COMMON(var_ft
->tag_ft
));
5303 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field type.");
5308 copy_ft
= (void *) bt_ctf_field_type_variant_create(
5309 (void *) tag_ft_copy
,
5310 var_ft
->tag_name
->len
? var_ft
->tag_name
->str
: NULL
);
5312 BT_LOGE_STR("Cannot create CTF writer variant field type.");
5316 /* Copy field_name_to_index */
5317 g_hash_table_iter_init(&iter
, var_ft
->choice_name_to_index
);
5318 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
5319 g_hash_table_insert(copy_ft
->choice_name_to_index
,
5323 g_array_set_size(copy_ft
->choices
, var_ft
->choices
->len
);
5325 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
5326 struct bt_ctf_field_type_common_variant_choice
*entry
, *copy_entry
;
5327 struct bt_ctf_field_type_common
*field_ft_copy
;
5330 entry
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
, i
);
5331 copy_entry
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
5333 BT_LOGD("Copying CTF writer variant field type's field: "
5334 "index=%" PRId64
", "
5335 "field-ft-addr=%p, field-name=\"%s\"",
5336 i
, entry
, g_quark_to_string(entry
->name
));
5338 field_ft_copy
= (void *) bt_ctf_field_type_copy(
5339 (void *) entry
->type
);
5340 if (!field_ft_copy
) {
5341 BT_LOGE("Cannot copy CTF writer variant field type's field: "
5342 "index=%" PRId64
", "
5343 "field-ft-addr=%p, field-name=\"%s\"",
5344 i
, entry
, g_quark_to_string(entry
->name
));
5349 copy_entry
->name
= entry
->name
;
5350 copy_entry
->type
= field_ft_copy
;
5353 copy_entry
->ranges
= g_array_new(FALSE
, TRUE
,
5354 sizeof(struct bt_ctf_field_type_common_variant_choice_range
));
5355 BT_ASSERT_DBG(copy_entry
->ranges
);
5356 g_array_set_size(copy_entry
->ranges
, entry
->ranges
->len
);
5358 for (range_i
= 0; range_i
< entry
->ranges
->len
; range_i
++) {
5359 copy_entry
->ranges
[range_i
] = entry
->ranges
[range_i
];
5363 if (var_ft
->tag_field_path
) {
5364 BT_LOGD_STR("Copying CTF writer variant field type's tag field path.");
5365 copy_ft
->tag_field_path
= bt_ctf_field_path_copy(
5366 var_ft
->tag_field_path
);
5367 if (!copy_ft
->tag_field_path
) {
5368 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field path.");
5373 copy_ft
->choices_up_to_date
= var_ft
->choices_up_to_date
;
5374 BT_LOGD("Copied CTF writer variant field type: original-ft-addr=%p, copy-ft-addr=%p",
5378 bt_ctf_object_put_ref(tag_ft_copy
);
5379 return (void *) copy_ft
;
5382 bt_ctf_object_put_ref(tag_ft_copy
);
5383 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5388 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy_recursive(
5389 struct bt_ctf_field_type
*ft
)
5391 struct bt_ctf_field_type_common
*container_ft_copy
= NULL
;
5392 struct bt_ctf_field_type_common_array
*array_ft
= (void *) ft
;
5393 struct bt_ctf_field_type_common_array
*copy_ft
= NULL
;
5395 BT_LOGD("Copying CTF writer array field type's: addr=%p", ft
);
5396 BT_LOGD_STR("Copying CTF writer array field type's element field type.");
5397 container_ft_copy
= bt_ctf_field_type_common_copy(array_ft
->element_ft
);
5398 if (!container_ft_copy
) {
5399 BT_LOGE_STR("Cannot copy CTF writer array field type's element field type.");
5403 copy_ft
= (void *) bt_ctf_field_type_array_create(
5404 (void *) container_ft_copy
, array_ft
->length
);
5406 BT_LOGE_STR("Cannot create CTF writer array field type.");
5410 BT_LOGD("Copied CTF writer array field type: original-ft-addr=%p, copy-ft-addr=%p",
5414 bt_ctf_object_put_ref(container_ft_copy
);
5415 return (void *) copy_ft
;
5419 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy_recursive(
5420 struct bt_ctf_field_type
*ft
)
5422 struct bt_ctf_field_type_common
*container_ft_copy
= NULL
;
5423 struct bt_ctf_field_type_common_sequence
*seq_ft
= (void *) ft
;
5424 struct bt_ctf_field_type_common_sequence
*copy_ft
= NULL
;
5426 BT_LOGD("Copying CTF writer sequence field type's: addr=%p", ft
);
5427 BT_LOGD_STR("Copying CTF writer sequence field type's element field type.");
5428 container_ft_copy
= bt_ctf_field_type_common_copy(seq_ft
->element_ft
);
5429 if (!container_ft_copy
) {
5430 BT_LOGE_STR("Cannot copy CTF writer sequence field type's element field type.");
5434 copy_ft
= (void *) bt_ctf_field_type_sequence_create(
5435 (void *) container_ft_copy
,
5436 seq_ft
->length_field_name
->len
?
5437 seq_ft
->length_field_name
->str
: NULL
);
5439 BT_LOGE_STR("Cannot create CTF writer sequence field type.");
5443 if (seq_ft
->length_field_path
) {
5444 BT_LOGD_STR("Copying CTF writer sequence field type's length field path.");
5445 copy_ft
->length_field_path
= bt_ctf_field_path_copy(
5446 seq_ft
->length_field_path
);
5447 if (!copy_ft
->length_field_path
) {
5448 BT_LOGE_STR("Cannot copy CTF writer sequence field type's length field path.");
5453 BT_LOGD("Copied CTF writer sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
5457 bt_ctf_object_put_ref(container_ft_copy
);
5458 return (void *) copy_ft
;
5460 bt_ctf_object_put_ref(container_ft_copy
);
5461 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5466 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(struct bt_ctf_field_type
*ft
)
5468 struct bt_ctf_field_type_common_string
*string_ft
= (void *) ft
;
5469 struct bt_ctf_field_type_common_string
*copy_ft
= NULL
;
5471 BT_LOGD("Copying CTF writer string field type's: addr=%p", ft
);
5472 copy_ft
= (void *) bt_ctf_field_type_string_create();
5474 BT_LOGE_STR("Cannot create CTF writer string field type.");
5478 copy_ft
->encoding
= string_ft
->encoding
;
5479 BT_LOGD("Copied CTF writer string field type: original-ft-addr=%p, copy-ft-addr=%p",
5483 return (void *) copy_ft
;