Skip to content

Commit a6d8918

Browse files
committed
processor_calyptia: remove for loop initial declarations
Signed-off-by: Thiago Padilha <thiago@padilha.cc>
1 parent 4eca767 commit a6d8918

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

plugins/processor_calyptia/calyptia_logs_from_lua.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
int calyptia_logs_from_lua(struct flb_processor_instance *ins, lua_State *L,
77
struct flb_mp_chunk_cobj *chunk_cobj)
88
{
9+
int i;
910
int logs_length, metadata_length, timestamps_length;
1011
struct flb_mp_chunk_record *record;
1112

@@ -41,7 +42,7 @@ int calyptia_logs_from_lua(struct flb_processor_instance *ins, lua_State *L,
4142
return -1;
4243
}
4344

44-
for (int i = 1; i <= logs_length; i++) {
45+
for (i = 1; i <= logs_length; i++) {
4546
record = flb_mp_chunk_record_create(chunk_cobj);
4647
if (!record) {
4748
flb_plg_error(ins, "failed to create record");

plugins/processor_calyptia/calyptia_metrics_from_lua.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ struct metrics_header {
2121

2222
static void free_labels(char **labels, size_t label_count)
2323
{
24+
int i;
2425
if (!labels) {
2526
return;
2627
}
27-
for (int i = 0; i < label_count; i++) {
28+
for (i = 0; i < label_count; i++) {
2829
if (labels[i]) {
2930
free(labels[i]);
3031
}
@@ -59,7 +60,8 @@ static void split_fqname(const char *fqname, struct metrics_header *header)
5960
static int assign_label(char **keys, size_t key_count, char **values,
6061
const char *key, const char *value)
6162
{
62-
for (size_t i = 0; i < key_count; i++) {
63+
size_t i;
64+
for (i = 0; i < key_count; i++) {
6365
if (!strcmp(keys[i], key)) {
6466
values[i] = strdup(value);
6567
if (!values[i]) {
@@ -124,13 +126,14 @@ static double *lua_to_quantile_values(struct flb_processor_instance *ins,
124126
lua_State *L, double *quantile_keys,
125127
int count)
126128
{
129+
int i;
127130
double *quantile_values = calloc(count, sizeof(*quantile_values));
128131
if (!quantile_values) {
129132
flb_plg_error(ins, "could not allocate memory for quantile values");
130133
return NULL;
131134
}
132135

133-
for (int i = 0; i < count; i++) {
136+
for (i = 0; i < count; i++) {
134137
lua_pushnumber(L, quantile_keys[i]);
135138
lua_gettable(L, -2);
136139
quantile_values[i] = lua_to_double(L, -1);
@@ -144,13 +147,14 @@ static uint64_t *lua_to_bucket_values(struct flb_processor_instance *ins,
144147
lua_State *L, double *bucket_keys,
145148
int count)
146149
{
150+
int i;
147151
uint64_t *values = calloc(count, sizeof(*values));
148152
if (!values) {
149153
flb_plg_error(ins, "could not allocate memory for bucket values");
150154
return NULL;
151155
}
152156

153-
for (int i = 0; i < count; i++) {
157+
for (i = 0; i < count; i++) {
154158
lua_pushnumber(L, bucket_keys[i]);
155159
lua_gettable(L, -2);
156160
values[i] = lua_to_uint(L);
@@ -163,6 +167,7 @@ static uint64_t *lua_to_bucket_values(struct flb_processor_instance *ins,
163167
static double *lua_to_quantiles_buckets(struct flb_processor_instance *ins,
164168
lua_State *L, int *count)
165169
{
170+
int i;
166171
double *keys;
167172
*count = 0;
168173
if (lua_type(L, -1) != LUA_TTABLE) {
@@ -183,7 +188,7 @@ static double *lua_to_quantiles_buckets(struct flb_processor_instance *ins,
183188
}
184189

185190
lua_pushnil(L); // first key
186-
int i = 0;
191+
i = 0;
187192
while (lua_next(L, -2) != 0) {
188193
keys[i] = lua_to_double(L, -2);
189194
i++;
@@ -200,6 +205,7 @@ static double *lua_to_quantile_bucket_keys(struct flb_processor_instance *ins,
200205
lua_State *L, const char *kind,
201206
int *count)
202207
{
208+
int i;
203209
int sample_count;
204210
double *keys;
205211

@@ -214,7 +220,7 @@ static double *lua_to_quantile_bucket_keys(struct flb_processor_instance *ins,
214220
int found = 0;
215221

216222
/* find the first sample that has quantiles */
217-
for (int i = 1; i <= sample_count; i++) {
223+
for (i = 1; i <= sample_count; i++) {
218224
lua_rawgeti(L, -1, i);
219225
lua_getfield(L, -1, kind);
220226
if (lua_type(L, -1) == LUA_TTABLE) {
@@ -240,7 +246,8 @@ static double *lua_to_quantile_bucket_keys(struct flb_processor_instance *ins,
240246
static char **append_label(char **labels, size_t *labels_size,
241247
size_t *label_index, const char *label)
242248
{
243-
for (size_t i = 0; i < *label_index; i++) {
249+
size_t i;
250+
for (i = 0; i < *label_index; i++) {
244251
if (!strcmp(labels[i], label)) {
245252
/* don't do anything if the label is already in the array */
246253
return labels;
@@ -272,6 +279,7 @@ static char **append_label(char **labels, size_t *labels_size,
272279
static char **lua_to_label_keys(struct flb_processor_instance *ins,
273280
lua_State *L, int *label_count)
274281
{
282+
int i;
275283
int sample_count;
276284
char **label_keys;
277285
size_t label_index;
@@ -295,7 +303,7 @@ static char **lua_to_label_keys(struct flb_processor_instance *ins,
295303
labels_size = 0;
296304
label_index = 0;
297305

298-
for (int i = 1; i <= sample_count; i++) {
306+
for (i = 1; i <= sample_count; i++) {
299307
lua_rawgeti(L, -1, i);
300308
if (lua_type(L, -1) != LUA_TTABLE) {
301309
free_labels(label_keys, label_index);
@@ -357,6 +365,8 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,
357365
char **label_vals;
358366
int label_count;
359367
uint64_t timestamp;
368+
int i;
369+
int j;
360370

361371
if (lua_type(L, -1) != LUA_TTABLE) {
362372
flb_plg_error(ins, "expected metrics array");
@@ -365,7 +375,7 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,
365375

366376
metric_count = lua_objlen(L, -1);
367377

368-
for (int i = 1; i <= metric_count; i++) {
378+
for (i = 1; i <= metric_count; i++) {
369379
lua_rawgeti(L, -1, i);
370380

371381
label_keys = lua_to_label_keys(ins, L, &label_count);
@@ -465,7 +475,7 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,
465475
return -1;
466476
}
467477

468-
for (int j = 1; j <= sample_count; j++) {
478+
for (j = 1; j <= sample_count; j++) {
469479
label_vals = NULL;
470480

471481
/* get sample */

plugins/processor_calyptia/calyptia_metrics_to_lua.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ static void push_histogram(lua_State *L, struct cmt_map *map,
8181
static void push_summary(lua_State *L, struct cmt_map *map,
8282
struct cmt_metric *metric)
8383
{
84+
int i;
8485
struct cmt_summary *summary;
8586
struct cmt_opts *opts;
8687

@@ -89,7 +90,7 @@ static void push_summary(lua_State *L, struct cmt_map *map,
8990

9091
if (metric->sum_quantiles_set) {
9192
lua_createtable(L, summary->quantiles_count, 0);
92-
for (int i = 0; i < summary->quantiles_count; i++) {
93+
for (i = 0; i < summary->quantiles_count; i++) {
9394
lua_pushnumber(L, summary->quantiles[i]);
9495
lua_pushnumber(L, cmt_summary_quantile_get_value(metric, i));
9596
lua_settable(L, -3);

plugins/processor_calyptia/calyptia_traces_from_lua.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ static void lua_to_links(lua_State *L, struct ctrace_span *span)
2626
{
2727
struct ctrace_link *link;
2828
size_t count;
29+
size_t i;
2930
struct ctrace_id *trace_id;
3031

3132
if (lua_type(L, -1) != LUA_TTABLE) {
3233
return;
3334
}
3435

3536
count = lua_objlen(L, -1);
36-
for (size_t i = 1; i <= count; i++) {
37+
for (i = 1; i <= count; i++) {
3738
lua_rawgeti(L, -1, i);
3839

3940
lua_getfield(L, -1, "traceId");
@@ -69,14 +70,15 @@ static void lua_to_events(lua_State *L, struct ctrace_span *span)
6970
{
7071
struct ctrace_span_event *event;
7172
size_t count;
73+
size_t i;
7274
const char *name;
7375

7476
if (lua_type(L, -1) != LUA_TTABLE) {
7577
return;
7678
}
7779

7880
count = lua_objlen(L, -1);
79-
for (size_t i = 1; i <= count; i++) {
81+
for (i = 1; i <= count; i++) {
8082
lua_rawgeti(L, -1, i);
8183

8284
lua_getfield(L, -1, "name");
@@ -155,14 +157,15 @@ static void lua_to_spans(lua_State *L, struct ctrace *ctx,
155157
size_t count;
156158
struct ctrace_span *span;
157159
cfl_sds_t name;
160+
size_t i;
158161
struct ctrace_id *parent_span_id;
159162

160163
if (lua_type(L, -1) != LUA_TTABLE) {
161164
return;
162165
}
163166

164167
count = lua_objlen(L, -1);
165-
for (size_t i = 1; i <= count; i++) {
168+
for (i = 1; i <= count; i++) {
166169
lua_rawgeti(L, -1, i);
167170

168171
lua_getfield(L, -1, "name");
@@ -225,6 +228,7 @@ static void lua_to_scope_spans(lua_State *L, struct ctrace *ctx,
225228
struct ctrace_resource_span *resource_span)
226229
{
227230
size_t count;
231+
size_t i;
228232
struct ctrace_scope_span *scope_span;
229233

230234
if (lua_type(L, -1) != LUA_TTABLE) {
@@ -233,7 +237,7 @@ static void lua_to_scope_spans(lua_State *L, struct ctrace *ctx,
233237

234238
count = lua_objlen(L, -1);
235239

236-
for (size_t i = 1; i <= count; i++) {
240+
for (i = 1; i <= count; i++) {
237241
scope_span = ctr_scope_span_create(resource_span);
238242

239243
lua_rawgeti(L, -1, i);
@@ -258,6 +262,7 @@ static void lua_to_scope_spans(lua_State *L, struct ctrace *ctx,
258262
static void lua_to_resource_spans(lua_State *L, struct ctrace *ctx)
259263
{
260264
size_t count;
265+
size_t i;
261266
struct ctrace_resource_span *resource_span;
262267

263268
if (lua_type(L, -1) != LUA_TTABLE) {
@@ -266,7 +271,7 @@ static void lua_to_resource_spans(lua_State *L, struct ctrace *ctx)
266271

267272
count = lua_objlen(L, -1);
268273

269-
for (size_t i = 1; i <= count; i++) {
274+
for (i = 1; i <= count; i++) {
270275
resource_span = ctr_resource_span_create(ctx);
271276

272277
lua_rawgeti(L, -1, i);

plugins/processor_calyptia/lua_to_cfl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ bool lua_isinteger(lua_State *L, int index)
7676

7777
struct cfl_array *lua_array_to_variant(lua_State *L, int array_len)
7878
{
79+
int i;
7980
struct cfl_array *array = cfl_array_create(array_len);
8081

81-
for (int i = 1; i <= array_len; i++) {
82+
for (i = 1; i <= array_len; i++) {
8283
lua_rawgeti(L, -1, i);
8384
struct cfl_variant *variant = lua_to_variant(L, -1);
8485
cfl_array_append(array, variant);

0 commit comments

Comments
 (0)