4 * Babeltrace CTF IR - Event Types
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define BT_LOG_TAG "FIELD-TYPES"
30 #include <babeltrace/lib-logging-internal.h>
32 #include <babeltrace/assert-pre-internal.h>
33 #include <babeltrace/ctf-ir/field-types-internal.h>
34 #include <babeltrace/ctf-ir/field-path-internal.h>
35 #include <babeltrace/ctf-ir/fields-internal.h>
36 #include <babeltrace/ctf-ir/fields.h>
37 #include <babeltrace/ctf-ir/utils.h>
38 #include <babeltrace/ctf-ir/utils-internal.h>
39 #include <babeltrace/ref.h>
40 #include <babeltrace/ctf-ir/clock-class.h>
41 #include <babeltrace/ctf-ir/clock-class-internal.h>
42 #include <babeltrace/object-internal.h>
43 #include <babeltrace/ref.h>
44 #include <babeltrace/compiler-internal.h>
45 #include <babeltrace/endian-internal.h>
46 #include <babeltrace/assert-internal.h>
52 struct bt_field_type
*bt_field_type_integer_copy(
53 struct bt_field_type
*ft
);
56 struct bt_field_type
*bt_field_type_enumeration_copy_recursive(
57 struct bt_field_type
*ft
);
60 struct bt_field_type
*bt_field_type_floating_point_copy(
61 struct bt_field_type
*ft
);
64 struct bt_field_type
*bt_field_type_structure_copy_recursive(
65 struct bt_field_type
*ft
);
68 struct bt_field_type
*bt_field_type_variant_copy_recursive(
69 struct bt_field_type
*ft
);
72 struct bt_field_type
*bt_field_type_array_copy_recursive(
73 struct bt_field_type
*ft
);
76 struct bt_field_type
*bt_field_type_sequence_copy_recursive(
77 struct bt_field_type
*type
);
80 struct bt_field_type
*bt_field_type_string_copy(struct bt_field_type
*ft
);
82 static struct bt_field_type_common_methods bt_field_type_integer_methods
= {
83 .freeze
= bt_field_type_common_generic_freeze
,
84 .validate
= bt_field_type_common_integer_validate
,
85 .set_byte_order
= bt_field_type_common_integer_set_byte_order
,
86 .copy
= (bt_field_type_common_method_copy
)
87 bt_field_type_integer_copy
,
88 .compare
= bt_field_type_common_integer_compare
,
91 static struct bt_field_type_common_methods bt_field_type_floating_point_methods
= {
92 .freeze
= bt_field_type_common_generic_freeze
,
94 .set_byte_order
= bt_field_type_common_floating_point_set_byte_order
,
95 .copy
= (bt_field_type_common_method_copy
)
96 bt_field_type_floating_point_copy
,
97 .compare
= bt_field_type_common_floating_point_compare
,
100 static struct bt_field_type_common_methods bt_field_type_enumeration_methods
= {
101 .freeze
= bt_field_type_common_enumeration_freeze_recursive
,
102 .validate
= bt_field_type_common_enumeration_validate_recursive
,
103 .set_byte_order
= bt_field_type_common_enumeration_set_byte_order_recursive
,
104 .copy
= (bt_field_type_common_method_copy
)
105 bt_field_type_enumeration_copy_recursive
,
106 .compare
= bt_field_type_common_enumeration_compare_recursive
,
109 static struct bt_field_type_common_methods bt_field_type_string_methods
= {
110 .freeze
= bt_field_type_common_generic_freeze
,
112 .set_byte_order
= NULL
,
113 .copy
= (bt_field_type_common_method_copy
)
114 bt_field_type_string_copy
,
115 .compare
= bt_field_type_common_string_compare
,
118 static struct bt_field_type_common_methods bt_field_type_array_methods
= {
119 .freeze
= bt_field_type_common_array_freeze_recursive
,
120 .validate
= bt_field_type_common_array_validate_recursive
,
121 .set_byte_order
= bt_field_type_common_array_set_byte_order_recursive
,
122 .copy
= (bt_field_type_common_method_copy
)
123 bt_field_type_array_copy_recursive
,
124 .compare
= bt_field_type_common_array_compare_recursive
,
127 static struct bt_field_type_common_methods bt_field_type_sequence_methods
= {
128 .freeze
= bt_field_type_common_sequence_freeze_recursive
,
129 .validate
= bt_field_type_common_sequence_validate_recursive
,
130 .set_byte_order
= bt_field_type_common_sequence_set_byte_order_recursive
,
131 .copy
= (bt_field_type_common_method_copy
)
132 bt_field_type_sequence_copy_recursive
,
133 .compare
= bt_field_type_common_sequence_compare_recursive
,
136 static struct bt_field_type_common_methods bt_field_type_structure_methods
= {
137 .freeze
= bt_field_type_common_structure_freeze_recursive
,
138 .validate
= bt_field_type_common_structure_validate_recursive
,
139 .set_byte_order
= bt_field_type_common_structure_set_byte_order_recursive
,
140 .copy
= (bt_field_type_common_method_copy
)
141 bt_field_type_structure_copy_recursive
,
142 .compare
= bt_field_type_common_structure_compare_recursive
,
145 static struct bt_field_type_common_methods bt_field_type_variant_methods
= {
146 .freeze
= bt_field_type_common_variant_freeze_recursive
,
147 .validate
= bt_field_type_common_variant_validate_recursive
,
148 .set_byte_order
= bt_field_type_common_variant_set_byte_order_recursive
,
149 .copy
= (bt_field_type_common_method_copy
)
150 bt_field_type_variant_copy_recursive
,
151 .compare
= bt_field_type_common_variant_compare_recursive
,
155 void destroy_enumeration_mapping(struct enumeration_mapping
*mapping
)
161 void destroy_structure_field_common(struct structure_field_common
*field
)
167 BT_LOGD("Destroying structure/variant field type's field object: "
168 "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
169 field
, field
->type
, g_quark_to_string(field
->name
));
170 BT_LOGD_STR("Putting field type.");
176 void bt_field_type_common_initialize(struct bt_field_type_common
*ft
,
177 bool init_bo
, bt_object_release_func release_func
,
178 struct bt_field_type_common_methods
*methods
)
180 BT_ASSERT(ft
&& (ft
->id
> BT_FIELD_TYPE_ID_UNKNOWN
) &&
181 (ft
->id
< BT_FIELD_TYPE_ID_NR
));
183 bt_object_init(ft
, release_func
);
184 ft
->methods
= methods
;
188 const enum bt_byte_order bo
= BT_BYTE_ORDER_NATIVE
;
190 BT_LOGD("Setting initial field type's byte order: bo=%s",
191 bt_common_byte_order_string(bo
));
192 ret
= bt_field_type_common_set_byte_order(ft
, bo
);
200 void bt_field_type_common_integer_initialize(
201 struct bt_field_type_common
*ft
,
202 unsigned int size
, bt_object_release_func release_func
,
203 struct bt_field_type_common_methods
*methods
)
205 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
208 BT_LOGD("Initializing common integer field type object: size=%u",
210 ft
->id
= BT_FIELD_TYPE_ID_INTEGER
;
212 int_ft
->base
= BT_INTEGER_BASE_DECIMAL
;
213 int_ft
->encoding
= BT_STRING_ENCODING_NONE
;
214 bt_field_type_common_initialize(ft
, true, release_func
, methods
);
215 BT_LOGD("Initialized common integer field type object: addr=%p, size=%u",
220 void bt_field_type_common_floating_point_initialize(
221 struct bt_field_type_common
*ft
,
222 bt_object_release_func release_func
,
223 struct bt_field_type_common_methods
*methods
)
225 struct bt_field_type_common_floating_point
*flt_ft
= BT_FROM_COMMON(ft
);
227 BT_LOGD_STR("Initializing common floating point number field type object.");
228 ft
->id
= BT_FIELD_TYPE_ID_FLOAT
;
229 flt_ft
->exp_dig
= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
;
230 flt_ft
->mant_dig
= FLT_MANT_DIG
;
231 bt_field_type_common_initialize(ft
, true, release_func
, methods
);
232 BT_LOGD("Initialized common floating point number field type object: addr=%p, "
233 "exp-size=%u, mant-size=%u", ft
, flt_ft
->exp_dig
,
238 void bt_field_type_common_enumeration_initialize(
239 struct bt_field_type_common
*ft
,
240 struct bt_field_type_common
*container_ft
,
241 bt_object_release_func release_func
,
242 struct bt_field_type_common_methods
*methods
)
244 struct bt_field_type_common_enumeration
*enum_ft
= BT_FROM_COMMON(ft
);
246 BT_ASSERT(container_ft
);
247 BT_LOGD("Initializing common enumeration field type object: int-ft-addr=%p",
249 ft
->id
= BT_FIELD_TYPE_ID_ENUM
;
250 enum_ft
->container_ft
= bt_get(container_ft
);
251 enum_ft
->entries
= g_ptr_array_new_with_free_func(
252 (GDestroyNotify
) destroy_enumeration_mapping
);
253 bt_field_type_common_initialize(ft
, false, release_func
, methods
);
254 BT_LOGD("Initialized common enumeration field type object: addr=%p, "
255 "int-ft-addr=%p, int-ft-size=%u", ft
, container_ft
,
256 bt_field_type_common_integer_get_size(container_ft
));
260 void bt_field_type_common_string_initialize(
261 struct bt_field_type_common
*ft
,
262 bt_object_release_func release_func
,
263 struct bt_field_type_common_methods
*methods
)
265 struct bt_field_type_common_string
*string_ft
= BT_FROM_COMMON(ft
);
267 BT_LOGD_STR("Initializing common string field type object.");
268 ft
->id
= BT_FIELD_TYPE_ID_STRING
;
269 bt_field_type_common_initialize(ft
, true, release_func
, methods
);
270 string_ft
->encoding
= BT_STRING_ENCODING_UTF8
;
271 ft
->alignment
= CHAR_BIT
;
272 BT_LOGD("Initialized common string field type object: addr=%p", ft
);
276 void bt_field_type_common_structure_initialize(
277 struct bt_field_type_common
*ft
,
278 bt_object_release_func release_func
,
279 struct bt_field_type_common_methods
*methods
)
281 struct bt_field_type_common_structure
*struct_ft
= BT_FROM_COMMON(ft
);
283 BT_LOGD_STR("Initializing common structure field type object.");
284 ft
->id
= BT_FIELD_TYPE_ID_STRUCT
;
285 struct_ft
->fields
= g_ptr_array_new_with_free_func(
286 (GDestroyNotify
) destroy_structure_field_common
);
287 struct_ft
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
288 bt_field_type_common_initialize(ft
, true, release_func
, methods
);
289 BT_LOGD("Initialized common structure field type object: addr=%p", ft
);
293 void bt_field_type_common_array_initialize(
294 struct bt_field_type_common
*ft
,
295 struct bt_field_type_common
*element_ft
,
296 unsigned int length
, bt_object_release_func release_func
,
297 struct bt_field_type_common_methods
*methods
)
299 struct bt_field_type_common_array
*array_ft
= BT_FROM_COMMON(ft
);
301 BT_ASSERT(element_ft
);
302 BT_LOGD("Initializing common array field type object: element-ft-addr=%p, "
303 "length=%u", element_ft
, length
);
304 ft
->id
= BT_FIELD_TYPE_ID_ARRAY
;
305 array_ft
->element_ft
= bt_get(element_ft
);
306 array_ft
->length
= length
;
307 bt_field_type_common_initialize(ft
, false, release_func
, methods
);
308 BT_LOGD("Initialized common array field type object: addr=%p, "
309 "element-ft-addr=%p, length=%u", ft
, element_ft
, length
);
313 void bt_field_type_common_sequence_initialize(
314 struct bt_field_type_common
*ft
,
315 struct bt_field_type_common
*element_ft
,
316 const char *length_field_name
,
317 bt_object_release_func release_func
,
318 struct bt_field_type_common_methods
*methods
)
320 struct bt_field_type_common_sequence
*seq_ft
= BT_FROM_COMMON(ft
);
322 BT_ASSERT(element_ft
);
323 BT_ASSERT(length_field_name
);
324 BT_ASSERT(bt_identifier_is_valid(length_field_name
));
325 BT_LOGD("Initializing common sequence field type object: element-ft-addr=%p, "
326 "length-field-name=\"%s\"", element_ft
, length_field_name
);
327 ft
->id
= BT_FIELD_TYPE_ID_SEQUENCE
;
328 seq_ft
->element_ft
= bt_get(element_ft
);
329 seq_ft
->length_field_name
= g_string_new(length_field_name
);
330 bt_field_type_common_initialize(ft
, false, release_func
, methods
);
331 BT_LOGD("Initialized common sequence field type object: addr=%p, "
332 "element-ft-addr=%p, length-field-name=\"%s\"",
333 ft
, element_ft
, length_field_name
);
337 void bt_field_type_common_variant_initialize(
338 struct bt_field_type_common
*ft
,
339 struct bt_field_type_common
*tag_ft
,
340 const char *tag_name
,
341 bt_object_release_func release_func
,
342 struct bt_field_type_common_methods
*methods
)
344 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
346 BT_ASSERT(!tag_name
|| bt_identifier_is_valid(tag_name
));
347 BT_LOGD("Initializing common variant field type object: "
348 "tag-ft-addr=%p, tag-field-name=\"%s\"",
350 ft
->id
= BT_FIELD_TYPE_ID_VARIANT
;
351 var_ft
->tag_name
= g_string_new(tag_name
);
352 var_ft
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
353 var_ft
->fields
= g_ptr_array_new_with_free_func(
354 (GDestroyNotify
) destroy_structure_field_common
);
357 var_ft
->tag_ft
= bt_get(tag_ft
);
360 bt_field_type_common_initialize(ft
, true, release_func
, methods
);
361 /* A variant's alignment is undefined */
363 BT_LOGD("Initialized common variant field type object: addr=%p, "
364 "tag-ft-addr=%p, tag-field-name=\"%s\"",
365 ft
, tag_ft
, tag_name
);
369 void bt_field_type_common_integer_destroy(struct bt_object
*obj
)
371 struct bt_field_type_common_integer
*ft
= (void *) obj
;
377 BT_LOGD("Destroying integer field type object: addr=%p", ft
);
378 BT_LOGD_STR("Putting mapped clock class.");
379 bt_put(ft
->mapped_clock_class
);
384 void bt_field_type_common_floating_point_destroy(struct bt_object
*obj
)
386 struct bt_field_type_common_floating_point
*ft
= (void *) obj
;
392 BT_LOGD("Destroying floating point number field type object: addr=%p", ft
);
397 void bt_field_type_common_enumeration_destroy_recursive(struct bt_object
*obj
)
399 struct bt_field_type_common_enumeration
*ft
= (void *) obj
;
405 BT_LOGD("Destroying enumeration field type object: addr=%p", ft
);
406 g_ptr_array_free(ft
->entries
, TRUE
);
407 BT_LOGD_STR("Putting container field type.");
408 bt_put(ft
->container_ft
);
413 void bt_field_type_common_string_destroy(struct bt_object
*obj
)
415 struct bt_field_type_common_string
*ft
= (void *) obj
;
421 BT_LOGD("Destroying string field type object: addr=%p", ft
);
427 void bt_field_type_common_structure_destroy_recursive(struct bt_object
*obj
)
429 struct bt_field_type_common_structure
*ft
= (void *) obj
;
435 BT_LOGD("Destroying structure field type object: addr=%p", ft
);
436 g_ptr_array_free(ft
->fields
, TRUE
);
437 g_hash_table_destroy(ft
->field_name_to_index
);
442 void bt_field_type_common_array_destroy_recursive(struct bt_object
*obj
)
444 struct bt_field_type_common_array
*ft
= (void *) obj
;
450 BT_LOGD("Destroying array field type object: addr=%p", ft
);
451 BT_LOGD_STR("Putting element field type.");
452 bt_put(ft
->element_ft
);
457 void bt_field_type_common_sequence_destroy_recursive(struct bt_object
*obj
)
459 struct bt_field_type_common_sequence
*ft
= (void *) obj
;
465 BT_LOGD("Destroying sequence field type object: addr=%p", ft
);
466 BT_LOGD_STR("Putting element field type.");
467 bt_put(ft
->element_ft
);
468 g_string_free(ft
->length_field_name
, TRUE
);
469 BT_LOGD_STR("Putting length field path.");
470 bt_put(ft
->length_field_path
);
475 void bt_field_type_common_variant_destroy_recursive(struct bt_object
*obj
)
477 struct bt_field_type_common_variant
*ft
= (void *) obj
;
483 BT_LOGD("Destroying variant field type object: addr=%p", ft
);
484 g_ptr_array_free(ft
->fields
, TRUE
);
485 g_hash_table_destroy(ft
->field_name_to_index
);
486 g_string_free(ft
->tag_name
, TRUE
);
487 BT_LOGD_STR("Putting tag field type.");
489 BT_LOGD_STR("Putting tag field path.");
490 bt_put(ft
->tag_field_path
);
494 struct range_overlap_query
{
509 void check_ranges_overlap(gpointer element
, gpointer query
)
511 struct enumeration_mapping
*mapping
= element
;
512 struct range_overlap_query
*overlap_query
= query
;
514 if (mapping
->range_start
._signed
<= overlap_query
->range_end
._signed
515 && overlap_query
->range_start
._signed
<=
516 mapping
->range_end
._signed
) {
517 overlap_query
->overlaps
= 1;
518 overlap_query
->mapping_name
= mapping
->string
;
521 overlap_query
->overlaps
|=
522 mapping
->string
== overlap_query
->mapping_name
;
524 if (overlap_query
->overlaps
) {
525 BT_LOGV("Overlapping enumeration field type mappings: "
526 "mapping-name=\"%s\", "
527 "mapping-a-range-start=%" PRId64
", "
528 "mapping-a-range-end=%" PRId64
", "
529 "mapping-b-range-start=%" PRId64
", "
530 "mapping-b-range-end=%" PRId64
,
531 g_quark_to_string(mapping
->string
),
532 mapping
->range_start
._signed
,
533 mapping
->range_end
._signed
,
534 overlap_query
->range_start
._signed
,
535 overlap_query
->range_end
._signed
);
540 void check_ranges_overlap_unsigned(gpointer element
, gpointer query
)
542 struct enumeration_mapping
*mapping
= element
;
543 struct range_overlap_query
*overlap_query
= query
;
545 if (mapping
->range_start
._unsigned
<= overlap_query
->range_end
._unsigned
546 && overlap_query
->range_start
._unsigned
<=
547 mapping
->range_end
._unsigned
) {
548 overlap_query
->overlaps
= 1;
549 overlap_query
->mapping_name
= mapping
->string
;
552 overlap_query
->overlaps
|=
553 mapping
->string
== overlap_query
->mapping_name
;
555 if (overlap_query
->overlaps
) {
556 BT_LOGW("Overlapping enumeration field type mappings: "
557 "mapping-name=\"%s\", "
558 "mapping-a-range-start=%" PRIu64
", "
559 "mapping-a-range-end=%" PRIu64
", "
560 "mapping-b-range-start=%" PRIu64
", "
561 "mapping-b-range-end=%" PRIu64
,
562 g_quark_to_string(mapping
->string
),
563 mapping
->range_start
._unsigned
,
564 mapping
->range_end
._unsigned
,
565 overlap_query
->range_start
._unsigned
,
566 overlap_query
->range_end
._unsigned
);
571 gint
compare_enumeration_mappings_signed(struct enumeration_mapping
**a
,
572 struct enumeration_mapping
**b
)
574 return ((*a
)->range_start
._signed
< (*b
)->range_start
._signed
) ? -1 : 1;
578 gint
compare_enumeration_mappings_unsigned(struct enumeration_mapping
**a
,
579 struct enumeration_mapping
**b
)
581 return ((*a
)->range_start
._unsigned
< (*b
)->range_start
._unsigned
) ? -1 : 1;
585 int add_structure_field(GPtrArray
*fields
,
586 GHashTable
*field_name_to_index
,
587 struct bt_field_type_common
*field_type
, const char *field_name
)
590 GQuark name_quark
= g_quark_from_string(field_name
);
591 struct structure_field_common
*field
;
593 /* Make sure structure does not contain a field of the same name */
594 if (g_hash_table_lookup_extended(field_name_to_index
,
595 GUINT_TO_POINTER(name_quark
), NULL
, NULL
)) {
596 BT_LOGW("Structure or variant field type already contains a field type with this name: "
597 "field-name=\"%s\"", field_name
);
602 field
= g_new0(struct structure_field_common
, 1);
604 BT_LOGE_STR("Failed to allocate one structure/variant field type field.");
610 field
->name
= name_quark
;
611 field
->type
= field_type
;
612 g_hash_table_insert(field_name_to_index
,
613 GUINT_TO_POINTER(name_quark
), GUINT_TO_POINTER(fields
->len
));
614 g_ptr_array_add(fields
, field
);
615 BT_LOGV("Added structure/variant field type field: field-ft-addr=%p, "
616 "field-name=\"%s\"", field_type
, field_name
);
622 int bt_field_type_common_integer_validate(struct bt_field_type_common
*ft
)
625 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
627 if (int_ft
->mapped_clock_class
&& int_ft
->is_signed
) {
628 BT_LOGW("Invalid integer field type: cannot be signed and have a mapped clock class: "
629 "ft-addr=%p, clock-class-addr=%p, clock-class-name=\"%s\"",
630 ft
, int_ft
->mapped_clock_class
,
631 bt_clock_class_get_name(int_ft
->mapped_clock_class
));
641 struct enumeration_mapping
*bt_field_type_common_enumeration_get_mapping_by_index(
642 struct bt_field_type_common
*ft
, uint64_t index
)
644 struct bt_field_type_common_enumeration
*enum_ft
= BT_FROM_COMMON(ft
);
645 struct 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
);
661 * Note: This algorithm is O(n^2) vs number of enumeration mappings.
662 * Only used when freezing an enumeration.
665 void bt_field_type_common_enumeration_set_range_overlap(
666 struct bt_field_type_common_enumeration
*ft
)
671 BT_LOGV("Setting enumeration field type's overlap flag: addr=%p",
673 len
= ft
->entries
->len
;
674 is_signed
= bt_field_type_common_integer_is_signed(
675 BT_TO_COMMON(ft
->container_ft
));
677 for (i
= 0; i
< len
; i
++) {
678 for (j
= i
+ 1; j
< len
; j
++) {
679 struct enumeration_mapping
*mapping
[2];
681 mapping
[0] = bt_field_type_common_enumeration_get_mapping_by_index(
682 BT_TO_COMMON(ft
), i
);
683 mapping
[1] = bt_field_type_common_enumeration_get_mapping_by_index(
684 BT_TO_COMMON(ft
), j
);
686 if (mapping
[0]->range_start
._signed
687 <= mapping
[1]->range_end
._signed
688 && mapping
[0]->range_end
._signed
689 >= mapping
[1]->range_start
._signed
) {
690 ft
->has_overlapping_ranges
= BT_TRUE
;
694 if (mapping
[0]->range_start
._unsigned
695 <= mapping
[1]->range_end
._unsigned
696 && mapping
[0]->range_end
._unsigned
697 >= mapping
[1]->range_start
._unsigned
) {
698 ft
->has_overlapping_ranges
= BT_TRUE
;
706 if (ft
->has_overlapping_ranges
) {
707 BT_LOGV_STR("Enumeration field type has overlapping ranges.");
709 BT_LOGV_STR("Enumeration field type has no overlapping ranges.");
714 int bt_field_type_common_enumeration_validate_recursive(
715 struct bt_field_type_common
*ft
)
718 struct bt_field_type_common_enumeration
*enum_ft
= BT_FROM_COMMON(ft
);
720 ret
= bt_field_type_common_integer_validate(
721 BT_TO_COMMON(enum_ft
->container_ft
));
723 BT_LOGW("Invalid enumeration field type: container type is invalid: "
724 "enum-ft-addr=%p, int-ft-addr=%p",
725 ft
, enum_ft
->container_ft
);
729 /* Ensure enum has entries */
730 if (enum_ft
->entries
->len
== 0) {
731 BT_LOGW("Invalid enumeration field type: no entries: "
742 int bt_field_type_common_sequence_validate_recursive(
743 struct bt_field_type_common
*ft
)
746 struct bt_field_type_common_sequence
*seq_ft
= BT_FROM_COMMON(ft
);
748 /* Length field name should be set at this point */
749 if (seq_ft
->length_field_name
->len
== 0) {
750 BT_LOGW("Invalid sequence field type: no length field name: "
756 ret
= bt_field_type_common_validate(seq_ft
->element_ft
);
758 BT_LOGW("Invalid sequence field type: invalid element field type: "
759 "seq-ft-addr=%p, element-ft-add=%p",
760 ft
, seq_ft
->element_ft
);
768 int bt_field_type_common_array_validate_recursive(
769 struct bt_field_type_common
*ft
)
772 struct bt_field_type_common_array
*array_ft
= BT_FROM_COMMON(ft
);
774 ret
= bt_field_type_common_validate(array_ft
->element_ft
);
776 BT_LOGW("Invalid array field type: invalid element field type: "
777 "array-ft-addr=%p, element-ft-add=%p",
778 ft
, array_ft
->element_ft
);
785 int bt_field_type_common_structure_validate_recursive(
786 struct bt_field_type_common
*ft
)
789 struct bt_field_type_common
*child_ft
= NULL
;
790 int64_t field_count
=
791 bt_field_type_common_structure_get_field_count(ft
);
794 BT_ASSERT(field_count
>= 0);
796 for (i
= 0; i
< field_count
; ++i
) {
797 const char *field_name
;
799 ret
= bt_field_type_common_structure_borrow_field_by_index(ft
,
800 &field_name
, &child_ft
, i
);
802 ret
= bt_field_type_common_validate(child_ft
);
804 BT_LOGW("Invalid structure field type: "
805 "a contained field type is invalid: "
806 "struct-ft-addr=%p, field-ft-addr=%p, "
807 "field-name=\"%s\", field-index=%" PRId64
,
808 ft
, child_ft
, field_name
, i
);
818 bt_bool
bt_field_type_common_enumeration_has_overlapping_ranges(
819 struct bt_field_type_common_enumeration
*enum_ft
)
821 if (!enum_ft
->common
.frozen
) {
822 bt_field_type_common_enumeration_set_range_overlap(enum_ft
);
825 return enum_ft
->has_overlapping_ranges
;
829 int bt_field_type_common_variant_validate_recursive(
830 struct bt_field_type_common
*ft
)
834 struct bt_field_type_common
*child_ft
= NULL
;
835 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
838 if (var_ft
->tag_name
->len
== 0) {
839 BT_LOGW("Invalid variant field type: no tag field name: "
845 if (!var_ft
->tag_ft
) {
846 BT_LOGW("Invalid variant field type: no tag field type: "
847 "addr=%p, tag-field-name=\"%s\"", var_ft
,
848 var_ft
->tag_name
->str
);
853 if (bt_field_type_common_enumeration_has_overlapping_ranges(var_ft
->tag_ft
)) {
854 BT_LOGW("Invalid variant field type: enumeration tag field type has overlapping ranges: "
855 "variant-ft-addr=%p, tag-field-name=\"%s\", "
856 "enum-ft-addr=%p", ft
, var_ft
->tag_name
->str
,
863 * It is valid to have a variant field type which does not have
864 * the fields corresponding to each label in the associated
867 * It is also valid to have variant field type fields which
868 * cannot be selected because the variant field type tag has no
869 * mapping named as such. This scenario, while not ideal, cannot
872 * If a non-existing field happens to be selected by an
873 * enumeration while reading a variant field, an error will be
874 * generated at that point (while reading the stream).
876 field_count
= bt_field_type_common_variant_get_field_count(ft
);
877 if (field_count
< 0) {
878 BT_LOGW("Invalid variant field type: no fields: "
879 "addr=%p, tag-field-name=\"%s\"",
880 ft
, var_ft
->tag_name
->str
);
885 for (i
= 0; i
< field_count
; ++i
) {
886 const char *field_name
;
888 ret
= bt_field_type_common_variant_borrow_field_by_index(ft
,
889 &field_name
, &child_ft
, i
);
891 ret
= bt_field_type_common_validate(child_ft
);
893 BT_LOGW("Invalid variant field type: "
894 "a contained field type is invalid: "
895 "variant-ft-addr=%p, tag-field-name=\"%s\", "
896 "field-ft-addr=%p, field-name=\"%s\", "
897 "field-index=%" PRId64
,
898 ft
, var_ft
->tag_name
->str
, child_ft
,
909 * This function validates a given field type without considering
910 * where this field type is located. It only validates the properties
911 * of the given field type and the properties of its children if
915 int bt_field_type_common_validate(struct bt_field_type_common
*ft
)
922 /* Already marked as valid */
926 if (ft
->methods
->validate
) {
927 ret
= ft
->methods
->validate(ft
);
930 if (ret
== 0 && ft
->frozen
) {
931 /* Field type is valid */
932 BT_LOGV("Marking field type as valid: addr=%p", ft
);
940 struct bt_field_type
*bt_field_type_integer_create(unsigned int size
)
942 struct bt_field_type_common_integer
*integer
= NULL
;
944 BT_LOGD("Creating integer field type object: size=%u", size
);
946 if (size
== 0 || size
> 64) {
947 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
952 integer
= g_new0(struct bt_field_type_common_integer
, 1);
954 BT_LOGE_STR("Failed to allocate one integer field type.");
958 bt_field_type_common_integer_initialize(BT_TO_COMMON(integer
),
959 size
, bt_field_type_common_integer_destroy
,
960 &bt_field_type_integer_methods
);
961 BT_LOGD("Created integer field type object: addr=%p, size=%u",
969 return (void *) integer
;
973 int bt_field_type_common_integer_get_size(struct bt_field_type_common
*ft
)
975 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
977 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
978 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_INTEGER
,
980 return (int) int_ft
->size
;
983 int bt_field_type_integer_get_size(struct bt_field_type
*ft
)
985 return bt_field_type_common_integer_get_size((void *) ft
);
989 bt_bool
bt_field_type_common_integer_is_signed(struct bt_field_type_common
*ft
)
991 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
993 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
994 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_INTEGER
,
996 return int_ft
->is_signed
;
999 bt_bool
bt_field_type_integer_is_signed(struct bt_field_type
*ft
)
1001 return bt_field_type_common_integer_is_signed((void *) ft
);
1005 int bt_field_type_common_integer_set_is_signed(struct bt_field_type_common
*ft
,
1009 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
1012 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1018 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1024 if (ft
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
1025 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1026 "addr=%p, ft-id=%s", ft
,
1027 bt_common_field_type_id_string(ft
->id
));
1032 int_ft
->is_signed
= !!is_signed
;
1033 BT_LOGV("Set integer field type's signedness: addr=%p, is-signed=%d",
1040 int bt_field_type_integer_set_is_signed(struct bt_field_type
*ft
,
1043 return bt_field_type_common_integer_set_is_signed((void *) ft
,
1048 int bt_field_type_common_integer_set_size(struct bt_field_type_common
*ft
,
1052 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
1055 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1061 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1067 if (ft
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
1068 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1069 "addr=%p, ft-id=%s", ft
,
1070 bt_common_field_type_id_string(ft
->id
));
1075 if (size
== 0 || size
> 64) {
1076 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
1077 "addr=%p, size=%u", ft
, size
);
1082 int_ft
->size
= size
;
1083 BT_LOGV("Set integer field type's size: addr=%p, size=%u",
1090 int bt_field_type_integer_set_size(struct bt_field_type
*ft
,
1093 return bt_field_type_common_integer_set_size((void *) ft
, size
);
1097 enum bt_integer_base
bt_field_type_common_integer_get_base(
1098 struct bt_field_type_common
*ft
)
1100 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
1102 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1103 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_INTEGER
,
1105 return int_ft
->base
;
1108 enum bt_integer_base
bt_field_type_integer_get_base(
1109 struct bt_field_type
*ft
)
1111 return bt_field_type_common_integer_get_base((void *) ft
);
1115 int bt_field_type_common_integer_set_base(struct bt_field_type_common
*ft
,
1116 enum bt_integer_base base
)
1119 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
1122 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1128 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1134 if (ft
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
1135 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1136 "addr=%p, ft-id=%s", ft
,
1137 bt_common_field_type_id_string(ft
->id
));
1143 case BT_INTEGER_BASE_UNSPECIFIED
:
1144 case BT_INTEGER_BASE_BINARY
:
1145 case BT_INTEGER_BASE_OCTAL
:
1146 case BT_INTEGER_BASE_DECIMAL
:
1147 case BT_INTEGER_BASE_HEXADECIMAL
:
1149 int_ft
->base
= base
;
1153 BT_LOGW("Invalid parameter: unknown integer field type base: "
1154 "addr=%p, base=%d", ft
, base
);
1158 BT_LOGV("Set integer field type's base: addr=%p, base=%s",
1159 ft
, bt_common_integer_base_string(base
));
1165 int bt_field_type_integer_set_base(struct bt_field_type
*ft
,
1166 enum bt_integer_base base
)
1168 return bt_field_type_common_integer_set_base((void *) ft
, base
);
1172 enum bt_string_encoding
bt_field_type_common_integer_get_encoding(
1173 struct bt_field_type_common
*ft
)
1175 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
1177 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1178 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_INTEGER
,
1180 return int_ft
->encoding
;
1183 enum bt_string_encoding
bt_field_type_integer_get_encoding(
1184 struct bt_field_type
*ft
)
1186 return bt_field_type_common_integer_get_encoding((void *) ft
);
1190 int bt_field_type_common_integer_set_encoding(struct bt_field_type_common
*ft
,
1191 enum bt_string_encoding encoding
)
1194 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
1197 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1203 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1209 if (ft
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
1210 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1211 "addr=%p, ft-id=%s", ft
,
1212 bt_common_field_type_id_string(ft
->id
));
1217 if (encoding
!= BT_STRING_ENCODING_UTF8
&&
1218 encoding
!= BT_STRING_ENCODING_ASCII
&&
1219 encoding
!= BT_STRING_ENCODING_NONE
) {
1220 BT_LOGW("Invalid parameter: unknown string encoding: "
1221 "addr=%p, encoding=%d", ft
, encoding
);
1226 int_ft
->encoding
= encoding
;
1227 BT_LOGV("Set integer field type's encoding: addr=%p, encoding=%s",
1228 ft
, bt_common_string_encoding_string(encoding
));
1234 int bt_field_type_integer_set_encoding(struct bt_field_type
*ft
,
1235 enum bt_string_encoding encoding
)
1237 return bt_field_type_common_integer_set_encoding((void *) ft
, encoding
);
1241 struct bt_clock_class
*bt_field_type_common_integer_borrow_mapped_clock_class(
1242 struct bt_field_type_common
*ft
)
1244 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
1246 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1247 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_INTEGER
,
1249 return int_ft
->mapped_clock_class
;
1252 struct bt_clock_class
*bt_field_type_integer_borrow_mapped_clock_class(
1253 struct bt_field_type
*ft
)
1255 return bt_field_type_common_integer_borrow_mapped_clock_class(
1260 int bt_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
1261 struct bt_field_type_common
*ft
,
1262 struct bt_clock_class
*clock_class
)
1264 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
1268 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
1273 if (ft
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
1274 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1275 "addr=%p, ft-id=%s", ft
,
1276 bt_common_field_type_id_string(ft
->id
));
1280 if (!bt_clock_class_is_valid(clock_class
)) {
1281 BT_LOGW("Invalid parameter: clock class is invalid: ft-addr=%p"
1282 "clock-class-addr=%p, clock-class-name=\"%s\"",
1284 bt_clock_class_get_name(clock_class
));
1289 bt_put(int_ft
->mapped_clock_class
);
1290 int_ft
->mapped_clock_class
= bt_get(clock_class
);
1291 BT_LOGV("Set integer field type's mapped clock class: ft-addr=%p, "
1292 "clock-class-addr=%p, clock-class-name=\"%s\"",
1293 ft
, clock_class
, bt_clock_class_get_name(clock_class
));
1300 int bt_field_type_common_integer_set_mapped_clock_class(
1301 struct bt_field_type_common
*ft
,
1302 struct bt_clock_class
*clock_class
)
1307 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1313 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1319 ret
= bt_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
1326 int bt_field_type_integer_set_mapped_clock_class(struct bt_field_type
*ft
,
1327 struct bt_clock_class
*clock_class
)
1329 return bt_field_type_common_integer_set_mapped_clock_class((void *) ft
,
1334 void bt_field_type_enum_iter_destroy(struct bt_object
*obj
)
1336 struct bt_field_type_enumeration_mapping_iterator
*iter
=
1338 struct bt_field_type_enumeration_mapping_iterator
,
1341 BT_LOGD("Destroying enumeration field type mapping iterator: addr=%p",
1343 BT_LOGD_STR("Putting parent enumeration field type.");
1344 bt_put(iter
->enumeration_ft
);
1349 struct bt_field_type_enumeration_mapping_iterator
*
1350 bt_field_type_common_enumeration_find_mappings_type(
1351 struct bt_field_type_common
*ft
,
1352 enum bt_field_type_enumeration_mapping_iterator_type iterator_type
)
1354 struct bt_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1356 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1357 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_ENUM
,
1359 iter
= g_new0(struct bt_field_type_enumeration_mapping_iterator
, 1);
1361 BT_LOGE_STR("Failed to allocate one enumeration field type mapping.");
1365 bt_object_init(&iter
->base
, bt_field_type_enum_iter_destroy
);
1366 iter
->enumeration_ft
= bt_get(ft
);
1368 iter
->type
= iterator_type
;
1375 struct bt_field_type_enumeration_mapping_iterator
*
1376 bt_field_type_common_enumeration_find_mappings_by_name(
1377 struct bt_field_type_common
*ft
, const char *name
)
1379 struct bt_field_type_enumeration_mapping_iterator
*iter
;
1381 iter
= bt_field_type_common_enumeration_find_mappings_type(
1382 ft
, ITERATOR_BY_NAME
);
1384 BT_LOGW("Cannot create enumeration field type mapping iterator: "
1385 "ft-addr=%p, mapping-name=\"%s\"", ft
, name
);
1389 iter
->u
.name_quark
= g_quark_try_string(name
);
1390 if (!iter
->u
.name_quark
) {
1392 * No results are possible, set the iterator's position at the
1395 iter
->index
= iter
->enumeration_ft
->entries
->len
;
1405 struct bt_field_type_enumeration_mapping_iterator
*
1406 bt_field_type_enumeration_find_mappings_by_name(
1407 struct bt_field_type
*ft
, const char *name
)
1409 return bt_field_type_common_enumeration_find_mappings_by_name(
1413 int bt_field_type_enumeration_mapping_iterator_next(
1414 struct bt_field_type_enumeration_mapping_iterator
*iter
)
1416 struct bt_field_type_common_enumeration
*enum_ft
= iter
->enumeration_ft
;
1417 int i
, ret
= 0, len
;
1419 BT_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
1420 len
= enum_ft
->entries
->len
;
1421 for (i
= iter
->index
+ 1; i
< len
; i
++) {
1422 struct enumeration_mapping
*mapping
=
1423 bt_field_type_common_enumeration_get_mapping_by_index(
1424 BT_TO_COMMON(enum_ft
), i
);
1426 switch (iter
->type
) {
1427 case ITERATOR_BY_NAME
:
1428 if (mapping
->string
== iter
->u
.name_quark
) {
1433 case ITERATOR_BY_SIGNED_VALUE
:
1435 int64_t value
= iter
->u
.signed_value
;
1437 if (value
>= mapping
->range_start
._signed
&&
1438 value
<= mapping
->range_end
._signed
) {
1444 case ITERATOR_BY_UNSIGNED_VALUE
:
1446 uint64_t value
= iter
->u
.unsigned_value
;
1448 if (value
>= mapping
->range_start
._unsigned
&&
1449 value
<= mapping
->range_end
._unsigned
) {
1456 BT_LOGF("Invalid enumeration field type mapping iterator type: "
1457 "type=%d", iter
->type
);
1469 struct bt_field_type_enumeration_mapping_iterator
*
1470 bt_field_type_common_enumeration_signed_find_mappings_by_value(
1471 struct bt_field_type_common
*ft
, int64_t value
)
1473 struct bt_field_type_enumeration_mapping_iterator
*iter
;
1475 iter
= bt_field_type_common_enumeration_find_mappings_type(
1476 ft
, ITERATOR_BY_SIGNED_VALUE
);
1478 BT_LOGW("Cannot create enumeration field type mapping iterator: "
1479 "ft-addr=%p, value=%" PRId64
, ft
, value
);
1483 if (bt_field_type_common_integer_is_signed(
1484 BT_TO_COMMON(iter
->enumeration_ft
->container_ft
)) != 1) {
1485 BT_LOGW("Invalid parameter: enumeration field type is unsigned: "
1486 "enum-ft-addr=%p, int-ft-addr=%p",
1487 ft
, iter
->enumeration_ft
->container_ft
);
1491 iter
->u
.signed_value
= value
;
1499 struct bt_field_type_enumeration_mapping_iterator
*
1500 bt_field_type_enumeration_signed_find_mappings_by_value(
1501 struct bt_field_type
*ft
, int64_t value
)
1503 return bt_field_type_common_enumeration_signed_find_mappings_by_value(
1504 (void *) ft
, value
);
1508 struct bt_field_type_enumeration_mapping_iterator
*
1509 bt_field_type_common_enumeration_unsigned_find_mappings_by_value(
1510 struct bt_field_type_common
*ft
, uint64_t value
)
1512 struct bt_field_type_enumeration_mapping_iterator
*iter
;
1514 iter
= bt_field_type_common_enumeration_find_mappings_type(
1515 ft
, ITERATOR_BY_UNSIGNED_VALUE
);
1517 BT_LOGW("Cannot create enumeration field type mapping iterator: "
1518 "ft-addr=%p, value=%" PRIu64
, ft
, value
);
1522 if (bt_field_type_common_integer_is_signed(
1523 BT_TO_COMMON(iter
->enumeration_ft
->container_ft
)) != 0) {
1524 BT_LOGW("Invalid parameter: enumeration field type is signed: "
1525 "enum-ft-addr=%p, int-ft-addr=%p",
1526 ft
, iter
->enumeration_ft
->container_ft
);
1530 iter
->u
.unsigned_value
= value
;
1538 struct bt_field_type_enumeration_mapping_iterator
*
1539 bt_field_type_enumeration_unsigned_find_mappings_by_value(
1540 struct bt_field_type
*ft
, uint64_t value
)
1542 return bt_field_type_common_enumeration_unsigned_find_mappings_by_value(
1543 (void *) ft
, value
);
1546 int bt_field_type_enumeration_mapping_iterator_signed_get(
1547 struct bt_field_type_enumeration_mapping_iterator
*iter
,
1548 const char **mapping_name
, int64_t *range_begin
,
1551 BT_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
1552 BT_ASSERT_PRE(iter
->index
!= -1,
1553 "Invalid enumeration field type mapping iterator access: "
1554 "addr=%p, position=-1", iter
);
1555 return bt_field_type_common_enumeration_signed_get_mapping_by_index(
1556 (void *) iter
->enumeration_ft
, iter
->index
,
1557 mapping_name
, range_begin
, range_end
);
1560 int bt_field_type_enumeration_mapping_iterator_unsigned_get(
1561 struct bt_field_type_enumeration_mapping_iterator
*iter
,
1562 const char **mapping_name
, uint64_t *range_begin
,
1563 uint64_t *range_end
)
1565 BT_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
1566 BT_ASSERT_PRE(iter
->index
!= -1,
1567 "Invalid enumeration field type mapping iterator access: "
1568 "addr=%p, position=-1", iter
);
1569 return bt_field_type_common_enumeration_unsigned_get_mapping_by_index(
1570 (void *) iter
->enumeration_ft
, iter
->index
,
1571 mapping_name
, range_begin
, range_end
);
1575 int bt_field_type_common_enumeration_signed_get_mapping_by_index(
1576 struct bt_field_type_common
*ft
, uint64_t index
,
1577 const char **mapping_name
, int64_t *range_begin
,
1581 struct enumeration_mapping
*mapping
;
1583 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1584 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
,
1585 BT_FIELD_TYPE_ID_ENUM
, "Field type");
1586 mapping
= bt_field_type_common_enumeration_get_mapping_by_index(ft
,
1589 /* bt_field_type_common_enumeration_get_mapping_by_index() logs errors */
1595 *mapping_name
= g_quark_to_string(mapping
->string
);
1596 BT_ASSERT(*mapping_name
);
1600 *range_begin
= mapping
->range_start
._signed
;
1604 *range_end
= mapping
->range_end
._signed
;
1611 int bt_field_type_enumeration_signed_get_mapping_by_index(
1612 struct bt_field_type
*ft
, uint64_t index
,
1613 const char **mapping_name
, int64_t *range_begin
,
1616 return bt_field_type_common_enumeration_signed_get_mapping_by_index(
1617 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
1621 int bt_field_type_common_enumeration_unsigned_get_mapping_by_index(
1622 struct bt_field_type_common
*ft
, uint64_t index
,
1623 const char **mapping_name
, uint64_t *range_begin
,
1624 uint64_t *range_end
)
1627 struct enumeration_mapping
*mapping
;
1629 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1630 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_ENUM
, "Field type");
1631 mapping
= bt_field_type_common_enumeration_get_mapping_by_index(
1634 /* bt_field_type_common_enumeration_get_mapping_by_index() reports any error */
1640 *mapping_name
= g_quark_to_string(mapping
->string
);
1641 BT_ASSERT(*mapping_name
);
1645 *range_begin
= mapping
->range_start
._unsigned
;
1649 *range_end
= mapping
->range_end
._unsigned
;
1656 int bt_field_type_enumeration_unsigned_get_mapping_by_index(
1657 struct bt_field_type
*ft
, uint64_t index
,
1658 const char **mapping_name
, uint64_t *range_begin
,
1659 uint64_t *range_end
)
1661 return bt_field_type_common_enumeration_unsigned_get_mapping_by_index(
1662 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
1665 struct bt_field_type
*bt_field_type_enumeration_create(
1666 struct bt_field_type
*container_ft
)
1668 struct bt_field_type_common_enumeration
*enumeration
= NULL
;
1669 struct bt_field_type_common
*int_ft
= (void *) container_ft
;
1671 BT_LOGD("Creating enumeration field type object: int-ft-addr=%p",
1674 if (!container_ft
) {
1675 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1679 if (int_ft
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
1680 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
1681 "container-ft-addr=%p, container-ft-id=%s",
1682 container_ft
, bt_common_field_type_id_string(int_ft
->id
));
1686 enumeration
= g_new0(struct bt_field_type_common_enumeration
, 1);
1688 BT_LOGE_STR("Failed to allocate one enumeration field type.");
1692 bt_field_type_common_enumeration_initialize(BT_TO_COMMON(enumeration
),
1693 int_ft
, bt_field_type_common_enumeration_destroy_recursive
,
1694 &bt_field_type_enumeration_methods
);
1695 BT_LOGD("Created enumeration field type object: addr=%p, "
1696 "int-ft-addr=%p, int-ft-size=%u",
1697 enumeration
, container_ft
,
1698 bt_field_type_integer_get_size(container_ft
));
1702 BT_PUT(enumeration
);
1705 return (void *) enumeration
;
1709 struct bt_field_type_common
*
1710 bt_field_type_common_enumeration_borrow_container_field_type(
1711 struct bt_field_type_common
*ft
)
1713 struct bt_field_type_common_enumeration
*enum_ft
= BT_FROM_COMMON(ft
);
1715 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1716 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_ENUM
, "Field type");
1717 return BT_TO_COMMON(enum_ft
->container_ft
);
1720 struct bt_field_type
*bt_field_type_enumeration_borrow_container_field_type(
1721 struct bt_field_type
*ft
)
1723 return (void *) bt_field_type_common_enumeration_borrow_container_field_type(
1728 int bt_field_type_common_enumeration_signed_add_mapping(
1729 struct bt_field_type_common
*ft
, const char *string
,
1730 int64_t range_start
, int64_t range_end
)
1733 GQuark mapping_name
;
1734 struct enumeration_mapping
*mapping
;
1735 struct bt_field_type_common_enumeration
*enum_ft
= BT_FROM_COMMON(ft
);
1736 char *escaped_string
;
1739 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1745 BT_LOGW_STR("Invalid parameter: string is NULL.");
1751 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1757 if (ft
->id
!= BT_FIELD_TYPE_ID_ENUM
) {
1758 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1759 "addr=%p, ft-id=%s", ft
,
1760 bt_common_field_type_id_string(ft
->id
));
1765 if (range_end
< range_start
) {
1766 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1767 "addr=%p, range-start=%" PRId64
", range-end=%" PRId64
,
1768 ft
, range_start
, range_end
);
1773 if (strlen(string
) == 0) {
1774 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1775 "enum-ft-addr=%p, mapping-name-addr=%p", ft
,
1781 escaped_string
= g_strescape(string
, NULL
);
1782 if (!escaped_string
) {
1783 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1784 "mapping-name-addr=%p, mapping-name=\"%s\"",
1785 ft
, string
, string
);
1790 mapping
= g_new(struct enumeration_mapping
, 1);
1792 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1796 mapping_name
= g_quark_from_string(escaped_string
);
1797 *mapping
= (struct enumeration_mapping
) {
1798 .range_start
._signed
= range_start
,
1799 .range_end
._signed
= range_end
,
1800 .string
= mapping_name
,
1802 g_ptr_array_add(enum_ft
->entries
, mapping
);
1803 g_ptr_array_sort(enum_ft
->entries
,
1804 (GCompareFunc
) compare_enumeration_mappings_signed
);
1805 BT_LOGV("Added mapping to signed enumeration field type: addr=%p, "
1806 "name=\"%s\", range-start=%" PRId64
", "
1807 "range-end=%" PRId64
,
1808 ft
, string
, range_start
, range_end
);
1811 free(escaped_string
);
1817 int bt_field_type_enumeration_signed_add_mapping(
1818 struct bt_field_type
*ft
, const char *string
,
1819 int64_t range_start
, int64_t range_end
)
1821 return bt_field_type_common_enumeration_signed_add_mapping(
1822 (void *) ft
, string
, range_start
, range_end
);
1826 int bt_field_type_common_enumeration_unsigned_add_mapping(
1827 struct bt_field_type_common
*ft
, const char *string
,
1828 uint64_t range_start
, uint64_t range_end
)
1831 GQuark mapping_name
;
1832 struct enumeration_mapping
*mapping
;
1833 struct bt_field_type_common_enumeration
*enum_ft
= BT_FROM_COMMON(ft
);
1834 char *escaped_string
;
1837 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1843 BT_LOGW_STR("Invalid parameter: string is NULL.");
1849 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1855 if (ft
->id
!= BT_FIELD_TYPE_ID_ENUM
) {
1856 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1857 "addr=%p, ft-id=%s", ft
,
1858 bt_common_field_type_id_string(ft
->id
));
1863 if (range_end
< range_start
) {
1864 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1865 "addr=%p, range-start=%" PRIu64
", range-end=%" PRIu64
,
1866 ft
, range_start
, range_end
);
1871 if (strlen(string
) == 0) {
1872 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1873 "enum-ft-addr=%p, mapping-name-addr=%p", ft
,
1879 escaped_string
= g_strescape(string
, NULL
);
1880 if (!escaped_string
) {
1881 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1882 "mapping-name-addr=%p, mapping-name=\"%s\"",
1883 ft
, string
, string
);
1888 mapping
= g_new(struct enumeration_mapping
, 1);
1890 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1894 mapping_name
= g_quark_from_string(escaped_string
);
1895 *mapping
= (struct enumeration_mapping
) {
1896 .range_start
._unsigned
= range_start
,
1897 .range_end
._unsigned
= range_end
,
1898 .string
= mapping_name
,
1900 g_ptr_array_add(enum_ft
->entries
, mapping
);
1901 g_ptr_array_sort(enum_ft
->entries
,
1902 (GCompareFunc
) compare_enumeration_mappings_unsigned
);
1903 BT_LOGV("Added mapping to unsigned enumeration field type: addr=%p, "
1904 "name=\"%s\", range-start=%" PRIu64
", "
1905 "range-end=%" PRIu64
,
1906 ft
, string
, range_start
, range_end
);
1909 free(escaped_string
);
1915 int bt_field_type_enumeration_unsigned_add_mapping(
1916 struct bt_field_type
*ft
, const char *string
,
1917 uint64_t range_start
, uint64_t range_end
)
1919 return bt_field_type_common_enumeration_unsigned_add_mapping(
1920 (void *) ft
, string
, range_start
, range_end
);
1924 int64_t bt_field_type_common_enumeration_get_mapping_count(
1925 struct bt_field_type_common
*ft
)
1927 struct bt_field_type_common_enumeration
*enum_ft
= BT_FROM_COMMON(ft
);
1929 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1930 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_ENUM
, "Field type");
1931 return (int64_t) enum_ft
->entries
->len
;
1934 int64_t bt_field_type_enumeration_get_mapping_count(
1935 struct bt_field_type
*ft
)
1937 return bt_field_type_common_enumeration_get_mapping_count((void *) ft
);
1940 struct bt_field_type
*bt_field_type_floating_point_create(void)
1942 struct bt_field_type_common_floating_point
*floating_point
=
1943 g_new0(struct bt_field_type_common_floating_point
, 1);
1945 BT_LOGD_STR("Creating floating point number field type object.");
1947 if (!floating_point
) {
1948 BT_LOGE_STR("Failed to allocate one floating point number field type.");
1952 bt_field_type_common_floating_point_initialize(
1953 BT_TO_COMMON(floating_point
),
1954 bt_field_type_common_floating_point_destroy
,
1955 &bt_field_type_floating_point_methods
);
1956 BT_LOGD("Created floating point number field type object: addr=%p, "
1957 "exp-size=%u, mant-size=%u", floating_point
,
1958 floating_point
->exp_dig
, floating_point
->mant_dig
);
1961 return (void *) floating_point
;
1965 int bt_field_type_common_floating_point_get_exponent_digits(
1966 struct bt_field_type_common
*ft
)
1968 struct bt_field_type_common_floating_point
*flt_ft
= BT_FROM_COMMON(ft
);
1970 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1971 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_FLOAT
,
1973 return (int) flt_ft
->exp_dig
;
1976 int bt_field_type_floating_point_get_exponent_digits(
1977 struct bt_field_type
*ft
)
1979 return bt_field_type_common_floating_point_get_exponent_digits(
1984 int bt_field_type_common_floating_point_set_exponent_digits(
1985 struct bt_field_type_common
*ft
,
1986 unsigned int exponent_digits
)
1989 struct bt_field_type_common_floating_point
*flt_ft
= BT_FROM_COMMON(ft
);
1992 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1998 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2004 if (ft
->id
!= BT_FIELD_TYPE_ID_FLOAT
) {
2005 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
2006 "addr=%p, ft-id=%s", ft
,
2007 bt_common_field_type_id_string(ft
->id
));
2012 if ((exponent_digits
!= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
) &&
2013 (exponent_digits
!= sizeof(double) * CHAR_BIT
- DBL_MANT_DIG
) &&
2015 sizeof(long double) * CHAR_BIT
- LDBL_MANT_DIG
)) {
2016 BT_LOGW("Invalid parameter: invalid exponent size: "
2017 "addr=%p, exp-size=%u", ft
, exponent_digits
);
2022 flt_ft
->exp_dig
= exponent_digits
;
2023 BT_LOGV("Set floating point number field type's exponent size: addr=%p, "
2024 "exp-size=%u", ft
, exponent_digits
);
2030 int bt_field_type_floating_point_set_exponent_digits(
2031 struct bt_field_type
*ft
, unsigned int exponent_digits
)
2033 return bt_field_type_common_floating_point_set_exponent_digits(
2034 (void *) ft
, exponent_digits
);
2038 int bt_field_type_common_floating_point_get_mantissa_digits(
2039 struct bt_field_type_common
*ft
)
2041 struct bt_field_type_common_floating_point
*flt_ft
= BT_FROM_COMMON(ft
);
2043 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2044 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_FLOAT
,
2046 return (int) flt_ft
->mant_dig
;
2049 int bt_field_type_floating_point_get_mantissa_digits(
2050 struct bt_field_type
*ft
)
2052 return bt_field_type_common_floating_point_get_mantissa_digits(
2057 int bt_field_type_common_floating_point_set_mantissa_digits(
2058 struct bt_field_type_common
*ft
, unsigned int mantissa_digits
)
2061 struct bt_field_type_common_floating_point
*flt_ft
= BT_FROM_COMMON(ft
);
2064 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2070 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2076 if (ft
->id
!= BT_FIELD_TYPE_ID_FLOAT
) {
2077 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
2078 "addr=%p, ft-id=%s", ft
,
2079 bt_common_field_type_id_string(ft
->id
));
2084 if ((mantissa_digits
!= FLT_MANT_DIG
) &&
2085 (mantissa_digits
!= DBL_MANT_DIG
) &&
2086 (mantissa_digits
!= LDBL_MANT_DIG
)) {
2087 BT_LOGW("Invalid parameter: invalid mantissa size: "
2088 "addr=%p, mant-size=%u", ft
, mantissa_digits
);
2093 flt_ft
->mant_dig
= mantissa_digits
;
2094 BT_LOGV("Set floating point number field type's mantissa size: addr=%p, "
2095 "mant-size=%u", ft
, mantissa_digits
);
2101 int bt_field_type_floating_point_set_mantissa_digits(
2102 struct bt_field_type
*ft
, unsigned int mantissa_digits
)
2104 return bt_field_type_common_floating_point_set_mantissa_digits(
2105 (void *) ft
, mantissa_digits
);
2108 struct bt_field_type
*bt_field_type_structure_create(void)
2110 struct bt_field_type_common_structure
*structure
=
2111 g_new0(struct bt_field_type_common_structure
, 1);
2113 BT_LOGD_STR("Creating structure field type object.");
2116 BT_LOGE_STR("Failed to allocate one structure field type.");
2120 bt_field_type_common_structure_initialize(BT_TO_COMMON(structure
),
2121 bt_field_type_common_structure_destroy_recursive
,
2122 &bt_field_type_structure_methods
);
2123 BT_LOGD("Created structure field type object: addr=%p",
2131 return (void *) structure
;
2135 int bt_field_type_common_structure_replace_field(
2136 struct bt_field_type_common
*ft
,
2137 const char *field_name
,
2138 struct bt_field_type_common
*field_type
)
2141 struct bt_field_type_common_structure
*struct_ft
= BT_FROM_COMMON(ft
);
2146 BT_ASSERT(field_name
);
2147 BT_ASSERT(field_type
);
2148 BT_ASSERT(ft
->id
== BT_FIELD_TYPE_ID_STRUCT
);
2149 name_quark
= g_quark_from_string(field_name
);
2151 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
2152 struct structure_field_common
*field
= g_ptr_array_index(
2153 struct_ft
->fields
, i
);
2155 if (field
->name
== name_quark
) {
2156 bt_put(field
->type
);
2157 field
->type
= bt_get(field_type
);
2165 int bt_field_type_common_structure_add_field(struct bt_field_type_common
*ft
,
2166 struct bt_field_type_common
*field_type
,
2167 const char *field_name
)
2170 struct bt_field_type_common_structure
*struct_ft
= BT_FROM_COMMON(ft
);
2173 * TODO: check that `field_type` does not contain `type`,
2177 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2183 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2189 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2195 if (ft
->id
!= BT_FIELD_TYPE_ID_STRUCT
) {
2196 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2197 "addr=%p, ft-id=%s", ft
,
2198 bt_common_field_type_id_string(ft
->id
));
2203 if (ft
== field_type
) {
2204 BT_LOGW("Invalid parameter: structure field type and field type to add are the same: "
2210 if (add_structure_field(struct_ft
->fields
,
2211 struct_ft
->field_name_to_index
, field_type
, field_name
)) {
2212 BT_LOGW("Cannot add field to structure field type: "
2213 "struct-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2214 ft
, field_type
, field_name
);
2219 BT_LOGV("Added structure field type field: struct-ft-addr=%p, "
2220 "field-ft-addr=%p, field-name=\"%s\"", ft
,
2221 field_type
, field_name
);
2227 int bt_field_type_structure_add_field(struct bt_field_type
*ft
,
2228 struct bt_field_type
*field_type
,
2229 const char *field_name
)
2231 return bt_field_type_common_structure_add_field((void *) ft
,
2232 (void *) field_type
, field_name
);
2236 int64_t bt_field_type_common_structure_get_field_count(
2237 struct bt_field_type_common
*ft
)
2239 struct bt_field_type_common_structure
*struct_ft
= BT_FROM_COMMON(ft
);
2241 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2242 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_STRUCT
,
2244 return (int64_t) struct_ft
->fields
->len
;
2247 int64_t bt_field_type_structure_get_field_count(struct bt_field_type
*ft
)
2249 return bt_field_type_common_structure_get_field_count((void *) ft
);
2253 int bt_field_type_common_structure_borrow_field_by_index(
2254 struct bt_field_type_common
*ft
,
2255 const char **field_name
,
2256 struct bt_field_type_common
**field_type
, uint64_t index
)
2258 struct bt_field_type_common_structure
*struct_ft
= BT_FROM_COMMON(ft
);
2259 struct structure_field_common
*field
;
2261 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2262 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_STRUCT
,
2264 BT_ASSERT_PRE(index
< struct_ft
->fields
->len
,
2265 "Index is out of bounds: index=%" PRIu64
", "
2266 "count=%u, %![ft-]+_F",
2267 index
, struct_ft
->fields
->len
, ft
);
2268 field
= g_ptr_array_index(struct_ft
->fields
, index
);
2271 *field_type
= field
->type
;
2275 *field_name
= g_quark_to_string(field
->name
);
2276 BT_ASSERT(*field_name
);
2282 int bt_field_type_structure_borrow_field_by_index(
2283 struct bt_field_type
*ft
,
2284 const char **field_name
,
2285 struct bt_field_type
**field_type
, uint64_t index
)
2287 return bt_field_type_common_structure_borrow_field_by_index(
2288 (void *) ft
, field_name
, (void *) field_type
, index
);
2292 struct bt_field_type_common
*
2293 bt_field_type_common_structure_borrow_field_type_by_name(
2294 struct bt_field_type_common
*ft
, const char *name
)
2298 struct structure_field_common
*field
;
2299 struct bt_field_type_common_structure
*struct_ft
= BT_FROM_COMMON(ft
);
2300 struct bt_field_type_common
*field_type
= NULL
;
2302 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2303 BT_ASSERT_PRE_NON_NULL(name
, "Name");
2304 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_STRUCT
,
2306 name_quark
= g_quark_try_string(name
);
2308 BT_LOGV("No such structure field type field name: "
2309 "ft-addr=%p, field-name=\"%s\"",
2314 if (!g_hash_table_lookup_extended(struct_ft
->field_name_to_index
,
2315 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*) &index
)) {
2316 BT_LOGV("No such structure field type field name: "
2317 "ft-addr=%p, field-name=\"%s\"",
2322 field
= struct_ft
->fields
->pdata
[index
];
2323 field_type
= field
->type
;
2329 struct bt_field_type
*bt_field_type_structure_borrow_field_type_by_name(
2330 struct bt_field_type
*ft
, const char *name
)
2332 return (void *) bt_field_type_common_structure_borrow_field_type_by_name(
2336 struct bt_field_type
*bt_field_type_variant_create(
2337 struct bt_field_type
*tag_ft
, const char *tag_name
)
2339 struct bt_field_type_common_variant
*var_ft
= NULL
;
2341 BT_LOGD("Creating variant field type object: "
2342 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2345 if (tag_name
&& !bt_identifier_is_valid(tag_name
)) {
2346 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2347 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2352 var_ft
= g_new0(struct bt_field_type_common_variant
, 1);
2354 BT_LOGE_STR("Failed to allocate one variant field type.");
2358 bt_field_type_common_variant_initialize(BT_TO_COMMON(var_ft
),
2359 (void *) tag_ft
, tag_name
,
2360 bt_field_type_common_variant_destroy_recursive
,
2361 &bt_field_type_variant_methods
);
2362 BT_LOGD("Created variant field type object: addr=%p, "
2363 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2364 var_ft
, tag_ft
, tag_name
);
2371 return (void *) var_ft
;
2375 struct bt_field_type_common
*
2376 bt_field_type_common_variant_borrow_tag_field_type(
2377 struct bt_field_type_common
*ft
)
2379 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
2380 struct bt_field_type_common
*tag_ft
= NULL
;
2382 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2383 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_VARIANT
,
2386 if (!var_ft
->tag_ft
) {
2387 BT_LOGV("Variant field type has no tag field type: "
2392 tag_ft
= BT_TO_COMMON(var_ft
->tag_ft
);
2398 struct bt_field_type
*bt_field_type_variant_borrow_tag_field_type(
2399 struct bt_field_type
*ft
)
2401 return (void *) bt_field_type_common_variant_borrow_tag_field_type(
2406 const char *bt_field_type_common_variant_get_tag_name(
2407 struct bt_field_type_common
*ft
)
2409 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
2410 const char *tag_name
= NULL
;
2412 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2413 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_VARIANT
,
2416 if (var_ft
->tag_name
->len
== 0) {
2417 BT_LOGV("Variant field type has no tag field name: "
2422 tag_name
= var_ft
->tag_name
->str
;
2428 const char *bt_field_type_variant_get_tag_name(struct bt_field_type
*ft
)
2430 return bt_field_type_common_variant_get_tag_name((void *) ft
);
2434 int bt_field_type_common_variant_set_tag_name(
2435 struct bt_field_type_common
*ft
, const char *name
)
2438 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
2441 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2447 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2453 if (ft
->id
!= BT_FIELD_TYPE_ID_VARIANT
) {
2454 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2455 "addr=%p, ft-id=%s", ft
, bt_common_field_type_id_string(ft
->id
));
2460 if (!bt_identifier_is_valid(name
)) {
2461 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2462 "variant-ft-addr=%p, tag-field-name=\"%s\"",
2468 g_string_assign(var_ft
->tag_name
, name
);
2469 BT_LOGV("Set variant field type's tag field name: addr=%p, "
2470 "tag-field-name=\"%s\"", ft
, name
);
2476 int bt_field_type_variant_set_tag_name(
2477 struct bt_field_type
*ft
, const char *name
)
2479 return bt_field_type_common_variant_set_tag_name((void *) ft
, name
);
2483 int bt_field_type_common_variant_add_field(struct bt_field_type_common
*ft
,
2484 struct bt_field_type_common
*field_type
,
2485 const char *field_name
)
2489 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
2490 GQuark field_name_quark
= g_quark_from_string(field_name
);
2493 * TODO: check that `field_type` does not contain `type`,
2497 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2503 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2509 if (ft
->id
!= BT_FIELD_TYPE_ID_VARIANT
) {
2510 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2511 "addr=%p, ft-id=%s", ft
,
2512 bt_common_field_type_id_string(ft
->id
));
2517 if (ft
== field_type
) {
2518 BT_LOGW("Invalid parameter: variant field type and field type to add are the same: "
2524 /* The user has explicitly provided a tag; validate against it. */
2525 if (var_ft
->tag_ft
) {
2528 /* Make sure this name is present in the enum tag */
2529 for (i
= 0; i
< var_ft
->tag_ft
->entries
->len
; i
++) {
2530 struct enumeration_mapping
*mapping
=
2531 g_ptr_array_index(var_ft
->tag_ft
->entries
, i
);
2533 if (mapping
->string
== field_name_quark
) {
2540 /* Validation failed */
2541 BT_LOGW("Invalid parameter: field name does not name a tag field type's mapping: "
2542 "variant-ft-addr=%p, tag-ft-addr=%p, "
2543 "tag-field-name=\"%s\""
2544 "field-ft-addr=%p, field-name=\"%s\"",
2545 ft
, var_ft
->tag_ft
, var_ft
->tag_name
->str
,
2546 field_type
, field_name
);
2552 if (add_structure_field(var_ft
->fields
, var_ft
->field_name_to_index
,
2553 field_type
, field_name
)) {
2554 BT_LOGW("Cannot add field to variant field type: "
2555 "variant-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2556 ft
, field_type
, field_name
);
2561 BT_LOGV("Added variant field type field: variant-ft-addr=%p, "
2562 "field-ft-addr=%p, field-name=\"%s\"", ft
,
2563 field_type
, field_name
);
2569 int bt_field_type_variant_add_field(struct bt_field_type
*ft
,
2570 struct bt_field_type
*field_type
,
2571 const char *field_name
)
2573 return bt_field_type_common_variant_add_field((void *) ft
,
2574 (void *) field_type
, field_name
);
2578 struct bt_field_type_common
*
2579 bt_field_type_common_variant_borrow_field_type_by_name(
2580 struct bt_field_type_common
*ft
,
2581 const char *field_name
)
2585 struct structure_field_common
*field
;
2586 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
2587 struct bt_field_type_common
*field_type
= NULL
;
2589 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2590 BT_ASSERT_PRE_NON_NULL(field_name
, "Name");
2591 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_VARIANT
,
2593 name_quark
= g_quark_try_string(field_name
);
2595 BT_LOGV("No such variant field type field name: "
2596 "ft-addr=%p, field-name=\"%s\"",
2601 if (!g_hash_table_lookup_extended(var_ft
->field_name_to_index
,
2602 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*) &index
)) {
2603 BT_LOGV("No such variant field type field name: "
2604 "ft-addr=%p, field-name=\"%s\"",
2609 field
= g_ptr_array_index(var_ft
->fields
, index
);
2610 field_type
= field
->type
;
2616 struct bt_field_type
*bt_field_type_variant_borrow_field_type_by_name(
2617 struct bt_field_type
*ft
,
2618 const char *field_name
)
2620 return (void *) bt_field_type_common_variant_borrow_field_type_by_name(
2621 (void *) ft
, field_name
);
2625 struct bt_field_type_common
*
2626 bt_field_type_common_variant_borrow_field_type_from_tag(
2627 struct bt_field_type_common
*ft
,
2628 struct bt_field_common
*tag_field
,
2629 bt_field_common_create_func field_create_func
)
2632 const char *enum_value
;
2633 struct bt_field_type_common
*field_type
= NULL
;
2634 struct bt_field_type_enumeration_mapping_iterator
*iter
= NULL
;
2636 BT_ASSERT_PRE_NON_NULL(ft
, "Variant field type");
2637 BT_ASSERT_PRE_NON_NULL(tag_field
, "Tag field");
2638 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_VARIANT
,
2640 iter
= bt_field_common_enumeration_get_mappings(tag_field
,
2642 ret
= bt_field_type_enumeration_mapping_iterator_next(iter
);
2644 BT_LOGW("Cannot get enumeration field type mapping iterator from enumeration field: "
2645 "enum-field-addr=%p", tag_field
);
2649 ret
= bt_field_type_enumeration_mapping_iterator_signed_get(iter
,
2650 &enum_value
, NULL
, NULL
);
2652 BT_LOGW("Cannot get enumeration field type mapping iterator's current mapping: "
2653 "iter-addr=%p", iter
);
2657 field_type
= bt_field_type_common_variant_borrow_field_type_by_name(
2665 struct bt_field_type
*bt_field_type_variant_borrow_field_type_from_tag(
2666 struct bt_field_type
*ft
,
2667 struct bt_field
*tag_field
)
2669 return (void *) bt_field_type_common_variant_borrow_field_type_from_tag(
2670 (void *) ft
, (void *) tag_field
,
2671 (bt_field_common_create_func
) bt_field_create
);
2675 int64_t bt_field_type_common_variant_get_field_count(
2676 struct bt_field_type_common
*ft
)
2678 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
2680 BT_ASSERT_PRE_NON_NULL(ft
, "Variant field type");
2681 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_VARIANT
,
2683 return (int64_t) var_ft
->fields
->len
;
2686 int64_t bt_field_type_variant_get_field_count(struct bt_field_type
*ft
)
2688 return bt_field_type_common_variant_get_field_count((void *) ft
);
2692 int bt_field_type_common_variant_borrow_field_by_index(
2693 struct bt_field_type_common
*ft
,
2694 const char **field_name
,
2695 struct bt_field_type_common
**field_type
, uint64_t index
)
2697 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
2698 struct structure_field_common
*field
;
2700 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2701 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_VARIANT
,
2703 BT_ASSERT_PRE(index
< var_ft
->fields
->len
,
2704 "Index is out of bounds: index=%" PRIu64
", "
2705 "count=%u, %![ft-]+_F",
2706 index
, var_ft
->fields
->len
, ft
);
2707 field
= g_ptr_array_index(var_ft
->fields
, index
);
2710 *field_type
= field
->type
;
2714 *field_name
= g_quark_to_string(field
->name
);
2715 BT_ASSERT(*field_name
);
2721 int bt_field_type_variant_borrow_field_by_index(struct bt_field_type
*ft
,
2722 const char **field_name
, struct bt_field_type
**field_type
,
2725 return bt_field_type_common_variant_borrow_field_by_index((void *) ft
,
2726 field_name
, (void *) field_type
, index
);
2729 struct bt_field_type
*bt_field_type_array_create(
2730 struct bt_field_type
*element_ft
, unsigned int length
)
2732 struct bt_field_type_common_array
*array
= NULL
;
2734 BT_LOGD("Creating array field type object: element-ft-addr=%p, "
2735 "length=%u", element_ft
, length
);
2738 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2743 BT_LOGW_STR("Invalid parameter: length is zero.");
2747 array
= g_new0(struct bt_field_type_common_array
, 1);
2749 BT_LOGE_STR("Failed to allocate one array field type.");
2753 bt_field_type_common_array_initialize(BT_TO_COMMON(array
),
2754 (void *) element_ft
, length
,
2755 bt_field_type_common_array_destroy_recursive
,
2756 &bt_field_type_array_methods
);
2757 BT_LOGD("Created array field type object: addr=%p, "
2758 "element-ft-addr=%p, length=%u",
2759 array
, element_ft
, length
);
2766 return (void *) array
;
2770 struct bt_field_type_common
*
2771 bt_field_type_common_array_borrow_element_field_type(
2772 struct bt_field_type_common
*ft
)
2774 struct bt_field_type_common_array
*array_ft
= BT_FROM_COMMON(ft
);
2776 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2777 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_ARRAY
,
2779 BT_ASSERT(array_ft
&& array_ft
->element_ft
);
2780 return array_ft
->element_ft
;
2783 struct bt_field_type
*bt_field_type_array_borrow_element_field_type(
2784 struct bt_field_type
*ft
)
2786 return (void *) bt_field_type_common_array_borrow_element_field_type(
2791 int bt_field_type_common_array_set_element_field_type(
2792 struct bt_field_type_common
*ft
,
2793 struct bt_field_type_common
*element_ft
)
2796 struct bt_field_type_common_array
*array_ft
= BT_FROM_COMMON(ft
);
2799 BT_LOGW_STR("Invalid parameter: array field type is NULL.");
2805 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2810 if (ft
->id
!= BT_FIELD_TYPE_ID_ARRAY
) {
2811 BT_LOGW("Invalid parameter: field type is not an array field type: "
2812 "addr=%p, ft-id=%s", ft
,
2813 bt_common_field_type_id_string(ft
->id
));
2818 if (array_ft
->element_ft
) {
2819 BT_PUT(array_ft
->element_ft
);
2822 array_ft
->element_ft
= bt_get(element_ft
);
2823 BT_LOGV("Set array field type's element field type: array-ft-addr=%p, "
2824 "element-ft-addr=%p", ft
, element_ft
);
2831 int64_t bt_field_type_common_array_get_length(struct bt_field_type_common
*ft
)
2833 struct bt_field_type_common_array
*array_ft
= BT_FROM_COMMON(ft
);
2835 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2836 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_ARRAY
,
2838 return (int64_t) array_ft
->length
;
2841 int64_t bt_field_type_array_get_length(struct bt_field_type
*ft
)
2843 return bt_field_type_common_array_get_length((void *) ft
);
2846 struct bt_field_type
*bt_field_type_sequence_create(
2847 struct bt_field_type
*element_ft
,
2848 const char *length_field_name
)
2850 struct bt_field_type_common_sequence
*sequence
= NULL
;
2852 BT_LOGD("Creating sequence field type object: element-ft-addr=%p, "
2853 "length-field-name=\"%s\"", element_ft
, length_field_name
);
2856 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2860 if (!bt_identifier_is_valid(length_field_name
)) {
2861 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
2862 "length-field-name=\"%s\"", length_field_name
);
2866 sequence
= g_new0(struct bt_field_type_common_sequence
, 1);
2868 BT_LOGE_STR("Failed to allocate one sequence field type.");
2872 bt_field_type_common_sequence_initialize(BT_TO_COMMON(sequence
),
2873 (void *) element_ft
, length_field_name
,
2874 bt_field_type_common_sequence_destroy_recursive
,
2875 &bt_field_type_sequence_methods
);
2876 BT_LOGD("Created sequence field type object: addr=%p, "
2877 "element-ft-addr=%p, length-field-name=\"%s\"",
2878 sequence
, element_ft
, length_field_name
);
2885 return (void *) sequence
;
2889 struct bt_field_type_common
*bt_field_type_common_sequence_borrow_element_field_type(
2890 struct bt_field_type_common
*ft
)
2892 struct bt_field_type_common_sequence
*seq_ft
= BT_FROM_COMMON(ft
);
2894 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2895 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_SEQUENCE
,
2897 return seq_ft
->element_ft
;
2900 struct bt_field_type
*bt_field_type_sequence_borrow_element_field_type(
2901 struct bt_field_type
*ft
)
2903 return (void *) bt_field_type_common_sequence_borrow_element_field_type(
2908 int bt_field_type_common_sequence_set_element_field_type(
2909 struct bt_field_type_common
*ft
,
2910 struct bt_field_type_common
*element_ft
)
2913 struct bt_field_type_common_sequence
*seq_ft
= BT_FROM_COMMON(ft
);
2916 BT_LOGW_STR("Invalid parameter: sequence field type is NULL.");
2922 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2927 if (ft
->id
!= BT_FIELD_TYPE_ID_SEQUENCE
) {
2928 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2929 "addr=%p, ft-id=%s", ft
,
2930 bt_common_field_type_id_string(ft
->id
));
2935 if (seq_ft
->element_ft
) {
2936 BT_PUT(seq_ft
->element_ft
);
2939 seq_ft
->element_ft
= element_ft
;
2940 bt_get(seq_ft
->element_ft
);
2941 BT_LOGV("Set sequence field type's element field type: sequence-ft-addr=%p, "
2942 "element-ft-addr=%p", ft
, element_ft
);
2949 const char *bt_field_type_common_sequence_get_length_field_name(
2950 struct bt_field_type_common
*ft
)
2952 struct bt_field_type_common_sequence
*seq_ft
= BT_FROM_COMMON(ft
);
2954 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2955 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_SEQUENCE
,
2957 return seq_ft
->length_field_name
?
2958 seq_ft
->length_field_name
->str
: NULL
;
2961 const char *bt_field_type_sequence_get_length_field_name(
2962 struct bt_field_type
*ft
)
2964 return bt_field_type_common_sequence_get_length_field_name((void *) ft
);
2967 struct bt_field_type
*bt_field_type_string_create(void)
2969 struct bt_field_type_common_string
*string
=
2970 g_new0(struct bt_field_type_common_string
, 1);
2972 BT_LOGD_STR("Creating string field type object.");
2975 BT_LOGE_STR("Failed to allocate one string field type.");
2979 bt_field_type_common_string_initialize(BT_TO_COMMON(string
),
2980 bt_field_type_common_string_destroy
,
2981 &bt_field_type_string_methods
);
2982 BT_LOGD("Created string field type object: addr=%p", string
);
2983 return (void *) string
;
2987 enum bt_string_encoding
bt_field_type_common_string_get_encoding(
2988 struct bt_field_type_common
*ft
)
2990 struct bt_field_type_common_string
*string_ft
= BT_FROM_COMMON(ft
);
2992 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2993 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_STRING
,
2995 return string_ft
->encoding
;
2998 enum bt_string_encoding
bt_field_type_string_get_encoding(
2999 struct bt_field_type
*ft
)
3001 return bt_field_type_common_string_get_encoding((void *) ft
);
3005 int bt_field_type_common_string_set_encoding(struct bt_field_type_common
*ft
,
3006 enum bt_string_encoding encoding
)
3009 struct bt_field_type_common_string
*string_ft
= BT_FROM_COMMON(ft
);
3012 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3017 if (ft
->id
!= BT_FIELD_TYPE_ID_STRING
) {
3018 BT_LOGW("Invalid parameter: field type is not a string field type: "
3019 "addr=%p, ft-id=%s", ft
,
3020 bt_common_field_type_id_string(ft
->id
));
3025 if (encoding
!= BT_STRING_ENCODING_UTF8
&&
3026 encoding
!= BT_STRING_ENCODING_ASCII
) {
3027 BT_LOGW("Invalid parameter: unknown string encoding: "
3028 "addr=%p, encoding=%d", ft
, encoding
);
3033 string_ft
->encoding
= encoding
;
3034 BT_LOGV("Set string field type's encoding: addr=%p, encoding=%s",
3035 ft
, bt_common_string_encoding_string(encoding
));
3041 int bt_field_type_string_set_encoding(struct bt_field_type
*ft
,
3042 enum bt_string_encoding encoding
)
3044 return bt_field_type_common_string_set_encoding((void *) ft
, encoding
);
3048 int bt_field_type_common_get_alignment(struct bt_field_type_common
*ft
)
3051 enum bt_field_type_id type_id
;
3053 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
3056 ret
= (int) ft
->alignment
;
3060 type_id
= bt_field_type_common_get_type_id(ft
);
3062 case BT_FIELD_TYPE_ID_SEQUENCE
:
3064 struct bt_field_type_common
*element_ft
=
3065 bt_field_type_common_sequence_borrow_element_field_type(ft
);
3067 BT_ASSERT(element_ft
);
3068 ret
= bt_field_type_common_get_alignment(element_ft
);
3071 case BT_FIELD_TYPE_ID_ARRAY
:
3073 struct bt_field_type_common
*element_ft
=
3074 bt_field_type_common_array_borrow_element_field_type(ft
);
3076 BT_ASSERT(element_ft
);
3077 ret
= bt_field_type_common_get_alignment(element_ft
);
3080 case BT_FIELD_TYPE_ID_STRUCT
:
3082 int64_t i
, element_count
;
3084 element_count
= bt_field_type_common_structure_get_field_count(
3086 BT_ASSERT(element_count
>= 0);
3088 for (i
= 0; i
< element_count
; i
++) {
3089 struct bt_field_type_common
*field
= NULL
;
3090 int field_alignment
;
3092 ret
= bt_field_type_common_structure_borrow_field_by_index(
3093 ft
, NULL
, &field
, i
);
3094 BT_ASSERT(ret
== 0);
3096 field_alignment
= bt_field_type_common_get_alignment(
3098 if (field_alignment
< 0) {
3099 ret
= field_alignment
;
3103 ft
->alignment
= MAX(field_alignment
, ft
->alignment
);
3105 ret
= (int) ft
->alignment
;
3108 case BT_FIELD_TYPE_ID_UNKNOWN
:
3109 BT_LOGW("Invalid parameter: unknown field type ID: "
3110 "addr=%p, ft-id=%d", ft
, type_id
);
3114 ret
= (int) ft
->alignment
;
3122 int bt_field_type_get_alignment(struct bt_field_type
*ft
)
3124 return bt_field_type_common_get_alignment((void *) ft
);
3128 int is_power_of_two(unsigned int value
)
3130 return ((value
& (value
- 1)) == 0) && value
> 0;
3134 int bt_field_type_common_set_alignment(struct bt_field_type_common
*ft
,
3135 unsigned int alignment
)
3138 enum bt_field_type_id type_id
;
3140 /* Alignment must be a power of two */
3142 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3148 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3154 if (!is_power_of_two(alignment
)) {
3155 BT_LOGW("Invalid parameter: alignment is not a power of two: "
3156 "addr=%p, align=%u", ft
, alignment
);
3161 type_id
= bt_field_type_common_get_type_id(ft
);
3162 if (type_id
== BT_FIELD_TYPE_ID_UNKNOWN
) {
3163 BT_LOGW("Invalid parameter: unknown field type ID: "
3164 "addr=%p, ft-id=%d", ft
, type_id
);
3169 if (ft
->id
== BT_FIELD_TYPE_ID_STRING
&& alignment
!= CHAR_BIT
) {
3170 BT_LOGW("Invalid parameter: alignment must be %u for a string field type: "
3171 "addr=%p, align=%u", CHAR_BIT
, ft
, alignment
);
3176 if (type_id
== BT_FIELD_TYPE_ID_VARIANT
||
3177 type_id
== BT_FIELD_TYPE_ID_SEQUENCE
||
3178 type_id
== BT_FIELD_TYPE_ID_ARRAY
) {
3179 /* Setting an alignment on these types makes no sense */
3180 BT_LOGW("Invalid parameter: cannot set the alignment of this field type: "
3181 "addr=%p, ft-id=%s", ft
,
3182 bt_common_field_type_id_string(ft
->id
));
3187 ft
->alignment
= alignment
;
3189 BT_LOGV("Set field type's alignment: addr=%p, align=%u",
3196 int bt_field_type_set_alignment(struct bt_field_type
*ft
,
3197 unsigned int alignment
)
3199 return bt_field_type_common_set_alignment((void *) ft
, alignment
);
3203 enum bt_byte_order
bt_field_type_common_get_byte_order(
3204 struct bt_field_type_common
*ft
)
3206 enum bt_byte_order ret
= BT_BYTE_ORDER_UNKNOWN
;
3208 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
3211 case BT_FIELD_TYPE_ID_INTEGER
:
3213 struct bt_field_type_common_integer
*integer
=
3216 ret
= integer
->user_byte_order
;
3219 case BT_FIELD_TYPE_ID_ENUM
:
3221 struct bt_field_type_common_enumeration
*enum_ft
=
3224 ret
= bt_field_type_common_get_byte_order(
3225 BT_TO_COMMON(enum_ft
->container_ft
));
3228 case BT_FIELD_TYPE_ID_FLOAT
:
3230 struct bt_field_type_common_floating_point
*floating_point
=
3232 ret
= floating_point
->user_byte_order
;
3236 BT_LOGW("Invalid parameter: cannot get the byte order of this field type: "
3237 "addr=%p, ft-id=%s", ft
,
3238 bt_common_field_type_id_string(ft
->id
));
3242 BT_ASSERT(ret
== BT_BYTE_ORDER_NATIVE
||
3243 ret
== BT_BYTE_ORDER_LITTLE_ENDIAN
||
3244 ret
== BT_BYTE_ORDER_BIG_ENDIAN
||
3245 ret
== BT_BYTE_ORDER_NETWORK
);
3251 enum bt_byte_order
bt_field_type_get_byte_order(struct bt_field_type
*ft
)
3253 return bt_field_type_common_get_byte_order((void *) ft
);
3257 int bt_field_type_common_set_byte_order(struct bt_field_type_common
*ft
,
3258 enum bt_byte_order byte_order
)
3263 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3269 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3275 if (byte_order
!= BT_BYTE_ORDER_NATIVE
&&
3276 byte_order
!= BT_BYTE_ORDER_LITTLE_ENDIAN
&&
3277 byte_order
!= BT_BYTE_ORDER_BIG_ENDIAN
&&
3278 byte_order
!= BT_BYTE_ORDER_NETWORK
) {
3279 BT_LOGW("Invalid parameter: invalid byte order: "
3280 "addr=%p, bo=%s", ft
,
3281 bt_common_byte_order_string(byte_order
));
3286 if (ft
->methods
->set_byte_order
) {
3287 ft
->methods
->set_byte_order(ft
, byte_order
);
3290 BT_LOGV("Set field type's byte order: addr=%p, bo=%s",
3291 ft
, bt_common_byte_order_string(byte_order
));
3297 int bt_field_type_set_byte_order(struct bt_field_type
*ft
,
3298 enum bt_byte_order byte_order
)
3300 return bt_field_type_common_set_byte_order((void *) ft
, byte_order
);
3304 enum bt_field_type_id
bt_field_type_common_get_type_id(
3305 struct bt_field_type_common
*ft
)
3307 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
3311 enum bt_field_type_id
bt_field_type_get_type_id(struct bt_field_type
*ft
)
3313 return bt_field_type_common_get_type_id((void *) ft
);
3316 int bt_field_type_is_integer(struct bt_field_type
*type
)
3318 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_INTEGER
;
3321 int bt_field_type_is_floating_point(struct bt_field_type
*type
)
3323 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_FLOAT
;
3326 int bt_field_type_is_enumeration(struct bt_field_type
*type
)
3328 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_ENUM
;
3331 int bt_field_type_is_string(struct bt_field_type
*type
)
3333 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_STRING
;
3336 int bt_field_type_is_structure(struct bt_field_type
*type
)
3338 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_STRUCT
;
3341 int bt_field_type_is_array(struct bt_field_type
*type
)
3343 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_ARRAY
;
3346 int bt_field_type_is_sequence(struct bt_field_type
*type
)
3348 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_SEQUENCE
;
3351 int bt_field_type_is_variant(struct bt_field_type
*type
)
3353 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_VARIANT
;
3357 void _bt_field_type_common_freeze(struct bt_field_type_common
*ft
)
3359 if (!ft
|| ft
->frozen
) {
3363 BT_ASSERT(ft
->methods
->freeze
);
3364 ft
->methods
->freeze(ft
);
3368 void _bt_field_type_freeze(struct bt_field_type
*ft
)
3370 _bt_field_type_common_freeze((void *) ft
);
3374 struct bt_field_type_common
*
3375 bt_field_type_common_variant_borrow_field_type_signed(
3376 struct bt_field_type_common_variant
*var_ft
,
3379 struct bt_field_type_common
*field_type
= NULL
;
3380 GQuark field_name_quark
;
3382 struct structure_field_common
*field_entry
;
3383 struct range_overlap_query query
= {
3384 .range_start
._signed
= tag_value
,
3385 .range_end
._signed
= tag_value
,
3390 g_ptr_array_foreach(var_ft
->tag_ft
->entries
, check_ranges_overlap
,
3392 if (!query
.overlaps
) {
3396 field_name_quark
= query
.mapping_name
;
3397 if (!g_hash_table_lookup_extended(var_ft
->field_name_to_index
,
3398 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3402 field_entry
= g_ptr_array_index(var_ft
->fields
, (size_t) index
);
3403 field_type
= field_entry
->type
;
3410 struct bt_field_type_common
*
3411 bt_field_type_common_variant_borrow_field_type_unsigned(
3412 struct bt_field_type_common_variant
*var_ft
,
3415 struct bt_field_type_common
*field_type
= NULL
;
3416 GQuark field_name_quark
;
3418 struct structure_field_common
*field_entry
;
3419 struct range_overlap_query query
= {
3420 .range_start
._unsigned
= tag_value
,
3421 .range_end
._unsigned
= tag_value
,
3426 g_ptr_array_foreach(var_ft
->tag_ft
->entries
,
3427 check_ranges_overlap_unsigned
, &query
);
3428 if (!query
.overlaps
) {
3432 field_name_quark
= query
.mapping_name
;
3433 if (!g_hash_table_lookup_extended(var_ft
->field_name_to_index
,
3434 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3438 field_entry
= g_ptr_array_index(var_ft
->fields
, (size_t) index
);
3439 field_type
= field_entry
->type
;
3445 struct bt_field_type_common
*bt_field_type_common_copy(
3446 struct bt_field_type_common
*ft
)
3448 struct bt_field_type_common
*ft_copy
= NULL
;
3450 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
3451 BT_ASSERT(ft
->methods
->copy
);
3452 ft_copy
= ft
->methods
->copy(ft
);
3454 BT_LOGE_STR("Cannot copy field type.");
3458 ft_copy
->alignment
= ft
->alignment
;
3464 struct bt_field_type
*bt_field_type_copy(struct bt_field_type
*ft
)
3466 return (void *) bt_field_type_common_copy((void *) ft
);
3470 int bt_field_type_common_structure_get_field_name_index(
3471 struct bt_field_type_common
*ft
, const char *name
)
3476 struct bt_field_type_common_structure
*struct_ft
= BT_FROM_COMMON(ft
);
3478 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
3479 BT_ASSERT_PRE_NON_NULL(name
, "Name");
3480 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_STRUCT
,
3483 name_quark
= g_quark_try_string(name
);
3485 BT_LOGV("No such structure field type field name: "
3486 "ft-addr=%p, field-name=\"%s\"",
3492 if (!g_hash_table_lookup_extended(struct_ft
->field_name_to_index
,
3493 GUINT_TO_POINTER(name_quark
),
3494 NULL
, (gpointer
*) &index
)) {
3495 BT_LOGV("No such structure field type field name: "
3496 "ft-addr=%p, field-name=\"%s\"",
3509 int bt_field_type_common_variant_get_field_name_index(
3510 struct bt_field_type_common
*ft
, const char *name
)
3515 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
3517 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
3518 BT_ASSERT_PRE_NON_NULL(name
, "Name");
3519 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_VARIANT
,
3521 name_quark
= g_quark_try_string(name
);
3523 BT_LOGV("No such variant field type field name: "
3524 "ft-addr=%p, field-name=\"%s\"",
3530 if (!g_hash_table_lookup_extended(var_ft
->field_name_to_index
,
3531 GUINT_TO_POINTER(name_quark
),
3532 NULL
, (gpointer
*) &index
)) {
3533 BT_LOGV("No such variant field type field name: "
3534 "ft-addr=%p, field-name=\"%s\"",
3547 int bt_field_type_common_sequence_set_length_field_path(
3548 struct bt_field_type_common
*ft
, struct bt_field_path
*path
)
3551 struct bt_field_type_common_sequence
*seq_ft
= BT_FROM_COMMON(ft
);
3554 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3559 if (ft
->id
!= BT_FIELD_TYPE_ID_SEQUENCE
) {
3560 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
3561 "addr=%p, ft-id=%s", ft
,
3562 bt_common_field_type_id_string(ft
->id
));
3568 BT_MOVE(seq_ft
->length_field_path
, path
);
3569 BT_LOGV("Set sequence field type's length field path: ft-addr=%p, "
3570 "field-path-addr=%p", ft
, path
);
3577 int bt_field_type_common_variant_set_tag_field_path(
3578 struct bt_field_type_common
*ft
,
3579 struct bt_field_path
*path
)
3582 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
3585 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3590 if (ft
->id
!= BT_FIELD_TYPE_ID_VARIANT
) {
3591 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3592 "addr=%p, ft-id=%s", ft
,
3593 bt_common_field_type_id_string(ft
->id
));
3599 BT_MOVE(var_ft
->tag_field_path
, path
);
3600 BT_LOGV("Set variant field type's tag field path: ft-addr=%p, "
3601 "field-path-addr=%p", ft
, path
);
3608 int bt_field_type_common_variant_set_tag_field_type(
3609 struct bt_field_type_common
*ft
,
3610 struct bt_field_type_common
*tag_ft
)
3613 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
3616 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3622 BT_LOGW_STR("Invalid parameter: tag field type is NULL.");
3627 if (tag_ft
->id
!= BT_FIELD_TYPE_ID_ENUM
) {
3628 BT_LOGW("Invalid parameter: tag field type is not an enumeration field type: "
3629 "addr=%p, ft-id=%s", tag_ft
,
3630 bt_common_field_type_id_string(tag_ft
->id
));
3635 bt_put(var_ft
->tag_ft
);
3636 var_ft
->tag_ft
= bt_get(tag_ft
);
3637 BT_LOGV("Set variant field type's tag field type: variant-ft-addr=%p, "
3638 "tag-ft-addr=%p", ft
, tag_ft
);
3645 void bt_field_type_common_generic_freeze(struct bt_field_type_common
*ft
)
3651 void bt_field_type_common_enumeration_freeze_recursive(
3652 struct bt_field_type_common
*ft
)
3654 struct bt_field_type_common_enumeration
*enum_ft
= BT_FROM_COMMON(ft
);
3656 BT_LOGD("Freezing enumeration field type object: addr=%p", ft
);
3657 bt_field_type_common_enumeration_set_range_overlap(enum_ft
);
3658 bt_field_type_common_generic_freeze(ft
);
3659 BT_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p",
3660 enum_ft
->container_ft
);
3661 bt_field_type_common_freeze(BT_TO_COMMON(enum_ft
->container_ft
));
3665 void freeze_structure_field(struct structure_field_common
*field
)
3667 BT_LOGD("Freezing structure/variant field type field: field-addr=%p, "
3668 "field-ft-addr=%p, field-name=\"%s\"", field
,
3669 field
->type
, g_quark_to_string(field
->name
));
3670 bt_field_type_common_freeze(field
->type
);
3674 void bt_field_type_common_structure_freeze_recursive(
3675 struct bt_field_type_common
*ft
)
3677 struct bt_field_type_common_structure
*struct_ft
= BT_FROM_COMMON(ft
);
3679 /* Cache the alignment */
3680 BT_LOGD("Freezing structure field type object: addr=%p", ft
);
3681 ft
->alignment
= bt_field_type_common_get_alignment(ft
);
3682 bt_field_type_common_generic_freeze(ft
);
3683 g_ptr_array_foreach(struct_ft
->fields
,
3684 (GFunc
) freeze_structure_field
, NULL
);
3688 void bt_field_type_common_variant_freeze_recursive(
3689 struct bt_field_type_common
*ft
)
3691 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
3693 BT_LOGD("Freezing variant field type object: addr=%p", ft
);
3694 bt_field_type_common_generic_freeze(ft
);
3695 g_ptr_array_foreach(var_ft
->fields
,
3696 (GFunc
) freeze_structure_field
, NULL
);
3700 void bt_field_type_common_array_freeze_recursive(
3701 struct bt_field_type_common
*ft
)
3703 struct bt_field_type_common_array
*array_ft
= BT_FROM_COMMON(ft
);
3705 /* Cache the alignment */
3706 BT_LOGD("Freezing array field type object: addr=%p", ft
);
3707 ft
->alignment
= bt_field_type_common_get_alignment(ft
);
3708 bt_field_type_common_generic_freeze(ft
);
3709 BT_LOGD("Freezing array field type object's element field type: element-ft-addr=%p",
3710 array_ft
->element_ft
);
3711 bt_field_type_common_freeze(array_ft
->element_ft
);
3715 void bt_field_type_common_sequence_freeze_recursive(
3716 struct bt_field_type_common
*ft
)
3718 struct bt_field_type_common_sequence
*seq_ft
= BT_FROM_COMMON(ft
);
3720 /* Cache the alignment */
3721 BT_LOGD("Freezing sequence field type object: addr=%p", ft
);
3722 ft
->alignment
= bt_field_type_common_get_alignment(ft
);
3723 bt_field_type_common_generic_freeze(ft
);
3724 BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
3725 seq_ft
->element_ft
);
3726 bt_field_type_common_freeze(seq_ft
->element_ft
);
3730 void bt_field_type_common_integer_set_byte_order(
3731 struct bt_field_type_common
*ft
, enum bt_byte_order byte_order
)
3733 struct bt_field_type_common_integer
*int_ft
= BT_FROM_COMMON(ft
);
3735 int_ft
->user_byte_order
= byte_order
;
3739 void bt_field_type_common_enumeration_set_byte_order_recursive(
3740 struct bt_field_type_common
*ft
, enum bt_byte_order byte_order
)
3742 struct bt_field_type_common_enumeration
*enum_ft
= BT_FROM_COMMON(ft
);
3744 bt_field_type_common_set_byte_order(BT_TO_COMMON(enum_ft
->container_ft
),
3749 void bt_field_type_common_floating_point_set_byte_order(
3750 struct bt_field_type_common
*ft
, enum bt_byte_order byte_order
)
3752 struct bt_field_type_common_floating_point
*flt_ft
= BT_FROM_COMMON(ft
);
3754 flt_ft
->user_byte_order
= byte_order
;
3758 void bt_field_type_common_structure_set_byte_order_recursive(
3759 struct bt_field_type_common
*ft
,
3760 enum bt_byte_order byte_order
)
3763 struct bt_field_type_common_structure
*struct_ft
= BT_FROM_COMMON(ft
);
3765 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
3766 struct structure_field_common
*field
= g_ptr_array_index(
3767 struct_ft
->fields
, i
);
3768 struct bt_field_type_common
*field_type
= field
->type
;
3770 bt_field_type_common_set_byte_order(field_type
, byte_order
);
3775 void bt_field_type_common_variant_set_byte_order_recursive(
3776 struct bt_field_type_common
*ft
,
3777 enum bt_byte_order byte_order
)
3780 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
3782 for (i
= 0; i
< var_ft
->fields
->len
; i
++) {
3783 struct structure_field_common
*field
= g_ptr_array_index(
3785 struct bt_field_type_common
*field_type
= field
->type
;
3787 bt_field_type_common_set_byte_order(field_type
, byte_order
);
3792 void bt_field_type_common_array_set_byte_order_recursive(
3793 struct bt_field_type_common
*ft
,
3794 enum bt_byte_order byte_order
)
3796 struct bt_field_type_common_array
*array_ft
= BT_FROM_COMMON(ft
);
3798 bt_field_type_common_set_byte_order(array_ft
->element_ft
, byte_order
);
3802 void bt_field_type_common_sequence_set_byte_order_recursive(
3803 struct bt_field_type_common
*ft
,
3804 enum bt_byte_order byte_order
)
3806 struct bt_field_type_common_sequence
*seq_ft
= BT_FROM_COMMON(ft
);
3808 bt_field_type_common_set_byte_order(seq_ft
->element_ft
, byte_order
);
3813 int bt_field_type_common_integer_compare(struct bt_field_type_common
*ft_a
,
3814 struct bt_field_type_common
*ft_b
)
3817 struct bt_field_type_common_integer
*int_ft_a
= BT_FROM_COMMON(ft_a
);
3818 struct bt_field_type_common_integer
*int_ft_b
= BT_FROM_COMMON(ft_b
);
3821 if (int_ft_a
->size
!= int_ft_b
->size
) {
3822 BT_LOGV("Integer field types differ: different sizes: "
3823 "ft-a-size=%u, ft-b-size=%u",
3824 int_ft_a
->size
, int_ft_b
->size
);
3829 if (int_ft_a
->user_byte_order
!= int_ft_b
->user_byte_order
) {
3830 BT_LOGV("Integer field types differ: different byte orders: "
3831 "ft-a-bo=%s, ft-b-bo=%s",
3832 bt_common_byte_order_string(int_ft_a
->user_byte_order
),
3833 bt_common_byte_order_string(int_ft_b
->user_byte_order
));
3838 if (int_ft_a
->is_signed
!= int_ft_b
->is_signed
) {
3839 BT_LOGV("Integer field types differ: different signedness: "
3840 "ft-a-is-signed=%d, ft-b-is-signed=%d",
3841 int_ft_a
->is_signed
,
3842 int_ft_b
->is_signed
);
3847 if (int_ft_a
->base
!= int_ft_b
->base
) {
3848 BT_LOGV("Integer field types differ: different bases: "
3849 "ft-a-base=%s, ft-b-base=%s",
3850 bt_common_integer_base_string(int_ft_a
->base
),
3851 bt_common_integer_base_string(int_ft_b
->base
));
3856 if (int_ft_a
->encoding
!= int_ft_b
->encoding
) {
3857 BT_LOGV("Integer field types differ: different encodings: "
3858 "ft-a-encoding=%s, ft-b-encoding=%s",
3859 bt_common_string_encoding_string(int_ft_a
->encoding
),
3860 bt_common_string_encoding_string(int_ft_b
->encoding
));
3864 /* Mapped clock class */
3865 if (int_ft_a
->mapped_clock_class
) {
3866 if (!int_ft_b
->mapped_clock_class
) {
3867 BT_LOGV_STR("Integer field types differ: field type A "
3868 "has a mapped clock class, but field type B "
3873 if (bt_clock_class_compare(int_ft_a
->mapped_clock_class
,
3874 int_ft_b
->mapped_clock_class
) != 0) {
3875 BT_LOGV_STR("Integer field types differ: different "
3876 "mapped clock classes.");
3879 if (int_ft_b
->mapped_clock_class
) {
3880 BT_LOGV_STR("Integer field types differ: field type A "
3881 "has no description, but field type B has one.");
3894 int bt_field_type_common_floating_point_compare(
3895 struct bt_field_type_common
*ft_a
,
3896 struct bt_field_type_common
*ft_b
)
3899 struct bt_field_type_common_floating_point
*flt_ft_a
=
3900 BT_FROM_COMMON(ft_a
);
3901 struct bt_field_type_common_floating_point
*flt_ft_b
=
3902 BT_FROM_COMMON(ft_b
);
3905 if (flt_ft_a
->user_byte_order
!= flt_ft_b
->user_byte_order
) {
3906 BT_LOGV("Floating point number field types differ: different byte orders: "
3907 "ft-a-bo=%s, ft-b-bo=%s",
3908 bt_common_byte_order_string(flt_ft_a
->user_byte_order
),
3909 bt_common_byte_order_string(flt_ft_b
->user_byte_order
));
3913 /* Exponent length */
3914 if (flt_ft_a
->exp_dig
!= flt_ft_b
->exp_dig
) {
3915 BT_LOGV("Floating point number field types differ: different exponent sizes: "
3916 "ft-a-exp-size=%u, ft-b-exp-size=%u",
3917 flt_ft_a
->exp_dig
, flt_ft_b
->exp_dig
);
3921 /* Mantissa length */
3922 if (flt_ft_a
->mant_dig
!= flt_ft_b
->mant_dig
) {
3923 BT_LOGV("Floating point number field types differ: different mantissa sizes: "
3924 "ft-a-mant-size=%u, ft-b-mant-size=%u",
3925 flt_ft_a
->mant_dig
, flt_ft_b
->mant_dig
);
3937 int compare_enumeration_mappings(struct enumeration_mapping
*mapping_a
,
3938 struct enumeration_mapping
*mapping_b
)
3943 if (mapping_a
->string
!= mapping_b
->string
) {
3944 BT_LOGV("Enumeration field type mappings differ: different names: "
3945 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
3946 g_quark_to_string(mapping_a
->string
),
3947 g_quark_to_string(mapping_b
->string
));
3952 if (mapping_a
->range_start
._unsigned
!=
3953 mapping_b
->range_start
._unsigned
) {
3954 BT_LOGV("Enumeration field type mappings differ: different starts of range: "
3955 "mapping-a-range-start-unsigned=%" PRIu64
", "
3956 "mapping-b-range-start-unsigned=%" PRIu64
,
3957 mapping_a
->range_start
._unsigned
,
3958 mapping_b
->range_start
._unsigned
);
3963 if (mapping_a
->range_end
._unsigned
!=
3964 mapping_b
->range_end
._unsigned
) {
3965 BT_LOGV("Enumeration field type mappings differ: different ends of range: "
3966 "mapping-a-range-end-unsigned=%" PRIu64
", "
3967 "mapping-b-range-end-unsigned=%" PRIu64
,
3968 mapping_a
->range_end
._unsigned
,
3969 mapping_b
->range_end
._unsigned
);
3981 int bt_field_type_common_enumeration_compare_recursive(
3982 struct bt_field_type_common
*ft_a
,
3983 struct bt_field_type_common
*ft_b
)
3987 struct bt_field_type_common_enumeration
*enum_ft_a
=
3988 BT_FROM_COMMON(ft_a
);
3989 struct bt_field_type_common_enumeration
*enum_ft_b
=
3990 BT_FROM_COMMON(ft_b
);
3992 /* Container field type */
3993 ret
= bt_field_type_common_compare(
3994 BT_TO_COMMON(enum_ft_a
->container_ft
),
3995 BT_TO_COMMON(enum_ft_b
->container_ft
));
3997 BT_LOGV("Enumeration field types differ: different container field types: "
3998 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
3999 enum_ft_a
->container_ft
, enum_ft_b
->container_ft
);
4006 if (enum_ft_a
->entries
->len
!= enum_ft_b
->entries
->len
) {
4010 for (i
= 0; i
< enum_ft_a
->entries
->len
; ++i
) {
4011 struct enumeration_mapping
*mapping_a
=
4012 g_ptr_array_index(enum_ft_a
->entries
, i
);
4013 struct enumeration_mapping
*mapping_b
=
4014 g_ptr_array_index(enum_ft_b
->entries
, i
);
4016 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
4017 BT_LOGV("Enumeration field types differ: different mappings: "
4018 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
4019 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
4020 mapping_a
, mapping_b
,
4021 g_quark_to_string(mapping_a
->string
),
4022 g_quark_to_string(mapping_b
->string
));
4035 int bt_field_type_common_string_compare(struct bt_field_type_common
*ft_a
,
4036 struct bt_field_type_common
*ft_b
)
4039 struct bt_field_type_common_string
*string_ft_a
= BT_FROM_COMMON(ft_a
);
4040 struct bt_field_type_common_string
*string_ft_b
= BT_FROM_COMMON(ft_b
);
4043 if (string_ft_a
->encoding
!= string_ft_b
->encoding
) {
4044 BT_LOGV("String field types differ: different encodings: "
4045 "ft-a-encoding=%s, ft-b-encoding=%s",
4046 bt_common_string_encoding_string(string_ft_a
->encoding
),
4047 bt_common_string_encoding_string(string_ft_b
->encoding
));
4059 int compare_structure_fields(struct structure_field_common
*field_a
,
4060 struct structure_field_common
*field_b
)
4065 if (field_a
->name
!= field_b
->name
) {
4066 BT_LOGV("Structure/variant field type fields differ: different names: "
4067 "field-a-name=%s, field-b-name=%s",
4068 g_quark_to_string(field_a
->name
),
4069 g_quark_to_string(field_b
->name
));
4074 ret
= bt_field_type_common_compare(field_a
->type
, field_b
->type
);
4076 BT_LOGV("Structure/variant field type fields differ: different field types: "
4077 "field-name=\"%s\", field-a-ft-addr=%p, field-b-ft-addr=%p",
4078 g_quark_to_string(field_a
->name
),
4079 field_a
->type
, field_b
->type
);
4087 int bt_field_type_common_structure_compare_recursive(
4088 struct bt_field_type_common
*ft_a
,
4089 struct bt_field_type_common
*ft_b
)
4093 struct bt_field_type_common_structure
*struct_ft_a
=
4094 BT_FROM_COMMON(ft_a
);
4095 struct bt_field_type_common_structure
*struct_ft_b
=
4096 BT_FROM_COMMON(ft_b
);
4099 if (bt_field_type_common_get_alignment(ft_a
) !=
4100 bt_field_type_common_get_alignment(ft_b
)) {
4101 BT_LOGV("Structure field types differ: different alignments: "
4102 "ft-a-align=%u, ft-b-align=%u",
4103 bt_field_type_common_get_alignment(ft_a
),
4104 bt_field_type_common_get_alignment(ft_b
));
4109 if (struct_ft_a
->fields
->len
!= struct_ft_b
->fields
->len
) {
4110 BT_LOGV("Structure field types differ: different field counts: "
4111 "ft-a-field-count=%u, ft-b-field-count=%u",
4112 struct_ft_a
->fields
->len
, struct_ft_b
->fields
->len
);
4116 for (i
= 0; i
< struct_ft_a
->fields
->len
; ++i
) {
4117 struct structure_field_common
*field_a
=
4118 g_ptr_array_index(struct_ft_a
->fields
, i
);
4119 struct structure_field_common
*field_b
=
4120 g_ptr_array_index(struct_ft_b
->fields
, i
);
4122 ret
= compare_structure_fields(field_a
, field_b
);
4124 /* compare_structure_fields() logs what differs */
4125 BT_LOGV_STR("Structure field types differ: different fields.");
4138 int bt_field_type_common_variant_compare_recursive(
4139 struct bt_field_type_common
*ft_a
,
4140 struct bt_field_type_common
*ft_b
)
4144 struct bt_field_type_common_variant
*var_ft_a
= BT_FROM_COMMON(ft_a
);
4145 struct bt_field_type_common_variant
*var_ft_b
= BT_FROM_COMMON(ft_b
);
4148 if (strcmp(var_ft_a
->tag_name
->str
, var_ft_b
->tag_name
->str
)) {
4149 BT_LOGV("Variant field types differ: different tag field names: "
4150 "ft-a-tag-field-name=\"%s\", ft-b-tag-field-name=\"%s\"",
4151 var_ft_a
->tag_name
->str
, var_ft_b
->tag_name
->str
);
4156 ret
= bt_field_type_common_compare(BT_TO_COMMON(var_ft_a
->tag_ft
),
4157 BT_TO_COMMON(var_ft_b
->tag_ft
));
4159 BT_LOGV("Variant field types differ: different tag field types: "
4160 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
4161 var_ft_a
->tag_ft
, var_ft_b
->tag_ft
);
4168 if (var_ft_a
->fields
->len
!= var_ft_b
->fields
->len
) {
4169 BT_LOGV("Structure field types differ: different field counts: "
4170 "ft-a-field-count=%u, ft-b-field-count=%u",
4171 var_ft_a
->fields
->len
, var_ft_b
->fields
->len
);
4175 for (i
= 0; i
< var_ft_a
->fields
->len
; ++i
) {
4176 struct structure_field_common
*field_a
=
4177 g_ptr_array_index(var_ft_a
->fields
, i
);
4178 struct structure_field_common
*field_b
=
4179 g_ptr_array_index(var_ft_b
->fields
, i
);
4181 ret
= compare_structure_fields(field_a
, field_b
);
4183 /* compare_structure_fields() logs what differs */
4184 BT_LOGV_STR("Variant field types differ: different fields.");
4197 int bt_field_type_common_array_compare_recursive(
4198 struct bt_field_type_common
*ft_a
,
4199 struct bt_field_type_common
*ft_b
)
4202 struct bt_field_type_common_array
*array_ft_a
= BT_FROM_COMMON(ft_a
);
4203 struct bt_field_type_common_array
*array_ft_b
= BT_FROM_COMMON(ft_b
);
4206 if (array_ft_a
->length
!= array_ft_b
->length
) {
4207 BT_LOGV("Structure field types differ: different lengths: "
4208 "ft-a-length=%u, ft-b-length=%u",
4209 array_ft_a
->length
, array_ft_b
->length
);
4214 ret
= bt_field_type_common_compare(array_ft_a
->element_ft
,
4215 array_ft_b
->element_ft
);
4217 BT_LOGV("Array field types differ: different element field types: "
4218 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
4219 array_ft_a
->element_ft
, array_ft_b
->element_ft
);
4227 int bt_field_type_common_sequence_compare_recursive(
4228 struct bt_field_type_common
*ft_a
,
4229 struct bt_field_type_common
*ft_b
)
4232 struct bt_field_type_common_sequence
*seq_ft_a
= BT_FROM_COMMON(ft_a
);
4233 struct bt_field_type_common_sequence
*seq_ft_b
= BT_FROM_COMMON(ft_b
);
4236 if (strcmp(seq_ft_a
->length_field_name
->str
,
4237 seq_ft_b
->length_field_name
->str
)) {
4238 BT_LOGV("Sequence field types differ: different length field names: "
4239 "ft-a-length-field-name=\"%s\", "
4240 "ft-b-length-field-name=\"%s\"",
4241 seq_ft_a
->length_field_name
->str
,
4242 seq_ft_b
->length_field_name
->str
);
4247 ret
= bt_field_type_common_compare(seq_ft_a
->element_ft
,
4248 seq_ft_b
->element_ft
);
4250 BT_LOGV("Sequence field types differ: different element field types: "
4251 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
4252 seq_ft_a
->element_ft
, seq_ft_b
->element_ft
);
4260 int bt_field_type_common_compare(struct bt_field_type_common
*ft_a
,
4261 struct bt_field_type_common
*ft_b
)
4265 BT_ASSERT_PRE_NON_NULL(ft_a
, "Field type A");
4266 BT_ASSERT_PRE_NON_NULL(ft_b
, "Field type B");
4269 /* Same reference: equal (even if both are NULL) */
4275 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
4281 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
4286 if (ft_a
->id
!= ft_b
->id
) {
4287 /* Different type IDs */
4288 BT_LOGV("Field types differ: different IDs: "
4289 "ft-a-addr=%p, ft-b-addr=%p, "
4290 "ft-a-id=%s, ft-b-id=%s",
4292 bt_common_field_type_id_string(ft_a
->id
),
4293 bt_common_field_type_id_string(ft_b
->id
));
4297 if (ft_a
->id
== BT_FIELD_TYPE_ID_UNKNOWN
) {
4298 /* Both have unknown type IDs */
4299 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
4303 BT_ASSERT(ft_a
->methods
->compare
);
4304 ret
= ft_a
->methods
->compare(ft_a
, ft_b
);
4306 BT_LOGV("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
4314 int bt_field_type_compare(struct bt_field_type
*ft_a
,
4315 struct bt_field_type
*ft_b
)
4317 return bt_field_type_common_compare((void *) ft_a
, (void *) ft_b
);
4321 int64_t bt_field_type_common_get_field_count(struct bt_field_type_common
*ft
)
4323 int64_t field_count
= -1;
4326 case BT_FIELD_TYPE_ID_STRUCT
:
4328 bt_field_type_common_structure_get_field_count(ft
);
4330 case BT_FIELD_TYPE_ID_VARIANT
:
4332 bt_field_type_common_variant_get_field_count(ft
);
4334 case BT_FIELD_TYPE_ID_ARRAY
:
4335 case BT_FIELD_TYPE_ID_SEQUENCE
:
4337 * Array and sequence types always contain a single member
4338 * (the element type).
4350 struct bt_field_type_common
*bt_field_type_common_borrow_field_at_index(
4351 struct bt_field_type_common
*ft
, int index
)
4353 struct bt_field_type_common
*field_type
= NULL
;
4356 case BT_FIELD_TYPE_ID_STRUCT
:
4358 int ret
= bt_field_type_common_structure_borrow_field_by_index(
4359 ft
, NULL
, &field_type
, index
);
4366 case BT_FIELD_TYPE_ID_VARIANT
:
4368 int ret
= bt_field_type_common_variant_borrow_field_by_index(
4369 ft
, NULL
, &field_type
, index
);
4376 case BT_FIELD_TYPE_ID_ARRAY
:
4378 bt_field_type_common_array_borrow_element_field_type(ft
);
4380 case BT_FIELD_TYPE_ID_SEQUENCE
:
4382 bt_field_type_common_sequence_borrow_element_field_type(ft
);
4393 int bt_field_type_common_get_field_index(struct bt_field_type_common
*ft
,
4396 int field_index
= -1;
4399 case BT_FIELD_TYPE_ID_STRUCT
:
4400 field_index
= bt_field_type_common_structure_get_field_name_index(
4403 case BT_FIELD_TYPE_ID_VARIANT
:
4404 field_index
= bt_field_type_common_variant_get_field_name_index(
4415 struct bt_field_path
*bt_field_type_common_variant_borrow_tag_field_path(
4416 struct bt_field_type_common
*ft
)
4418 struct bt_field_type_common_variant
*var_ft
= BT_FROM_COMMON(ft
);
4420 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
4421 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_VARIANT
,
4423 return var_ft
->tag_field_path
;
4426 struct bt_field_path
*bt_field_type_variant_borrow_tag_field_path(
4427 struct bt_field_type
*ft
)
4429 return bt_field_type_common_variant_borrow_tag_field_path((void *) ft
);
4433 struct bt_field_path
*bt_field_type_common_sequence_borrow_length_field_path(
4434 struct bt_field_type_common
*ft
)
4436 struct bt_field_type_common_sequence
*seq_ft
= BT_FROM_COMMON(ft
);
4438 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
4439 BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft
, BT_FIELD_TYPE_ID_SEQUENCE
,
4441 return seq_ft
->length_field_path
;
4444 struct bt_field_path
*bt_field_type_sequence_borrow_length_field_path(
4445 struct bt_field_type
*ft
)
4447 return bt_field_type_common_sequence_borrow_length_field_path(
4452 int bt_field_type_common_validate_single_clock_class(
4453 struct bt_field_type_common
*ft
,
4454 struct bt_clock_class
**expected_clock_class
)
4462 BT_ASSERT(expected_clock_class
);
4465 case BT_FIELD_TYPE_ID_INTEGER
:
4467 struct bt_clock_class
*mapped_clock_class
=
4468 bt_field_type_common_integer_borrow_mapped_clock_class(ft
);
4470 if (!mapped_clock_class
) {
4474 if (!*expected_clock_class
) {
4475 /* Move reference to output parameter */
4476 *expected_clock_class
= bt_get(mapped_clock_class
);
4477 mapped_clock_class
= NULL
;
4478 BT_LOGV("Setting expected clock class: "
4479 "expected-clock-class-addr=%p",
4480 *expected_clock_class
);
4482 if (mapped_clock_class
!= *expected_clock_class
) {
4483 BT_LOGW("Integer field type is not mapped to "
4484 "the expected clock class: "
4485 "mapped-clock-class-addr=%p, "
4486 "mapped-clock-class-name=\"%s\", "
4487 "expected-clock-class-addr=%p, "
4488 "expected-clock-class-name=\"%s\"",
4490 bt_clock_class_get_name(mapped_clock_class
),
4491 *expected_clock_class
,
4492 bt_clock_class_get_name(*expected_clock_class
));
4493 bt_put(mapped_clock_class
);
4501 case BT_FIELD_TYPE_ID_ENUM
:
4502 case BT_FIELD_TYPE_ID_ARRAY
:
4503 case BT_FIELD_TYPE_ID_SEQUENCE
:
4505 struct bt_field_type_common
*sub_ft
= NULL
;
4508 case BT_FIELD_TYPE_ID_ENUM
:
4509 sub_ft
= bt_field_type_common_enumeration_borrow_container_field_type(
4512 case BT_FIELD_TYPE_ID_ARRAY
:
4513 sub_ft
= bt_field_type_common_array_borrow_element_field_type(
4516 case BT_FIELD_TYPE_ID_SEQUENCE
:
4517 sub_ft
= bt_field_type_common_sequence_borrow_element_field_type(
4521 BT_LOGF("Unexpected field type ID: id=%d", ft
->id
);
4526 ret
= bt_field_type_common_validate_single_clock_class(sub_ft
,
4527 expected_clock_class
);
4530 case BT_FIELD_TYPE_ID_STRUCT
:
4533 int64_t count
= bt_field_type_common_structure_get_field_count(
4536 for (i
= 0; i
< count
; i
++) {
4538 struct bt_field_type_common
*member_type
;
4540 ret
= bt_field_type_common_structure_borrow_field_by_index(
4541 ft
, &name
, &member_type
, i
);
4542 BT_ASSERT(ret
== 0);
4543 ret
= bt_field_type_common_validate_single_clock_class(
4544 member_type
, expected_clock_class
);
4546 BT_LOGW("Structure field type's field's type "
4547 "is not recursively mapped to the "
4548 "expected clock class: "
4549 "field-ft-addr=%p, field-name=\"%s\"",
4556 case BT_FIELD_TYPE_ID_VARIANT
:
4559 int64_t count
= bt_field_type_common_variant_get_field_count(
4562 for (i
= 0; i
< count
; i
++) {
4564 struct bt_field_type_common
*member_type
;
4566 ret
= bt_field_type_common_variant_borrow_field_by_index(
4567 ft
, &name
, &member_type
, i
);
4568 BT_ASSERT(ret
== 0);
4569 ret
= bt_field_type_common_validate_single_clock_class(
4570 member_type
, expected_clock_class
);
4572 BT_LOGW("Variant field type's field's type "
4573 "is not recursively mapped to the "
4574 "expected clock class: "
4575 "field-ft-addr=%p, field-name=\"%s\"",
4591 struct bt_field_type
*bt_field_type_integer_copy(
4592 struct bt_field_type
*ft
)
4594 struct bt_field_type_common_integer
*int_ft
= (void *) ft
;
4595 struct bt_field_type_common_integer
*copy_ft
;
4597 BT_LOGD("Copying CTF writer integer field type's: addr=%p", ft
);
4598 copy_ft
= (void *) bt_field_type_integer_create(int_ft
->size
);
4600 BT_LOGE_STR("Cannot create CTF writer integer field type.");
4604 copy_ft
->mapped_clock_class
= bt_get(int_ft
->mapped_clock_class
);
4605 copy_ft
->user_byte_order
= int_ft
->user_byte_order
;
4606 copy_ft
->is_signed
= int_ft
->is_signed
;
4607 copy_ft
->size
= int_ft
->size
;
4608 copy_ft
->base
= int_ft
->base
;
4609 copy_ft
->encoding
= int_ft
->encoding
;
4610 BT_LOGD("Copied CTF writer integer field type: original-ft-addr=%p, copy-ft-addr=%p",
4614 return (void *) copy_ft
;
4618 struct bt_field_type
*bt_field_type_enumeration_copy_recursive(
4619 struct bt_field_type
*ft
)
4622 struct bt_field_type_common_enumeration
*enum_ft
= (void *) ft
;
4623 struct bt_field_type_common_enumeration
*copy_ft
= NULL
;
4624 struct bt_field_type_common_enumeration
*container_copy_ft
;
4626 BT_LOGD("Copying CTF writer enumeration field type's: addr=%p", ft
);
4628 /* Copy the source enumeration's container */
4629 BT_LOGD_STR("Copying CTF writer enumeration field type's container field type.");
4630 container_copy_ft
= BT_FROM_COMMON(bt_field_type_common_copy(
4631 BT_TO_COMMON(enum_ft
->container_ft
)));
4632 if (!container_copy_ft
) {
4633 BT_LOGE_STR("Cannot copy CTF writer enumeration field type's container field type.");
4637 copy_ft
= (void *) bt_field_type_enumeration_create(
4638 (void *) container_copy_ft
);
4640 BT_LOGE_STR("Cannot create CTF writer enumeration field type.");
4644 /* Copy all enumaration entries */
4645 for (i
= 0; i
< enum_ft
->entries
->len
; i
++) {
4646 struct enumeration_mapping
*mapping
= g_ptr_array_index(
4647 enum_ft
->entries
, i
);
4648 struct enumeration_mapping
*copy_mapping
= g_new0(
4649 struct enumeration_mapping
, 1);
4651 if (!copy_mapping
) {
4652 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
4656 *copy_mapping
= *mapping
;
4657 g_ptr_array_add(copy_ft
->entries
, copy_mapping
);
4660 BT_LOGD("Copied CTF writer enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
4664 bt_put(container_copy_ft
);
4665 return (void *) copy_ft
;
4668 bt_put(container_copy_ft
);
4670 return (void *) copy_ft
;
4674 struct bt_field_type
*bt_field_type_floating_point_copy(
4675 struct bt_field_type
*ft
)
4677 struct bt_field_type_common_floating_point
*flt_ft
= BT_FROM_COMMON(ft
);
4678 struct bt_field_type_common_floating_point
*copy_ft
;
4680 BT_LOGD("Copying CTF writer floating point number field type's: addr=%p", ft
);
4681 copy_ft
= (void *) bt_field_type_floating_point_create();
4683 BT_LOGE_STR("Cannot create CTF writer floating point number field type.");
4687 copy_ft
->user_byte_order
= flt_ft
->user_byte_order
;
4688 copy_ft
->exp_dig
= flt_ft
->exp_dig
;
4689 copy_ft
->mant_dig
= flt_ft
->mant_dig
;
4690 BT_LOGD("Copied CTF writer floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
4694 return (void *) copy_ft
;
4698 struct bt_field_type
*bt_field_type_structure_copy_recursive(
4699 struct bt_field_type
*ft
)
4702 GHashTableIter iter
;
4703 gpointer key
, value
;
4704 struct bt_field_type_common_structure
*struct_ft
= (void *) ft
;
4705 struct bt_field_type_common_structure
*copy_ft
;
4707 BT_LOGD("Copying CTF writer structure field type's: addr=%p", ft
);
4708 copy_ft
= (void *) bt_field_type_structure_create();
4710 BT_LOGE_STR("Cannot create CTF writer structure field type.");
4714 /* Copy field_name_to_index */
4715 g_hash_table_iter_init(&iter
, struct_ft
->field_name_to_index
);
4716 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
4717 g_hash_table_insert(copy_ft
->field_name_to_index
,
4721 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
4722 struct structure_field_common
*entry
, *copy_entry
;
4723 struct bt_field_type_common
*field_ft_copy
;
4725 entry
= g_ptr_array_index(struct_ft
->fields
, i
);
4726 BT_LOGD("Copying CTF writer structure field type's field: "
4727 "index=%" PRId64
", "
4728 "field-ft-addr=%p, field-name=\"%s\"",
4729 i
, entry
, g_quark_to_string(entry
->name
));
4730 copy_entry
= g_new0(struct structure_field_common
, 1);
4732 BT_LOGE_STR("Failed to allocate one structure field type field.");
4736 field_ft_copy
= (void *) bt_field_type_copy(
4737 (void *) entry
->type
);
4738 if (!field_ft_copy
) {
4739 BT_LOGE("Cannot copy CTF writer structure field type's field: "
4740 "index=%" PRId64
", "
4741 "field-ft-addr=%p, field-name=\"%s\"",
4742 i
, entry
, g_quark_to_string(entry
->name
));
4747 copy_entry
->name
= entry
->name
;
4748 copy_entry
->type
= field_ft_copy
;
4749 g_ptr_array_add(copy_ft
->fields
, copy_entry
);
4752 BT_LOGD("Copied CTF writer structure field type: original-ft-addr=%p, copy-ft-addr=%p",
4756 return (void *) copy_ft
;
4764 struct bt_field_type
*bt_field_type_variant_copy_recursive(
4765 struct bt_field_type
*ft
)
4768 GHashTableIter iter
;
4769 gpointer key
, value
;
4770 struct bt_field_type_common
*tag_ft_copy
= NULL
;
4771 struct bt_field_type_common_variant
*var_ft
= (void *) ft
;
4772 struct bt_field_type_common_variant
*copy_ft
= NULL
;
4774 BT_LOGD("Copying CTF writer variant field type's: addr=%p", ft
);
4775 if (var_ft
->tag_ft
) {
4776 BT_LOGD_STR("Copying CTF writer variant field type's tag field type.");
4777 tag_ft_copy
= bt_field_type_common_copy(
4778 BT_TO_COMMON(var_ft
->tag_ft
));
4780 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field type.");
4785 copy_ft
= (void *) bt_field_type_variant_create(
4786 (void *) tag_ft_copy
,
4787 var_ft
->tag_name
->len
? var_ft
->tag_name
->str
: NULL
);
4789 BT_LOGE_STR("Cannot create CTF writer variant field type.");
4793 /* Copy field_name_to_index */
4794 g_hash_table_iter_init(&iter
, var_ft
->field_name_to_index
);
4795 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
4796 g_hash_table_insert(copy_ft
->field_name_to_index
,
4800 for (i
= 0; i
< var_ft
->fields
->len
; i
++) {
4801 struct structure_field_common
*entry
, *copy_entry
;
4802 struct bt_field_type_common
*field_ft_copy
;
4804 entry
= g_ptr_array_index(var_ft
->fields
, i
);
4805 BT_LOGD("Copying CTF writer variant field type's field: "
4806 "index=%" PRId64
", "
4807 "field-ft-addr=%p, field-name=\"%s\"",
4808 i
, entry
, g_quark_to_string(entry
->name
));
4809 copy_entry
= g_new0(struct structure_field_common
, 1);
4811 BT_LOGE_STR("Failed to allocate one variant field type field.");
4815 field_ft_copy
= (void *) bt_field_type_copy(
4816 (void *) entry
->type
);
4817 if (!field_ft_copy
) {
4818 BT_LOGE("Cannot copy CTF writer variant field type's field: "
4819 "index=%" PRId64
", "
4820 "field-ft-addr=%p, field-name=\"%s\"",
4821 i
, entry
, g_quark_to_string(entry
->name
));
4826 copy_entry
->name
= entry
->name
;
4827 copy_entry
->type
= field_ft_copy
;
4828 g_ptr_array_add(copy_ft
->fields
, copy_entry
);
4831 if (var_ft
->tag_field_path
) {
4832 BT_LOGD_STR("Copying CTF writer variant field type's tag field path.");
4833 copy_ft
->tag_field_path
= bt_field_path_copy(
4834 var_ft
->tag_field_path
);
4835 if (!copy_ft
->tag_field_path
) {
4836 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field path.");
4841 BT_LOGD("Copied variant field type: original-ft-addr=%p, copy-ft-addr=%p",
4845 bt_put(tag_ft_copy
);
4846 return (void *) copy_ft
;
4849 bt_put(tag_ft_copy
);
4855 struct bt_field_type
*bt_field_type_array_copy_recursive(
4856 struct bt_field_type
*ft
)
4858 struct bt_field_type_common
*container_ft_copy
= NULL
;
4859 struct bt_field_type_common_array
*array_ft
= (void *) ft
;
4860 struct bt_field_type_common_array
*copy_ft
= NULL
;
4862 BT_LOGD("Copying CTF writer array field type's: addr=%p", ft
);
4863 BT_LOGD_STR("Copying CTF writer array field type's element field type.");
4864 container_ft_copy
= bt_field_type_common_copy(array_ft
->element_ft
);
4865 if (!container_ft_copy
) {
4866 BT_LOGE_STR("Cannot copy CTF writer array field type's element field type.");
4870 copy_ft
= (void *) bt_field_type_array_create(
4871 (void *) container_ft_copy
, array_ft
->length
);
4873 BT_LOGE_STR("Cannot create CTF writer array field type.");
4877 BT_LOGD("Copied CTF writer array field type: original-ft-addr=%p, copy-ft-addr=%p",
4881 bt_put(container_ft_copy
);
4882 return (void *) copy_ft
;
4886 struct bt_field_type
*bt_field_type_sequence_copy_recursive(
4887 struct bt_field_type
*ft
)
4889 struct bt_field_type_common
*container_ft_copy
= NULL
;
4890 struct bt_field_type_common_sequence
*seq_ft
= (void *) ft
;
4891 struct bt_field_type_common_sequence
*copy_ft
= NULL
;
4893 BT_LOGD("Copying CTF writer sequence field type's: addr=%p", ft
);
4894 BT_LOGD_STR("Copying CTF writer sequence field type's element field type.");
4895 container_ft_copy
= bt_field_type_common_copy(seq_ft
->element_ft
);
4896 if (!container_ft_copy
) {
4897 BT_LOGE_STR("Cannot copy CTF writer sequence field type's element field type.");
4901 copy_ft
= (void *) bt_field_type_sequence_create(
4902 (void *) container_ft_copy
,
4903 seq_ft
->length_field_name
->len
?
4904 seq_ft
->length_field_name
->str
: NULL
);
4906 BT_LOGE_STR("Cannot create CTF writer sequence field type.");
4910 if (seq_ft
->length_field_path
) {
4911 BT_LOGD_STR("Copying CTF writer sequence field type's length field path.");
4912 copy_ft
->length_field_path
= bt_field_path_copy(
4913 seq_ft
->length_field_path
);
4914 if (!copy_ft
->length_field_path
) {
4915 BT_LOGE_STR("Cannot copy CTF writer sequence field type's length field path.");
4920 BT_LOGD("Copied CTF writer sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
4924 bt_put(container_ft_copy
);
4925 return (void *) copy_ft
;
4927 bt_put(container_ft_copy
);
4933 struct bt_field_type
*bt_field_type_string_copy(struct bt_field_type
*ft
)
4935 struct bt_field_type_common_string
*string_ft
= (void *) ft
;
4936 struct bt_field_type_common_string
*copy_ft
= NULL
;
4938 BT_LOGD("Copying CTF writer string field type's: addr=%p", ft
);
4939 copy_ft
= (void *) bt_field_type_string_create();
4941 BT_LOGE_STR("Cannot create CTF writer string field type.");
4945 copy_ft
->encoding
= string_ft
->encoding
;
4946 BT_LOGD("Copied CTF writer string field type: original-ft-addr=%p, copy-ft-addr=%p",
4950 return (void *) copy_ft
;