2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
7 #include <babeltrace2/babeltrace.h>
8 #include "common/macros.h"
9 #include "common/assert.h"
15 #include "ctf-meta-visitors.h"
18 int set_text_array_sequence_field_class(struct ctf_field_class
*fc
)
28 case CTF_FIELD_CLASS_TYPE_STRUCT
:
30 struct ctf_field_class_struct
*struct_fc
= (void *) fc
;
32 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
33 struct ctf_named_field_class
*named_fc
=
34 ctf_field_class_struct_borrow_member_by_index(
37 ret
= set_text_array_sequence_field_class(named_fc
->fc
);
45 case CTF_FIELD_CLASS_TYPE_VARIANT
:
47 struct ctf_field_class_variant
*var_fc
= (void *) fc
;
49 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
50 struct ctf_named_field_class
*named_fc
=
51 ctf_field_class_variant_borrow_option_by_index(
54 ret
= set_text_array_sequence_field_class(named_fc
->fc
);
62 case CTF_FIELD_CLASS_TYPE_ARRAY
:
63 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
65 struct ctf_field_class_array_base
*array_fc
= (void *) fc
;
67 if (array_fc
->elem_fc
->type
== CTF_FIELD_CLASS_TYPE_INT
||
68 array_fc
->elem_fc
->type
== CTF_FIELD_CLASS_TYPE_ENUM
) {
69 struct ctf_field_class_int
*int_fc
=
70 (void *) array_fc
->elem_fc
;
72 if (int_fc
->base
.base
.alignment
== 8 &&
73 int_fc
->base
.size
== 8 &&
74 int_fc
->encoding
== CTF_ENCODING_UTF8
) {
75 array_fc
->is_text
= true;
78 * Force integer element to be unsigned;
79 * this makes the decoder enter a single
80 * path when reading a text
81 * array/sequence and we can safely
82 * decode bytes as characters anyway.
84 int_fc
->is_signed
= false;
88 ret
= set_text_array_sequence_field_class(array_fc
->elem_fc
);
104 int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class
*ctf_tc
)
109 if (!ctf_tc
->is_translated
) {
110 ret
= set_text_array_sequence_field_class(
111 ctf_tc
->packet_header_fc
);
117 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
118 struct ctf_stream_class
*sc
= ctf_tc
->stream_classes
->pdata
[i
];
121 if (!sc
->is_translated
) {
122 ret
= set_text_array_sequence_field_class(
123 sc
->packet_context_fc
);
128 ret
= set_text_array_sequence_field_class(
129 sc
->event_header_fc
);
134 ret
= set_text_array_sequence_field_class(
135 sc
->event_common_context_fc
);
141 for (j
= 0; j
< sc
->event_classes
->len
; j
++) {
142 struct ctf_event_class
*ec
=
143 sc
->event_classes
->pdata
[j
];
145 if (ec
->is_translated
) {
149 ret
= set_text_array_sequence_field_class(
150 ec
->spec_context_fc
);
155 ret
= set_text_array_sequence_field_class(