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>
43 #define BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(_field, _type_id, _name) \
44 BT_ASSERT_PRE((_field)->type->id == ((int) (_type_id)), \
45 _name " has the wrong type ID: expected-type-id=%s, " \
47 bt_common_field_type_id_string((int) (_type_id)), (_field))
49 #define BT_ASSERT_PRE_FIELD_COMMON_IS_SET(_field, _name) \
50 BT_ASSERT_PRE(bt_field_common_is_set_recursive(_field), \
51 _name " is not set: %!+_f", (_field))
53 #define BT_ASSERT_PRE_FIELD_COMMON_HOT(_field, _name) \
54 BT_ASSERT_PRE_HOT((_field), (_name), ": +%!+_f", (_field))
57 struct bt_field_common
;
59 typedef void (*bt_field_common_method_set_is_frozen
)(struct bt_field_common
*,
61 typedef int (*bt_field_common_method_validate
)(struct bt_field_common
*);
62 typedef struct bt_field_common
*(*bt_field_common_method_copy
)(
63 struct bt_field_common
*);
64 typedef bt_bool (*bt_field_common_method_is_set
)(struct bt_field_common
*);
65 typedef void (*bt_field_common_method_reset
)(struct bt_field_common
*);
67 struct bt_field_common_methods
{
68 bt_field_common_method_set_is_frozen set_is_frozen
;
69 bt_field_common_method_validate validate
;
70 bt_field_common_method_copy copy
;
71 bt_field_common_method_is_set is_set
;
72 bt_field_common_method_reset reset
;
75 struct bt_field_common
{
76 struct bt_object base
;
77 struct bt_field_type_common
*type
;
78 struct bt_field_common_methods
*methods
;
83 * Specialized data for either CTF IR or CTF writer APIs.
84 * See comment in `field-types-internal.h` for more details.
95 struct bt_field_common_integer
{
96 struct bt_field_common common
;
103 struct bt_field_common_floating_point
{
104 struct bt_field_common common
;
108 struct bt_field_common_structure
{
109 struct bt_field_common common
;
111 /* Array of `struct bt_field_common *`, owned by this */
115 struct bt_field_common_variant
{
116 struct bt_field_common common
;
123 /* Weak: belongs to `choices` below */
124 struct bt_field_common
*current_field
;
126 /* Array of `struct bt_field_common *`, owned by this */
130 struct bt_field_common_array
{
131 struct bt_field_common common
;
133 /* Array of `struct bt_field_common *`, owned by this */
137 struct bt_field_common_sequence
{
138 struct bt_field_common common
;
141 * This is the true sequence field's length: its value can be
142 * less than `elements->len` below because we never shrink the
143 * array of elements to avoid reallocation.
147 /* Array of `struct bt_field_common *`, owned by this */
151 struct bt_field_common_string
{
152 struct bt_field_common common
;
157 struct bt_field_enumeration
{
158 struct bt_field_common_integer common
;
162 struct bt_field_common
*bt_field_common_copy(struct bt_field_common
*field
);
165 int bt_field_common_structure_initialize(struct bt_field_common
*field
,
166 struct bt_field_type_common
*type
,
167 bt_object_release_func release_func
,
168 struct bt_field_common_methods
*methods
,
169 bt_field_common_create_func field_create_func
,
170 GDestroyNotify field_release_func
);
173 int bt_field_common_array_initialize(struct bt_field_common
*field
,
174 struct bt_field_type_common
*type
,
175 bt_object_release_func release_func
,
176 struct bt_field_common_methods
*methods
,
177 bt_field_common_create_func field_create_func
,
178 GDestroyNotify field_destroy_func
);
181 int bt_field_common_sequence_initialize(struct bt_field_common
*field
,
182 struct bt_field_type_common
*type
,
183 bt_object_release_func release_func
,
184 struct bt_field_common_methods
*methods
,
185 GDestroyNotify field_destroy_func
);
188 int bt_field_common_variant_initialize(struct bt_field_common
*field
,
189 struct bt_field_type_common
*type
,
190 bt_object_release_func release_func
,
191 struct bt_field_common_methods
*methods
,
192 bt_field_common_create_func field_create_func
,
193 GDestroyNotify field_release_func
);
196 int bt_field_common_string_initialize(struct bt_field_common
*field
,
197 struct bt_field_type_common
*type
,
198 bt_object_release_func release_func
,
199 struct bt_field_common_methods
*methods
);
202 int bt_field_common_generic_validate(struct bt_field_common
*field
);
205 int bt_field_common_structure_validate_recursive(struct bt_field_common
*field
);
208 int bt_field_common_variant_validate_recursive(struct bt_field_common
*field
);
211 int bt_field_common_array_validate_recursive(struct bt_field_common
*field
);
214 int bt_field_common_sequence_validate_recursive(struct bt_field_common
*field
);
217 void bt_field_common_generic_reset(struct bt_field_common
*field
);
220 void bt_field_common_structure_reset_recursive(struct bt_field_common
*field
);
223 void bt_field_common_variant_reset_recursive(struct bt_field_common
*field
);
226 void bt_field_common_array_reset_recursive(struct bt_field_common
*field
);
229 void bt_field_common_sequence_reset_recursive(struct bt_field_common
*field
);
232 void bt_field_common_generic_set_is_frozen(struct bt_field_common
*field
,
236 void bt_field_common_structure_set_is_frozen_recursive(
237 struct bt_field_common
*field
, bool is_frozen
);
240 void bt_field_common_variant_set_is_frozen_recursive(
241 struct bt_field_common
*field
, bool is_frozen
);
244 void bt_field_common_array_set_is_frozen_recursive(
245 struct bt_field_common
*field
, bool is_frozen
);
248 void bt_field_common_sequence_set_is_frozen_recursive(
249 struct bt_field_common
*field
, bool is_frozen
);
252 void _bt_field_common_set_is_frozen_recursive(struct bt_field_common
*field
,
256 bt_bool
bt_field_common_generic_is_set(struct bt_field_common
*field
);
259 bt_bool
bt_field_common_structure_is_set_recursive(
260 struct bt_field_common
*field
);
263 bt_bool
bt_field_common_variant_is_set_recursive(struct bt_field_common
*field
);
266 bt_bool
bt_field_common_array_is_set_recursive(struct bt_field_common
*field
);
269 bt_bool
bt_field_common_sequence_is_set_recursive(struct bt_field_common
*field
);
272 # define bt_field_common_validate_recursive _bt_field_common_validate_recursive
273 # define bt_field_common_set_is_frozen_recursive _bt_field_common_set_is_frozen_recursive
274 # define bt_field_common_is_set_recursive _bt_field_common_is_set_recursive
275 # define bt_field_common_reset_recursive _bt_field_common_reset_recursive
276 # define bt_field_common_set _bt_field_common_set
277 # define bt_field_validate_recursive _bt_field_validate_recursive
278 # define bt_field_set_is_frozen_recursive _bt_field_set_is_frozen_recursive
279 # define bt_field_is_set_recursive _bt_field_is_set_recursive
280 # define bt_field_reset_recursive _bt_field_reset_recursive
281 # define bt_field_set _bt_field_set
283 # define bt_field_common_validate_recursive(_field) (-1)
284 # define bt_field_common_set_is_frozen_recursive(_field, _is_frozen)
285 # define bt_field_common_is_set_recursive(_field) (BT_FALSE)
286 # define bt_field_common_reset_recursive(_field)
287 # define bt_field_common_set(_field, _val)
288 # define bt_field_validate_recursive(_field) (-1)
289 # define bt_field_set_is_frozen_recursive(_field, _is_frozen)
290 # define bt_field_is_set_recursive(_field) (BT_FALSE)
291 # define bt_field_reset_recursive(_field)
292 # define bt_field_set(_field, _val)
296 static inline bool field_type_common_has_known_id(
297 struct bt_field_type_common
*ft
)
299 return (int) ft
->id
> BT_FIELD_TYPE_ID_UNKNOWN
||
300 (int) ft
->id
< BT_FIELD_TYPE_ID_NR
;
304 int _bt_field_common_validate_recursive(struct bt_field_common
*field
)
309 BT_ASSERT_PRE_MSG("%s", "Invalid field: field is NULL.");
314 BT_ASSERT(field_type_common_has_known_id(field
->type
));
316 if (field
->methods
->validate
) {
317 ret
= field
->methods
->validate(field
);
325 void _bt_field_common_reset_recursive(struct bt_field_common
*field
)
328 BT_ASSERT(field
->methods
->reset
);
329 field
->methods
->reset(field
);
333 void _bt_field_common_set(struct bt_field_common
*field
, bool value
)
336 field
->payload_set
= value
;
340 bt_bool
_bt_field_common_is_set_recursive(struct bt_field_common
*field
)
342 bt_bool is_set
= BT_FALSE
;
348 BT_ASSERT(field_type_common_has_known_id(field
->type
));
349 BT_ASSERT(field
->methods
->is_set
);
350 is_set
= field
->methods
->is_set(field
);
357 void bt_field_common_initialize(struct bt_field_common
*field
,
358 struct bt_field_type_common
*ft
,
359 bt_object_release_func release_func
,
360 struct bt_field_common_methods
*methods
)
364 bt_object_init(field
, release_func
);
365 field
->methods
= methods
;
366 field
->type
= bt_get(ft
);
370 struct bt_field_type_common
*bt_field_common_borrow_type(
371 struct bt_field_common
*field
)
373 struct bt_field_type_common
*ret
= NULL
;
375 BT_ASSERT_PRE_NON_NULL(field
, "Field");
381 int64_t bt_field_common_sequence_get_length(struct bt_field_common
*field
)
383 struct bt_field_common_sequence
*sequence
= BT_FROM_COMMON(field
);
385 BT_ASSERT_PRE_NON_NULL(field
, "Sequence field");
386 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
, BT_FIELD_TYPE_ID_SEQUENCE
,
388 return (int64_t) sequence
->length
;
392 int bt_field_common_sequence_set_length(struct bt_field_common
*field
,
393 uint64_t length
, bt_field_common_create_func field_create_func
)
396 struct bt_field_common_sequence
*sequence
= BT_FROM_COMMON(field
);
398 BT_ASSERT_PRE_NON_NULL(field
, "Sequence field");
399 BT_ASSERT_PRE_FIELD_COMMON_HOT(field
, "Sequence field");
401 if (length
> sequence
->elements
->len
) {
403 struct bt_field_type_common_sequence
*sequence_ft
;
404 uint64_t cur_len
= sequence
->elements
->len
;
407 g_ptr_array_set_size(sequence
->elements
, length
);
408 sequence_ft
= BT_FROM_COMMON(sequence
->common
.type
);
410 for (i
= cur_len
; i
< sequence
->elements
->len
; i
++) {
411 struct bt_field_common
*elem_field
=
412 field_create_func(sequence_ft
->element_ft
);
419 BT_ASSERT(!sequence
->elements
->pdata
[i
]);
420 sequence
->elements
->pdata
[i
] = elem_field
;
424 sequence
->length
= length
;
431 struct bt_field_common
*bt_field_common_structure_borrow_field_by_name(
432 struct bt_field_common
*field
, const char *name
)
434 struct bt_field_common
*ret
= NULL
;
436 struct bt_field_type_common_structure
*structure_ft
;
437 struct bt_field_common_structure
*structure
= BT_FROM_COMMON(field
);
439 GHashTable
*field_name_to_index
;
441 BT_ASSERT_PRE_NON_NULL(field
, "Structure field");
442 BT_ASSERT_PRE_NON_NULL(name
, "Field name");
443 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
444 BT_FIELD_TYPE_ID_STRUCT
, "Field");
445 structure_ft
= BT_FROM_COMMON(field
->type
);
446 field_name_to_index
= structure_ft
->field_name_to_index
;
447 field_quark
= g_quark_from_string(name
);
448 if (!g_hash_table_lookup_extended(field_name_to_index
,
449 GUINT_TO_POINTER(field_quark
),
450 NULL
, (gpointer
*) &index
)) {
451 BT_LOGV("Invalid parameter: no such field in structure field's type: "
452 "struct-field-addr=%p, struct-ft-addr=%p, name=\"%s\"",
453 field
, field
->type
, name
);
457 ret
= structure
->fields
->pdata
[index
];
465 struct bt_field_common
*bt_field_common_structure_borrow_field_by_index(
466 struct bt_field_common
*field
, uint64_t index
)
468 struct bt_field_common_structure
*structure
= BT_FROM_COMMON(field
);
470 BT_ASSERT_PRE_NON_NULL(field
, "Structure field");
471 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
472 BT_FIELD_TYPE_ID_STRUCT
, "Field");
473 BT_ASSERT_PRE(index
< structure
->fields
->len
,
474 "Index is out of bound: %![struct-field-]+_f, "
475 "index=%" PRIu64
", count=%u", field
, index
,
476 structure
->fields
->len
);
477 return structure
->fields
->pdata
[index
];
481 struct bt_field_common
*bt_field_common_array_borrow_field(
482 struct bt_field_common
*field
, uint64_t index
)
484 struct bt_field_common_array
*array
= BT_FROM_COMMON(field
);
486 BT_ASSERT_PRE_NON_NULL(field
, "Array field");
487 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
, BT_FIELD_TYPE_ID_ARRAY
,
489 BT_ASSERT_PRE(index
< array
->elements
->len
,
490 "Index is out of bound: %![array-field-]+_f, "
491 "index=%" PRIu64
", count=%u", field
,
492 index
, array
->elements
->len
);
493 return array
->elements
->pdata
[(size_t) index
];
497 struct bt_field_common
*bt_field_common_sequence_borrow_field(
498 struct bt_field_common
*field
, uint64_t index
)
500 struct bt_field_common_sequence
*sequence
= BT_FROM_COMMON(field
);
502 BT_ASSERT_PRE_NON_NULL(field
, "Sequence field");
503 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
, BT_FIELD_TYPE_ID_SEQUENCE
,
505 BT_ASSERT_PRE(index
< sequence
->length
,
506 "Index is out of bound: %![seq-field-]+_f, "
507 "index=%" PRIu64
", count=%u", field
, index
,
508 sequence
->elements
->len
);
509 return sequence
->elements
->pdata
[(size_t) index
];
513 int bt_field_variant_common_set_tag(struct bt_field_common
*variant_field
,
514 uint64_t tag_uval
, bool is_signed
)
517 int64_t choice_index
;
518 struct bt_field_common_variant
*variant
= BT_FROM_COMMON(variant_field
);
520 BT_ASSERT_PRE_NON_NULL(variant_field
, "Variant field");
521 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(variant_field
,
522 BT_FIELD_TYPE_ID_VARIANT
, "Field");
524 /* Find matching index in variant field's type */
525 choice_index
= bt_field_type_common_variant_find_choice_index(
526 variant_field
->type
, tag_uval
, is_signed
);
527 if (choice_index
< 0) {
532 /* Select corresponding field */
533 BT_ASSERT(choice_index
< variant
->fields
->len
);
534 variant
->current_field
= variant
->fields
->pdata
[choice_index
];
535 variant
->tag_value
.u
= tag_uval
;
542 struct bt_field_common
*bt_field_common_variant_borrow_current_field(
543 struct bt_field_common
*variant_field
)
545 struct bt_field_common_variant
*variant
= BT_FROM_COMMON(variant_field
);
547 BT_ASSERT_PRE_NON_NULL(variant_field
, "Variant field");
548 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(variant_field
,
549 BT_FIELD_TYPE_ID_VARIANT
, "Field");
550 BT_ASSERT_PRE(variant
->current_field
,
551 "Variant field has no current field: %!+_f", variant_field
);
552 return variant
->current_field
;
556 int bt_field_common_variant_get_tag_signed(struct bt_field_common
*variant_field
,
559 struct bt_field_common_variant
*variant
= BT_FROM_COMMON(variant_field
);
561 BT_ASSERT_PRE_NON_NULL(variant_field
, "Variant field");
562 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(variant_field
,
563 BT_FIELD_TYPE_ID_VARIANT
, "Field");
564 BT_ASSERT_PRE(variant
->current_field
,
565 "Variant field has no current field: %!+_f", variant_field
);
566 *tag
= variant
->tag_value
.i
;
571 int bt_field_common_variant_get_tag_unsigned(struct bt_field_common
*variant_field
,
574 struct bt_field_common_variant
*variant
= BT_FROM_COMMON(variant_field
);
576 BT_ASSERT_PRE_NON_NULL(variant_field
, "Variant field");
577 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(variant_field
,
578 BT_FIELD_TYPE_ID_VARIANT
, "Field");
579 BT_ASSERT_PRE(variant
->current_field
,
580 "Variant field has no current field: %!+_f", variant_field
);
581 *tag
= variant
->tag_value
.u
;
586 struct bt_field_type_enumeration_mapping_iterator
*
587 bt_field_common_enumeration_get_mappings(struct bt_field_common
*field
,
588 bt_field_common_create_func field_create_func
,
591 struct bt_field_type_common_enumeration
*enum_type
= NULL
;
592 struct bt_field_type_common_integer
*integer_type
= NULL
;
593 struct bt_field_type_enumeration_mapping_iterator
*iter
= NULL
;
596 BT_ASSERT(field
->type
->id
== BT_FIELD_TYPE_ID_ENUM
);
597 BT_ASSERT(field
->payload_set
);
598 enum_type
= BT_FROM_COMMON(field
->type
);
599 integer_type
= enum_type
->container_ft
;
601 if (!integer_type
->is_signed
) {
602 iter
= bt_field_type_common_enumeration_unsigned_find_mappings_by_value(
605 iter
= bt_field_type_common_enumeration_signed_find_mappings_by_value(
606 field
->type
, (int64_t) uval
);
613 int bt_field_common_floating_point_get_value(struct bt_field_common
*field
,
616 struct bt_field_common_floating_point
*floating_point
=
617 BT_FROM_COMMON(field
);
619 BT_ASSERT_PRE_NON_NULL(field
, "Floating point number field");
620 BT_ASSERT_PRE_NON_NULL(value
, "Value");
621 BT_ASSERT_PRE_FIELD_COMMON_IS_SET(field
, "Floating point number field");
622 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
623 BT_FIELD_TYPE_ID_FLOAT
, "Field");
624 *value
= floating_point
->payload
;
629 int bt_field_common_floating_point_set_value(struct bt_field_common
*field
,
632 struct bt_field_common_floating_point
*floating_point
=
633 BT_FROM_COMMON(field
);
635 BT_ASSERT_PRE_NON_NULL(field
, "Floating point number field");
636 BT_ASSERT_PRE_FIELD_COMMON_HOT(field
, "Floating point number field");
637 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
638 BT_FIELD_TYPE_ID_FLOAT
, "Field");
639 floating_point
->payload
= value
;
640 bt_field_common_set(field
, true);
645 const char *bt_field_common_string_get_value(struct bt_field_common
*field
)
647 struct bt_field_common_string
*string
= BT_FROM_COMMON(field
);
649 BT_ASSERT_PRE_NON_NULL(field
, "String field");
650 BT_ASSERT_PRE_FIELD_COMMON_IS_SET(field
, "String field");
651 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
652 BT_FIELD_TYPE_ID_STRING
, "Field");
653 return (const char *) string
->buf
->data
;
657 int bt_field_common_string_set_value(struct bt_field_common
*field
,
660 struct bt_field_common_string
*string
= BT_FROM_COMMON(field
);
663 BT_ASSERT_PRE_NON_NULL(field
, "String field");
664 BT_ASSERT_PRE_NON_NULL(value
, "Value");
665 BT_ASSERT_PRE_FIELD_COMMON_HOT(field
, "String field");
666 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
667 BT_FIELD_TYPE_ID_STRING
, "Field");
669 str_len
= strlen(value
);
671 if (str_len
+ 1 > string
->buf
->len
) {
672 g_array_set_size(string
->buf
, str_len
+ 1);
675 memcpy(string
->buf
->data
, value
, str_len
);
676 ((char *) string
->buf
->data
)[str_len
] = '\0';
677 string
->size
= str_len
;
678 bt_field_common_set(field
, true);
683 int bt_field_common_string_append_len(struct bt_field_common
*field
,
684 const char *value
, unsigned int length
)
686 struct bt_field_common_string
*string_field
= BT_FROM_COMMON(field
);
690 BT_ASSERT_PRE_NON_NULL(field
, "String field");
691 BT_ASSERT_PRE_NON_NULL(value
, "Value");
692 BT_ASSERT_PRE_FIELD_COMMON_HOT(field
, "String field");
693 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
694 BT_FIELD_TYPE_ID_STRING
, "Field");
696 /* Make sure no null bytes are appended */
697 BT_ASSERT_PRE(memchr(value
, '\0', length
) == NULL
,
698 "String value to append contains a null character: "
699 "partial-value=\"%.32s\", length=%u", value
, length
);
701 new_size
= string_field
->size
+ length
;
703 if (new_size
+ 1 > string_field
->buf
->len
) {
704 g_array_set_size(string_field
->buf
, new_size
+ 1);
707 data
= string_field
->buf
->data
;
708 memcpy(data
+ string_field
->size
, value
, length
);
709 ((char *) string_field
->buf
->data
)[new_size
] = '\0';
710 string_field
->size
= new_size
;
711 bt_field_common_set(field
, true);
716 int bt_field_common_string_append(struct bt_field_common
*field
,
719 BT_ASSERT_PRE_NON_NULL(value
, "Value");
721 return bt_field_common_string_append_len(field
, value
,
726 int bt_field_common_string_clear(struct bt_field_common
*field
)
728 struct bt_field_common_string
*string_field
= BT_FROM_COMMON(field
);
730 BT_ASSERT_PRE_NON_NULL(field
, "String field");
731 BT_ASSERT_PRE_FIELD_COMMON_HOT(field
, "String field");
732 BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field
,
733 BT_FIELD_TYPE_ID_STRING
, "Field");
734 string_field
->size
= 0;
735 bt_field_common_set(field
, true);
740 int _bt_field_validate_recursive(struct bt_field
*field
)
742 return _bt_field_common_validate_recursive((void *) field
);
746 void _bt_field_set_is_frozen_recursive(struct bt_field
*field
, bool is_frozen
)
748 return _bt_field_common_set_is_frozen_recursive((void *) field
,
753 bt_bool
_bt_field_is_set_recursive(struct bt_field
*field
)
755 return _bt_field_common_is_set_recursive((void *) field
);
759 void _bt_field_reset_recursive(struct bt_field
*field
)
761 _bt_field_common_reset_recursive((void *) field
);
765 void _bt_field_set(struct bt_field
*field
, bool value
)
767 _bt_field_common_set((void *) field
, value
);
771 void bt_field_common_finalize(struct bt_field_common
*field
)
774 BT_LOGD_STR("Putting field's type.");
779 void bt_field_common_integer_finalize(struct bt_field_common
*field
)
782 BT_LOGD("Finalizing common integer field object: addr=%p", field
);
783 bt_field_common_finalize(field
);
787 void bt_field_common_floating_point_finalize(struct bt_field_common
*field
)
790 BT_LOGD("Finalizing common floating point number field object: addr=%p", field
);
791 bt_field_common_finalize(field
);
795 void bt_field_common_structure_finalize_recursive(struct bt_field_common
*field
)
797 struct bt_field_common_structure
*structure
= BT_FROM_COMMON(field
);
800 BT_LOGD("Finalizing common structure field object: addr=%p", field
);
801 bt_field_common_finalize(field
);
803 if (structure
->fields
) {
804 g_ptr_array_free(structure
->fields
, TRUE
);
809 void bt_field_common_variant_finalize_recursive(struct bt_field_common
*field
)
811 struct bt_field_common_variant
*variant
= BT_FROM_COMMON(field
);
814 BT_LOGD("Finalizing common variant field object: addr=%p", field
);
815 bt_field_common_finalize(field
);
817 if (variant
->fields
) {
818 g_ptr_array_free(variant
->fields
, TRUE
);
823 void bt_field_common_array_finalize_recursive(struct bt_field_common
*field
)
825 struct bt_field_common_array
*array
= BT_FROM_COMMON(field
);
828 BT_LOGD("Finalizing common array field object: addr=%p", field
);
829 bt_field_common_finalize(field
);
831 if (array
->elements
) {
832 g_ptr_array_free(array
->elements
, TRUE
);
837 void bt_field_common_sequence_finalize_recursive(struct bt_field_common
*field
)
839 struct bt_field_common_sequence
*sequence
= BT_FROM_COMMON(field
);
842 BT_LOGD("Finalizing common sequence field object: addr=%p", field
);
843 bt_field_common_finalize(field
);
845 if (sequence
->elements
) {
846 g_ptr_array_free(sequence
->elements
, TRUE
);
851 void bt_field_common_string_finalize(struct bt_field_common
*field
)
853 struct bt_field_common_string
*string
= BT_FROM_COMMON(field
);
856 BT_LOGD("Finalizing common string field object: addr=%p", field
);
857 bt_field_common_finalize(field
);
860 g_array_free(string
->buf
, TRUE
);
865 static inline bool value_is_in_range_signed(unsigned int size
, int64_t value
)
868 int64_t min_value
, max_value
;
870 min_value
= -(1ULL << (size
- 1));
871 max_value
= (1ULL << (size
- 1)) - 1;
872 if (value
< min_value
|| value
> max_value
) {
873 BT_LOGF("Value is out of bounds: value=%" PRId64
", "
874 "min-value=%" PRId64
", max-value=%" PRId64
,
875 value
, min_value
, max_value
);
883 static inline bool value_is_in_range_unsigned(unsigned int size
, uint64_t value
)
888 max_value
= (size
== 64) ? UINT64_MAX
: ((uint64_t) 1 << size
) - 1;
889 if (value
> max_value
) {
890 BT_LOGF("Value is out of bounds: value=%" PRIu64
", "
891 "max-value=%" PRIu64
,
900 struct bt_field
*bt_field_create_recursive(struct bt_field_type
*type
);
903 void bt_field_destroy_recursive(struct bt_field
*field
);
905 #endif /* BABELTRACE_CTF_IR_FIELDS_INTERNAL_H */