1 #ifndef BABELTRACE_CTF_IR_FIELDS_INTERNAL_H
2 #define BABELTRACE_CTF_IR_FIELDS_INTERNAL_H
5 * Babeltrace - CTF IR: Event Fields internal
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include <babeltrace/assert-pre-internal.h>
31 #include <babeltrace/common-internal.h>
32 #include <babeltrace/ctf-ir/field-types-internal.h>
33 #include <babeltrace/ctf-ir/utils-internal.h>
34 #include <babeltrace/object-internal.h>
35 #include <babeltrace/babeltrace-internal.h>
36 #include <babeltrace/types.h>
42 #define BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(_field, _type_id, _name) \
43 BT_ASSERT_PRE((_field)->type->id == ((int) (_type_id)), \
44 _name " has the wrong type ID: expected-type-id=%s, " \
46 bt_common_field_type_id_string((int) (_type_id)), (_field))
48 #define BT_ASSERT_PRE_FIELD_COMMON_IS_SET(_field, _name) \
49 BT_ASSERT_PRE(bt_field_common_is_set_recursive(_field), \
50 _name " is not set: %!+_f", (_field))
52 #define BT_ASSERT_PRE_FIELD_COMMON_HOT(_field, _name) \
53 BT_ASSERT_PRE_HOT((_field), (_name), ": +%!+_f", (_field))
56 struct bt_field_common
;
58 typedef void (*bt_field_common_method_set_is_frozen
)(struct bt_field_common
*,
60 typedef int (*bt_field_common_method_validate
)(struct bt_field_common
*);
61 typedef struct bt_field_common
*(*bt_field_common_method_copy
)(
62 struct bt_field_common
*);
63 typedef bt_bool (*bt_field_common_method_is_set
)(struct bt_field_common
*);
64 typedef void (*bt_field_common_method_reset
)(struct bt_field_common
*);
66 struct bt_field_common_methods
{
67 bt_field_common_method_set_is_frozen set_is_frozen
;
68 bt_field_common_method_validate validate
;
69 bt_field_common_method_copy copy
;
70 bt_field_common_method_is_set is_set
;
71 bt_field_common_method_reset reset
;
74 struct bt_field_common
{
75 struct bt_object base
;
76 struct bt_field_type_common
*type
;
77 struct bt_field_common_methods
*methods
;
82 * Specialized data for either CTF IR or CTF writer APIs.
83 * See comment in `field-types-internal.h` for more details.
94 struct bt_field_common_integer
{
95 struct bt_field_common common
;
102 struct bt_field_common_floating_point
{
103 struct bt_field_common common
;
107 struct bt_field_common_structure
{
108 struct bt_field_common common
;
110 /* Array of `struct bt_field_common *`, owned by this */
114 struct bt_field_common_variant
{
115 struct bt_field_common common
;
122 /* Weak: belongs to `choices` below */
123 struct bt_field_common
*current_field
;
125 /* Array of `struct bt_field_common *`, owned by this */
129 struct bt_field_common_array
{
130 struct bt_field_common common
;
132 /* Array of `struct bt_field_common *`, owned by this */
136 struct bt_field_common_sequence
{
137 struct bt_field_common common
;
140 * This is the true sequence field's length: its value can be
141 * less than `elements->len` below because we never shrink the
142 * array of elements to avoid reallocation.
146 /* Array of `struct bt_field_common *`, owned by this */
150 struct bt_field_common_string
{
151 struct bt_field_common common
;
155 struct bt_field_enumeration
{
156 struct bt_field_common_integer common
;
160 struct bt_field_common
*bt_field_common_copy(struct bt_field_common
*field
);
163 int bt_field_common_structure_initialize(struct bt_field_common
*field
,
164 struct bt_field_type_common
*type
,
165 bt_object_release_func release_func
,
166 struct bt_field_common_methods
*methods
,
167 bt_field_common_create_func field_create_func
,
168 GDestroyNotify field_release_func
);
171 int bt_field_common_array_initialize(struct bt_field_common
*field
,
172 struct bt_field_type_common
*type
,
173 bt_object_release_func release_func
,
174 struct bt_field_common_methods
*methods
,
175 bt_field_common_create_func field_create_func
,
176 GDestroyNotify field_destroy_func
);
179 int bt_field_common_sequence_initialize(struct bt_field_common
*field
,
180 struct bt_field_type_common
*type
,
181 bt_object_release_func release_func
,
182 struct bt_field_common_methods
*methods
,
183 GDestroyNotify field_destroy_func
);
186 int bt_field_common_variant_initialize(struct bt_field_common
*field
,
187 struct bt_field_type_common
*type
,
188 bt_object_release_func release_func
,
189 struct bt_field_common_methods
*methods
,
190 bt_field_common_create_func field_create_func
,
191 GDestroyNotify field_release_func
);
194 int bt_field_common_generic_validate(struct bt_field_common
*field
);
197 int bt_field_common_structure_validate_recursive(struct bt_field_common
*field
);
200 int bt_field_common_variant_validate_recursive(struct bt_field_common
*field
);
203 int bt_field_common_array_validate_recursive(struct bt_field_common
*field
);
206 int bt_field_common_sequence_validate_recursive(struct bt_field_common
*field
);
209 void bt_field_common_generic_reset(struct bt_field_common
*field
);
212 void bt_field_common_structure_reset_recursive(struct bt_field_common
*field
);
215 void bt_field_common_variant_reset_recursive(struct bt_field_common
*field
);
218 void bt_field_common_array_reset_recursive(struct bt_field_common
*field
);
221 void bt_field_common_sequence_reset_recursive(struct bt_field_common
*field
);
224 void bt_field_common_string_reset(struct bt_field_common
*field
);
227 void bt_field_common_generic_set_is_frozen(struct bt_field_common
*field
,
231 void bt_field_common_structure_set_is_frozen_recursive(
232 struct bt_field_common
*field
, bool is_frozen
);
235 void bt_field_common_variant_set_is_frozen_recursive(
236 struct bt_field_common
*field
, bool is_frozen
);
239 void bt_field_common_array_set_is_frozen_recursive(
240 struct bt_field_common
*field
, bool is_frozen
);
243 void bt_field_common_sequence_set_is_frozen_recursive(
244 struct bt_field_common
*field
, bool is_frozen
);
247 void _bt_field_common_set_is_frozen_recursive(struct bt_field_common
*field
,
251 bt_bool
bt_field_common_generic_is_set(struct bt_field_common
*field
);
254 bt_bool
bt_field_common_structure_is_set_recursive(
255 struct bt_field_common
*field
);
258 bt_bool
bt_field_common_variant_is_set_recursive(struct bt_field_common
*field
);
261 bt_bool
bt_field_common_array_is_set_recursive(struct bt_field_common
*field
);
264 bt_bool
bt_field_common_sequence_is_set_recursive(struct bt_field_common
*field
);
267 # define bt_field_common_validate_recursive _bt_field_common_validate_recursive
268 # define bt_field_common_set_is_frozen_recursive _bt_field_common_set_is_frozen_recursive
269 # define bt_field_common_is_set_recursive _bt_field_common_is_set_recursive
270 # define bt_field_common_reset_recursive _bt_field_common_reset_recursive
271 # define bt_field_common_set _bt_field_common_set
272 # define bt_field_validate_recursive _bt_field_validate_recursive
273 # define bt_field_set_is_frozen_recursive _bt_field_set_is_frozen_recursive
274 # define bt_field_is_set_recursive _bt_field_is_set_recursive
275 # define bt_field_reset_recursive _bt_field_reset_recursive
276 # define bt_field_set _bt_field_set
278 # define bt_field_common_validate_recursive(_field) (-1)
279 # define bt_field_common_set_is_frozen_recursive(_field, _is_frozen)
280 # define bt_field_common_is_set_recursive(_field) (BT_FALSE)
281 # define bt_field_common_reset_recursive(_field)
282 # define bt_field_common_set(_field, _val)
283 # define bt_field_validate_recursive(_field) (-1)
284 # define bt_field_set_is_frozen_recursive(_field, _is_frozen)
285 # define bt_field_is_set_recursive(_field) (BT_FALSE)
286 # define bt_field_reset_recursive(_field)
287 # define bt_field_set(_field, _val)
291 static inline bool field_type_common_has_known_id(
292 struct bt_field_type_common
*ft
)
294 return (int) ft
->id
> BT_FIELD_TYPE_ID_UNKNOWN
||
295 (int) ft
->id
< BT_FIELD_TYPE_ID_NR
;
299 int _bt_field_common_validate_recursive(struct bt_field_common
*field
)
304 BT_ASSERT_PRE_MSG("%s", "Invalid field: field is NULL.");
309 BT_ASSERT(field_type_common_has_known_id(field
->type
));
311 if (field
->methods
->validate
) {
312 ret
= field
->methods
->validate(field
);
320 void _bt_field_common_reset_recursive(struct bt_field_common
*field
)
323 BT_ASSERT(field
->methods
->reset
);
324 field
->methods
->reset(field
);
328 void _bt_field_common_set(struct bt_field_common
*field
, bool value
)
331 field
->payload_set
= value
;
335 bt_bool
_bt_field_common_is_set_recursive(struct bt_field_common
*field
)
337 bt_bool is_set
= BT_FALSE
;
343 BT_ASSERT(field_type_common_has_known_id(field
->type
));
344 BT_ASSERT(field
->methods
->is_set
);
345 is_set
= field
->methods
->is_set(field
);
352 void bt_field_common_initialize(struct bt_field_common
*field
,
353 struct bt_field_type_common
*ft
,
354 bt_object_release_func release_func
,
355 struct bt_field_common_methods
*methods
)
359 bt_object_init(field
, release_func
);
360 field
->methods
= methods
;
361 field
->type
= bt_get(ft
);
365 struct bt_field_type_common
*bt_field_common_borrow_type(
366 struct bt_field_common
*field
)
368 struct bt_field_type_common
*ret
= NULL
;
370 BT_ASSERT_PRE_NON_NULL(field
, "Field");
376 int64_t bt_field_common_sequence_get_length(struct bt_field_common
*field
)
378 struct bt_field_common_sequence
*sequence
= BT_FROM_COMMON(field
);
380 BT_ASSERT_PRE_NON_NULL(field
, "Sequence field");
381 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
, BT_FIELD_TYPE_ID_SEQUENCE
,
383 return (int64_t) sequence
->length
;
387 int bt_field_common_sequence_set_length(struct bt_field_common
*field
,
388 uint64_t length
, bt_field_common_create_func field_create_func
)
391 struct bt_field_common_sequence
*sequence
= BT_FROM_COMMON(field
);
393 BT_ASSERT_PRE_NON_NULL(field
, "Sequence field");
394 BT_ASSERT_PRE_FIELD_COMMON_HOT(field
, "Sequence field");
396 if (length
> sequence
->elements
->len
) {
398 struct bt_field_type_common_sequence
*sequence_ft
;
399 uint64_t cur_len
= sequence
->elements
->len
;
402 g_ptr_array_set_size(sequence
->elements
, length
);
403 sequence_ft
= BT_FROM_COMMON(sequence
->common
.type
);
405 for (i
= cur_len
; i
< sequence
->elements
->len
; i
++) {
406 struct bt_field_common
*elem_field
=
407 field_create_func(sequence_ft
->element_ft
);
414 BT_ASSERT(!sequence
->elements
->pdata
[i
]);
415 sequence
->elements
->pdata
[i
] = elem_field
;
419 sequence
->length
= length
;
426 struct bt_field_common
*bt_field_common_structure_borrow_field_by_name(
427 struct bt_field_common
*field
, const char *name
)
429 struct bt_field_common
*ret
= NULL
;
431 struct bt_field_type_common_structure
*structure_ft
;
432 struct bt_field_common_structure
*structure
= BT_FROM_COMMON(field
);
434 GHashTable
*field_name_to_index
;
436 BT_ASSERT_PRE_NON_NULL(field
, "Structure field");
437 BT_ASSERT_PRE_NON_NULL(name
, "Field name");
438 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
439 BT_FIELD_TYPE_ID_STRUCT
, "Field");
440 structure_ft
= BT_FROM_COMMON(field
->type
);
441 field_name_to_index
= structure_ft
->field_name_to_index
;
442 field_quark
= g_quark_from_string(name
);
443 if (!g_hash_table_lookup_extended(field_name_to_index
,
444 GUINT_TO_POINTER(field_quark
),
445 NULL
, (gpointer
*) &index
)) {
446 BT_LOGV("Invalid parameter: no such field in structure field's type: "
447 "struct-field-addr=%p, struct-ft-addr=%p, name=\"%s\"",
448 field
, field
->type
, name
);
452 ret
= structure
->fields
->pdata
[index
];
460 struct bt_field_common
*bt_field_common_structure_borrow_field_by_index(
461 struct bt_field_common
*field
, uint64_t index
)
463 struct bt_field_common_structure
*structure
= BT_FROM_COMMON(field
);
465 BT_ASSERT_PRE_NON_NULL(field
, "Structure field");
466 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
467 BT_FIELD_TYPE_ID_STRUCT
, "Field");
468 BT_ASSERT_PRE(index
< structure
->fields
->len
,
469 "Index is out of bound: %![struct-field-]+_f, "
470 "index=%" PRIu64
", count=%u", field
, index
,
471 structure
->fields
->len
);
472 return structure
->fields
->pdata
[index
];
476 struct bt_field_common
*bt_field_common_array_borrow_field(
477 struct bt_field_common
*field
, uint64_t index
)
479 struct bt_field_common_array
*array
= BT_FROM_COMMON(field
);
481 BT_ASSERT_PRE_NON_NULL(field
, "Array field");
482 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
, BT_FIELD_TYPE_ID_ARRAY
,
484 BT_ASSERT_PRE(index
< array
->elements
->len
,
485 "Index is out of bound: %![array-field-]+_f, "
486 "index=%" PRIu64
", count=%u", field
,
487 index
, array
->elements
->len
);
488 return array
->elements
->pdata
[(size_t) index
];
492 struct bt_field_common
*bt_field_common_sequence_borrow_field(
493 struct bt_field_common
*field
, uint64_t index
)
495 struct bt_field_common_sequence
*sequence
= BT_FROM_COMMON(field
);
497 BT_ASSERT_PRE_NON_NULL(field
, "Sequence field");
498 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
, BT_FIELD_TYPE_ID_SEQUENCE
,
500 BT_ASSERT_PRE(index
< sequence
->length
,
501 "Index is out of bound: %![seq-field-]+_f, "
502 "index=%" PRIu64
", count=%u", field
, index
,
503 sequence
->elements
->len
);
504 return sequence
->elements
->pdata
[(size_t) index
];
508 int bt_field_variant_common_set_tag(struct bt_field_common
*variant_field
,
509 uint64_t tag_uval
, bool is_signed
)
512 int64_t choice_index
;
513 struct bt_field_common_variant
*variant
= BT_FROM_COMMON(variant_field
);
515 BT_ASSERT_PRE_NON_NULL(variant_field
, "Variant field");
516 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(variant_field
,
517 BT_FIELD_TYPE_ID_VARIANT
, "Field");
519 /* Find matching index in variant field's type */
520 choice_index
= bt_field_type_common_variant_find_choice_index(
521 variant_field
->type
, tag_uval
, is_signed
);
522 if (choice_index
< 0) {
527 /* Select corresponding field */
528 BT_ASSERT(choice_index
< variant
->fields
->len
);
529 variant
->current_field
= variant
->fields
->pdata
[choice_index
];
530 variant
->tag_value
.u
= tag_uval
;
537 struct bt_field_common
*bt_field_common_variant_borrow_current_field(
538 struct bt_field_common
*variant_field
)
540 struct bt_field_common_variant
*variant
= BT_FROM_COMMON(variant_field
);
542 BT_ASSERT_PRE_NON_NULL(variant_field
, "Variant field");
543 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(variant_field
,
544 BT_FIELD_TYPE_ID_VARIANT
, "Field");
545 BT_ASSERT_PRE(variant
->current_field
,
546 "Variant field has no current field: %!+_f", variant_field
);
547 return variant
->current_field
;
551 int bt_field_common_variant_get_tag_signed(struct bt_field_common
*variant_field
,
554 struct bt_field_common_variant
*variant
= BT_FROM_COMMON(variant_field
);
556 BT_ASSERT_PRE_NON_NULL(variant_field
, "Variant field");
557 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(variant_field
,
558 BT_FIELD_TYPE_ID_VARIANT
, "Field");
559 BT_ASSERT_PRE(variant
->current_field
,
560 "Variant field has no current field: %!+_f", variant_field
);
561 *tag
= variant
->tag_value
.i
;
566 int bt_field_common_variant_get_tag_unsigned(struct bt_field_common
*variant_field
,
569 struct bt_field_common_variant
*variant
= BT_FROM_COMMON(variant_field
);
571 BT_ASSERT_PRE_NON_NULL(variant_field
, "Variant field");
572 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(variant_field
,
573 BT_FIELD_TYPE_ID_VARIANT
, "Field");
574 BT_ASSERT_PRE(variant
->current_field
,
575 "Variant field has no current field: %!+_f", variant_field
);
576 *tag
= variant
->tag_value
.u
;
581 struct bt_field_type_enumeration_mapping_iterator
*
582 bt_field_common_enumeration_get_mappings(struct bt_field_common
*field
,
583 bt_field_common_create_func field_create_func
,
586 struct bt_field_type_common_enumeration
*enum_type
= NULL
;
587 struct bt_field_type_common_integer
*integer_type
= NULL
;
588 struct bt_field_type_enumeration_mapping_iterator
*iter
= NULL
;
591 BT_ASSERT(field
->type
->id
== BT_FIELD_TYPE_ID_ENUM
);
592 BT_ASSERT(field
->payload_set
);
593 enum_type
= BT_FROM_COMMON(field
->type
);
594 integer_type
= enum_type
->container_ft
;
596 if (!integer_type
->is_signed
) {
597 iter
= bt_field_type_common_enumeration_unsigned_find_mappings_by_value(
600 iter
= bt_field_type_common_enumeration_signed_find_mappings_by_value(
601 field
->type
, (int64_t) uval
);
608 int bt_field_common_floating_point_get_value(struct bt_field_common
*field
,
611 struct bt_field_common_floating_point
*floating_point
=
612 BT_FROM_COMMON(field
);
614 BT_ASSERT_PRE_NON_NULL(field
, "Floating point number field");
615 BT_ASSERT_PRE_NON_NULL(value
, "Value");
616 BT_ASSERT_PRE_FIELD_COMMON_IS_SET(field
, "Floating point number field");
617 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
618 BT_FIELD_TYPE_ID_FLOAT
, "Field");
619 *value
= floating_point
->payload
;
624 int bt_field_common_floating_point_set_value(struct bt_field_common
*field
,
627 struct bt_field_common_floating_point
*floating_point
=
628 BT_FROM_COMMON(field
);
630 BT_ASSERT_PRE_NON_NULL(field
, "Floating point number field");
631 BT_ASSERT_PRE_FIELD_COMMON_HOT(field
, "Floating point number field");
632 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
633 BT_FIELD_TYPE_ID_FLOAT
, "Field");
634 floating_point
->payload
= value
;
635 bt_field_common_set(field
, true);
640 const char *bt_field_common_string_get_value(struct bt_field_common
*field
)
642 struct bt_field_common_string
*string
= BT_FROM_COMMON(field
);
644 BT_ASSERT_PRE_NON_NULL(field
, "String field");
645 BT_ASSERT_PRE_FIELD_COMMON_IS_SET(field
, "String field");
646 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
647 BT_FIELD_TYPE_ID_STRING
, "Field");
648 return string
->payload
->str
;
652 int bt_field_common_string_set_value(struct bt_field_common
*field
,
655 struct bt_field_common_string
*string
= BT_FROM_COMMON(field
);
657 BT_ASSERT_PRE_NON_NULL(field
, "String field");
658 BT_ASSERT_PRE_NON_NULL(value
, "Value");
659 BT_ASSERT_PRE_FIELD_COMMON_HOT(field
, "String field");
660 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
661 BT_FIELD_TYPE_ID_STRING
, "Field");
663 if (string
->payload
) {
664 g_string_assign(string
->payload
, value
);
666 string
->payload
= g_string_new(value
);
669 bt_field_common_set(field
, true);
674 int bt_field_common_string_append(struct bt_field_common
*field
,
677 struct bt_field_common_string
*string_field
= BT_FROM_COMMON(field
);
679 BT_ASSERT_PRE_NON_NULL(field
, "String field");
680 BT_ASSERT_PRE_NON_NULL(value
, "Value");
681 BT_ASSERT_PRE_FIELD_COMMON_HOT(field
, "String field");
682 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
683 BT_FIELD_TYPE_ID_STRING
, "Field");
685 if (string_field
->payload
) {
686 g_string_append(string_field
->payload
, value
);
688 string_field
->payload
= g_string_new(value
);
691 bt_field_common_set(field
, true);
696 int bt_field_common_string_append_len(struct bt_field_common
*field
,
697 const char *value
, unsigned int length
)
699 struct bt_field_common_string
*string_field
= BT_FROM_COMMON(field
);
701 BT_ASSERT_PRE_NON_NULL(field
, "String field");
702 BT_ASSERT_PRE_NON_NULL(value
, "Value");
703 BT_ASSERT_PRE_FIELD_COMMON_HOT(field
, "String field");
704 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
705 BT_FIELD_TYPE_ID_STRING
, "Field");
707 /* make sure no null bytes are appended */
708 BT_ASSERT_PRE(memchr(value
, '\0', length
) == NULL
,
709 "String value to append contains a null character: "
710 "partial-value=\"%.32s\", length=%u", value
, length
);
712 if (string_field
->payload
) {
713 g_string_append_len(string_field
->payload
, value
, length
);
715 string_field
->payload
= g_string_new_len(value
, length
);
718 bt_field_common_set(field
, true);
723 int bt_field_common_string_clear(struct bt_field_common
*field
)
725 struct bt_field_common_string
*string_field
= BT_FROM_COMMON(field
);
727 BT_ASSERT_PRE_NON_NULL(field
, "String field");
728 BT_ASSERT_PRE_FIELD_COMMON_HOT(field
, "String field");
729 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
730 BT_FIELD_TYPE_ID_STRING
, "Field");
732 if (string_field
->payload
) {
733 g_string_set_size(string_field
->payload
, 0);
735 string_field
->payload
= g_string_new(NULL
);
738 bt_field_common_set(field
, true);
743 int _bt_field_validate_recursive(struct bt_field
*field
)
745 return _bt_field_common_validate_recursive((void *) field
);
749 void _bt_field_set_is_frozen_recursive(struct bt_field
*field
, bool is_frozen
)
751 return _bt_field_common_set_is_frozen_recursive((void *) field
,
756 bt_bool
_bt_field_is_set_recursive(struct bt_field
*field
)
758 return _bt_field_common_is_set_recursive((void *) field
);
762 void _bt_field_reset_recursive(struct bt_field
*field
)
764 _bt_field_common_reset_recursive((void *) field
);
768 void _bt_field_set(struct bt_field
*field
, bool value
)
770 _bt_field_common_set((void *) field
, value
);
774 void bt_field_common_finalize(struct bt_field_common
*field
)
777 BT_LOGD_STR("Putting field's type.");
782 void bt_field_common_integer_finalize(struct bt_field_common
*field
)
785 BT_LOGD("Finalizing common integer field object: addr=%p", field
);
786 bt_field_common_finalize(field
);
790 void bt_field_common_floating_point_finalize(struct bt_field_common
*field
)
793 BT_LOGD("Finalizing common floating point number field object: addr=%p", field
);
794 bt_field_common_finalize(field
);
798 void bt_field_common_structure_finalize_recursive(struct bt_field_common
*field
)
800 struct bt_field_common_structure
*structure
= BT_FROM_COMMON(field
);
803 BT_LOGD("Finalizing common structure field object: addr=%p", field
);
804 bt_field_common_finalize(field
);
806 if (structure
->fields
) {
807 g_ptr_array_free(structure
->fields
, TRUE
);
812 void bt_field_common_variant_finalize_recursive(struct bt_field_common
*field
)
814 struct bt_field_common_variant
*variant
= BT_FROM_COMMON(field
);
817 BT_LOGD("Finalizing common variant field object: addr=%p", field
);
818 bt_field_common_finalize(field
);
820 if (variant
->fields
) {
821 g_ptr_array_free(variant
->fields
, TRUE
);
826 void bt_field_common_array_finalize_recursive(struct bt_field_common
*field
)
828 struct bt_field_common_array
*array
= BT_FROM_COMMON(field
);
831 BT_LOGD("Finalizing common array field object: addr=%p", field
);
832 bt_field_common_finalize(field
);
834 if (array
->elements
) {
835 g_ptr_array_free(array
->elements
, TRUE
);
840 void bt_field_common_sequence_finalize_recursive(struct bt_field_common
*field
)
842 struct bt_field_common_sequence
*sequence
= BT_FROM_COMMON(field
);
845 BT_LOGD("Finalizing common sequence field object: addr=%p", field
);
846 bt_field_common_finalize(field
);
848 if (sequence
->elements
) {
849 g_ptr_array_free(sequence
->elements
, TRUE
);
854 void bt_field_common_string_finalize(struct bt_field_common
*field
)
856 struct bt_field_common_string
*string
= BT_FROM_COMMON(field
);
859 BT_LOGD("Finalizing common string field object: addr=%p", field
);
860 bt_field_common_finalize(field
);
862 if (string
->payload
) {
863 g_string_free(string
->payload
, TRUE
);
868 static inline bool value_is_in_range_signed(unsigned int size
, int64_t value
)
871 int64_t min_value
, max_value
;
873 min_value
= -(1ULL << (size
- 1));
874 max_value
= (1ULL << (size
- 1)) - 1;
875 if (value
< min_value
|| value
> max_value
) {
876 BT_LOGF("Value is out of bounds: value=%" PRId64
", "
877 "min-value=%" PRId64
", max-value=%" PRId64
,
878 value
, min_value
, max_value
);
886 static inline bool value_is_in_range_unsigned(unsigned int size
, uint64_t value
)
891 max_value
= (size
== 64) ? UINT64_MAX
: ((uint64_t) 1 << size
) - 1;
892 if (value
> max_value
) {
893 BT_LOGF("Value is out of bounds: value=%" PRIu64
", "
894 "max-value=%" PRIu64
,
903 struct bt_field
*bt_field_create_recursive(struct bt_field_type
*type
);
906 void bt_field_destroy_recursive(struct bt_field
*field
);
908 #endif /* BABELTRACE_CTF_IR_FIELDS_INTERNAL_H */