Fix: src.ctf.fs: initialize the other_entry variable
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-update-text-array-sequence.c
CommitLineData
44c440bc
PP
1/*
2 * Copyright 2018 - Philippe Proulx <pproulx@efficios.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 */
14
3fadfbc0 15#include <babeltrace2/babeltrace.h>
91d81473 16#include "common/macros.h"
578e048b 17#include "common/assert.h"
44c440bc
PP
18#include <glib.h>
19#include <stdint.h>
20#include <string.h>
21#include <inttypes.h>
22
23#include "ctf-meta-visitors.h"
24
25static inline
5cd6d0e5 26int set_text_array_sequence_field_class(struct ctf_field_class *fc)
44c440bc
PP
27{
28 int ret = 0;
29 uint64_t i;
30
5cd6d0e5 31 if (!fc) {
44c440bc
PP
32 goto end;
33 }
34
864cad70
PP
35 switch (fc->type) {
36 case CTF_FIELD_CLASS_TYPE_STRUCT:
44c440bc 37 {
5cd6d0e5 38 struct ctf_field_class_struct *struct_fc = (void *) fc;
44c440bc 39
5cd6d0e5
PP
40 for (i = 0; i < struct_fc->members->len; i++) {
41 struct ctf_named_field_class *named_fc =
42 ctf_field_class_struct_borrow_member_by_index(
43 struct_fc, i);
44c440bc 44
5cd6d0e5 45 ret = set_text_array_sequence_field_class(named_fc->fc);
44c440bc
PP
46 if (ret) {
47 goto end;
48 }
49 }
50
51 break;
52 }
864cad70 53 case CTF_FIELD_CLASS_TYPE_VARIANT:
44c440bc 54 {
5cd6d0e5 55 struct ctf_field_class_variant *var_fc = (void *) fc;
44c440bc 56
5cd6d0e5
PP
57 for (i = 0; i < var_fc->options->len; i++) {
58 struct ctf_named_field_class *named_fc =
59 ctf_field_class_variant_borrow_option_by_index(
60 var_fc, i);
44c440bc 61
5cd6d0e5 62 ret = set_text_array_sequence_field_class(named_fc->fc);
44c440bc
PP
63 if (ret) {
64 goto end;
65 }
66 }
67
68 break;
69 }
864cad70
PP
70 case CTF_FIELD_CLASS_TYPE_ARRAY:
71 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
44c440bc 72 {
5cd6d0e5 73 struct ctf_field_class_array_base *array_fc = (void *) fc;
44c440bc 74
864cad70
PP
75 if (array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_INT ||
76 array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_ENUM) {
5cd6d0e5
PP
77 struct ctf_field_class_int *int_fc =
78 (void *) array_fc->elem_fc;
44c440bc 79
5cd6d0e5
PP
80 if (int_fc->base.base.alignment == 8 &&
81 int_fc->base.size == 8 &&
82 int_fc->encoding == CTF_ENCODING_UTF8) {
83 array_fc->is_text = true;
44c440bc
PP
84
85 /*
86 * Force integer element to be unsigned;
87 * this makes the decoder enter a single
88 * path when reading a text
89 * array/sequence and we can safely
90 * decode bytes as characters anyway.
91 */
5cd6d0e5 92 int_fc->is_signed = false;
44c440bc
PP
93 }
94 }
95
5cd6d0e5 96 ret = set_text_array_sequence_field_class(array_fc->elem_fc);
44c440bc
PP
97 if (ret) {
98 goto end;
99 }
100
101 break;
102 }
103 default:
104 break;
105 }
106
107end:
108 return ret;
109}
110
111BT_HIDDEN
112int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class *ctf_tc)
113{
114 int ret = 0;
115 uint64_t i;
116
117 if (!ctf_tc->is_translated) {
5cd6d0e5
PP
118 ret = set_text_array_sequence_field_class(
119 ctf_tc->packet_header_fc);
44c440bc
PP
120 if (ret) {
121 goto end;
122 }
123 }
124
125 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
126 struct ctf_stream_class *sc = ctf_tc->stream_classes->pdata[i];
127 uint64_t j;
128
129 if (!sc->is_translated) {
5cd6d0e5
PP
130 ret = set_text_array_sequence_field_class(
131 sc->packet_context_fc);
44c440bc
PP
132 if (ret) {
133 goto end;
134 }
135
5cd6d0e5
PP
136 ret = set_text_array_sequence_field_class(
137 sc->event_header_fc);
44c440bc
PP
138 if (ret) {
139 goto end;
140 }
141
5cd6d0e5
PP
142 ret = set_text_array_sequence_field_class(
143 sc->event_common_context_fc);
44c440bc
PP
144 if (ret) {
145 goto end;
146 }
147 }
148
149 for (j = 0; j < sc->event_classes->len; j++) {
150 struct ctf_event_class *ec =
151 sc->event_classes->pdata[j];
152
153 if (ec->is_translated) {
154 continue;
155 }
156
5cd6d0e5
PP
157 ret = set_text_array_sequence_field_class(
158 ec->spec_context_fc);
44c440bc
PP
159 if (ret) {
160 goto end;
161 }
162
5cd6d0e5
PP
163 ret = set_text_array_sequence_field_class(
164 ec->payload_fc);
44c440bc
PP
165 if (ret) {
166 goto end;
167 }
168 }
169 }
170
171end:
172 return ret;
173}
This page took 0.060859 seconds and 4 git commands to generate.