diff options
-rw-r--r-- | .clang-format | 1 | ||||
-rw-r--r-- | cras/src/common/array.h | 4 | ||||
-rw-r--r-- | cras/src/server/cras_dsp_ini.c | 16 | ||||
-rw-r--r-- | cras/src/server/cras_dsp_mod_ladspa.c | 2 | ||||
-rw-r--r-- | cras/src/server/cras_dsp_pipeline.c | 58 | ||||
-rw-r--r-- | cras/src/server/cras_expr.c | 22 | ||||
-rw-r--r-- | cras/src/tests/.clang-format | 13 | ||||
-rw-r--r-- | cras/src/tests/array_unittest.cc | 2 |
8 files changed, 66 insertions, 52 deletions
diff --git a/.clang-format b/.clang-format index 97117ecb..c2b20759 100644 --- a/.clang-format +++ b/.clang-format @@ -69,6 +69,7 @@ ExperimentalAutoDetectBinPacking: false # | sed "s,^#define \([^[:space:]]*FOREACH[^[:space:]]*\)(.*$, - '\1'," \ # | sort | uniq ForEachMacros: + - 'ARRAY_ELEMENT_FOREACH' - 'DL_FOREACH' - 'DL_FOREACH_INTERNAL' - 'LL_FOREACH' diff --git a/cras/src/common/array.h b/cras/src/common/array.h index 716dab1a..0f295088 100644 --- a/cras/src/common/array.h +++ b/cras/src/common/array.h @@ -27,7 +27,7 @@ void f() ARRAY_APPEND(&a, 1.0); *ARRAY_APPEND_ZERO(&a) = 2.0; - FOR_ARRAY_ELEMENT(&a, i, p) { + ARRAY_ELEMENT_FOREACH(&a, i, p) { printf("%f\n", *p); // prints 1.0 2.0 } @@ -87,7 +87,7 @@ void f() /* Go through each element in the array a and assign index and pointer to the element to the variable i and ptr */ -#define FOR_ARRAY_ELEMENT(a, i, ptr) \ +#define ARRAY_ELEMENT_FOREACH(a, i, ptr) \ for ((i) = 0, (ptr) = (a)->element; (i) < (a)->count; \ (i)++, (ptr)++) diff --git a/cras/src/server/cras_dsp_ini.c b/cras/src/server/cras_dsp_ini.c index a8b3a9c2..ad417866 100644 --- a/cras/src/server/cras_dsp_ini.c +++ b/cras/src/server/cras_dsp_ini.c @@ -73,7 +73,7 @@ static int lookup_flow(struct ini *ini, const char *name) int i; const struct flow *flow; - FOR_ARRAY_ELEMENT(&ini->flows, i, flow) { + ARRAY_ELEMENT_FOREACH(&ini->flows, i, flow) { if (strcmp(flow->name, name) == 0) return i; } @@ -175,8 +175,8 @@ static void fill_flow_info(struct ini *ini) struct plugin **pplugin; int *pport; - FOR_ARRAY_ELEMENT(&ini->plugins, i, plugin) { - FOR_ARRAY_ELEMENT(&plugin->ports, j, port) { + ARRAY_ELEMENT_FOREACH(&ini->plugins, i, plugin) { + ARRAY_ELEMENT_FOREACH(&plugin->ports, j, port) { int flow_id = port->flow_id; if (flow_id == INVALID_FLOW_ID) continue; @@ -250,7 +250,7 @@ struct plugin *find_first_playback_sink_plugin(struct ini *ini) int i; struct plugin *plugin; - FOR_ARRAY_ELEMENT(&ini->plugins, i, plugin) { + ARRAY_ELEMENT_FOREACH(&ini->plugins, i, plugin) { if (strcmp(plugin->library, "builtin") != 0) continue; if (strcmp(plugin->label, "sink") != 0) @@ -416,7 +416,7 @@ void cras_dsp_ini_free(struct ini *ini) int i; /* free plugins */ - FOR_ARRAY_ELEMENT(&ini->plugins, i, p) { + ARRAY_ELEMENT_FOREACH(&ini->plugins, i, p) { cras_expr_expression_free(p->disable_expr); ARRAY_FREE(&p->ports); } @@ -467,13 +467,13 @@ void cras_dsp_ini_dump(struct dumper *d, struct ini *ini) dumpf(d, "ini->dict = %p\n", ini->dict); dumpf(d, "number of plugins = %d\n", ARRAY_COUNT(&ini->plugins)); - FOR_ARRAY_ELEMENT(&ini->plugins, i, plugin) { + ARRAY_ELEMENT_FOREACH(&ini->plugins, i, plugin) { dumpf(d, "[plugin %d: %s]\n", i, plugin->title); dumpf(d, "library=%s\n", plugin->library); dumpf(d, "label=%s\n", plugin->label); dumpf(d, "purpose=%s\n", plugin->purpose); dumpf(d, "disable=%p\n", plugin->disable_expr); - FOR_ARRAY_ELEMENT(&plugin->ports, j, port) { + ARRAY_ELEMENT_FOREACH(&plugin->ports, j, port) { dumpf(d, " [%s port %d] type=%s, flow_id=%d, value=%g\n", port_direction_str(port->direction), j, @@ -483,7 +483,7 @@ void cras_dsp_ini_dump(struct dumper *d, struct ini *ini) } dumpf(d, "number of flows = %d\n", ARRAY_COUNT(&ini->flows)); - FOR_ARRAY_ELEMENT(&ini->flows, i, flow) { + ARRAY_ELEMENT_FOREACH(&ini->flows, i, flow) { dumpf(d, " [flow %d] %s, %s, %s:%d -> %s:%d\n", i, flow->name, port_type_str(flow->type), plugin_title(flow->from), flow->from_port, diff --git a/cras/src/server/cras_dsp_mod_ladspa.c b/cras/src/server/cras_dsp_mod_ladspa.c index 9110ad40..8d72f393 100644 --- a/cras/src/server/cras_dsp_mod_ladspa.c +++ b/cras/src/server/cras_dsp_mod_ladspa.c @@ -134,7 +134,7 @@ static int verify_plugin_descriptor(struct plugin *plugin, return -1; } - FOR_ARRAY_ELEMENT(&plugin->ports, i, port) { + ARRAY_ELEMENT_FOREACH(&plugin->ports, i, port) { LADSPA_PortDescriptor port_desc = desc->PortDescriptors[i]; if ((port->direction == PORT_INPUT) != !!(port_desc & LADSPA_PORT_INPUT)) { diff --git a/cras/src/server/cras_dsp_pipeline.c b/cras/src/server/cras_dsp_pipeline.c index 699c86bf..f99f8c7d 100644 --- a/cras/src/server/cras_dsp_pipeline.c +++ b/cras/src/server/cras_dsp_pipeline.c @@ -150,7 +150,7 @@ static struct instance *find_instance_by_plugin(instance_array *instances, int i; struct instance *instance; - FOR_ARRAY_ELEMENT(instances, i, instance) { + ARRAY_ELEMENT_FOREACH(instances, i, instance) { if (instance->plugin == plugin) return instance; } @@ -197,7 +197,7 @@ static int find_origin_port(struct ini *ini, instance_array *instances, k = 0; found = 0; - FOR_ARRAY_ELEMENT(&plugin->ports, i, port) { + ARRAY_ELEMENT_FOREACH(&plugin->ports, i, port) { if (index == i) { found = 1; break; @@ -209,7 +209,7 @@ static int find_origin_port(struct ini *ini, instance_array *instances, return -1; found = 0; - FOR_ARRAY_ELEMENT(&plugin->ports, i, port) { + ARRAY_ELEMENT_FOREACH(&plugin->ports, i, port) { if (port->direction == PORT_INPUT && port->type == type) { if (k-- == 0) { index = i; @@ -237,7 +237,7 @@ static struct audio_port *find_output_audio_port(instance_array *instances, if (!instance) return NULL; - FOR_ARRAY_ELEMENT(&instance->output_audio_ports, i, audio_port) { + ARRAY_ELEMENT_FOREACH(&instance->output_audio_ports, i, audio_port) { if (audio_port->original_index == index) return audio_port; } @@ -257,7 +257,7 @@ static struct control_port *find_output_control_port(instance_array *instances, if (!instance) return NULL; - FOR_ARRAY_ELEMENT(&instance->output_control_ports, i, control_port) { + ARRAY_ELEMENT_FOREACH(&instance->output_control_ports, i, control_port) { if (control_port->original_index == index) return control_port; } @@ -291,7 +291,7 @@ static int topological_sort(struct pipeline *pipeline, return 0; visited[index] = 1; - FOR_ARRAY_ELEMENT(&plugin->ports, i, port) { + ARRAY_ELEMENT_FOREACH(&plugin->ports, i, port) { if (port->flow_id == INVALID_FLOW_ID) continue; flow_id = port->flow_id; @@ -313,7 +313,7 @@ static int topological_sort(struct pipeline *pipeline, instance->plugin = plugin; /* constructs audio and control ports for the instance */ - FOR_ARRAY_ELEMENT(&plugin->ports, i, port) { + ARRAY_ELEMENT_FOREACH(&plugin->ports, i, port) { int need_connect = (port->flow_id != INVALID_FLOW_ID && port->direction == PORT_INPUT); struct plugin *origin = NULL; @@ -378,7 +378,7 @@ static struct plugin *find_enabled_builtin_plugin(struct ini *ini, int i; struct plugin *plugin, *found = NULL; - FOR_ARRAY_ELEMENT(&ini->plugins, i, plugin) { + ARRAY_ELEMENT_FOREACH(&ini->plugins, i, plugin) { if (strcmp(plugin->library, "builtin") != 0) continue; if (strcmp(plugin->label, label) != 0) @@ -481,7 +481,7 @@ static void use_buffers(char *busy, audio_port_array *audio_ports) int i, k = 0; struct audio_port *audio_port; - FOR_ARRAY_ELEMENT(audio_ports, i, audio_port) { + ARRAY_ELEMENT_FOREACH(audio_ports, i, audio_port) { while (busy[k]) k++; audio_port->buf_index = k; @@ -494,7 +494,7 @@ static void unuse_buffers(char *busy, audio_port_array *audio_ports) int i; struct audio_port *audio_port; - FOR_ARRAY_ELEMENT(audio_ports, i, audio_port) { + ARRAY_ELEMENT_FOREACH(audio_ports, i, audio_port) { busy[audio_port->buf_index] = 0; } } @@ -508,7 +508,7 @@ static int allocate_buffers(struct pipeline *pipeline) char *busy; /* first figure out how many buffers do we need */ - FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) { + ARRAY_ELEMENT_FOREACH(&pipeline->instances, i, instance) { int in = ARRAY_COUNT(&instance->input_audio_ports); int out = ARRAY_COUNT(&instance->output_audio_ports); @@ -545,12 +545,12 @@ static int allocate_buffers(struct pipeline *pipeline) /* Now assign buffer index for each instance's input/output ports */ busy = calloc(peak_buf, sizeof(*busy)); - FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) { + ARRAY_ELEMENT_FOREACH(&pipeline->instances, i, instance) { int j; struct audio_port *audio_port; /* Collect input buffers from upstream */ - FOR_ARRAY_ELEMENT(&instance->input_audio_ports, j, audio_port) { + ARRAY_ELEMENT_FOREACH(&instance->input_audio_ports, j, audio_port) { audio_port->buf_index = audio_port->peer->buf_index; } @@ -598,7 +598,7 @@ int cras_dsp_pipeline_load(struct pipeline *pipeline) int i; struct instance *instance; - FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) { + ARRAY_ELEMENT_FOREACH(&pipeline->instances, i, instance) { struct plugin *plugin = instance->plugin; if (load_module(plugin, instance) != 0) return -1; @@ -616,7 +616,7 @@ static void calculate_audio_delay(struct pipeline *pipeline) int i; struct instance *instance; - FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) { + ARRAY_ELEMENT_FOREACH(&pipeline->instances, i, instance) { struct dsp_module *module = instance->module; audio_port_array *audio_in = &instance->input_audio_ports; struct audio_port *audio_port; @@ -625,7 +625,7 @@ static void calculate_audio_delay(struct pipeline *pipeline) /* Finds the max delay of all modules that provide input to this * instance. */ - FOR_ARRAY_ELEMENT(audio_in, j, audio_port) { + ARRAY_ELEMENT_FOREACH(audio_in, j, audio_port) { struct instance *upstream = find_instance_by_plugin( &pipeline->instances, audio_port->peer->plugin); delay = MAX(upstream->total_delay, delay); @@ -640,7 +640,7 @@ int cras_dsp_pipeline_instantiate(struct pipeline *pipeline, int sample_rate) int i; struct instance *instance; - FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) { + ARRAY_ELEMENT_FOREACH(&pipeline->instances, i, instance) { struct dsp_module *module = instance->module; if (module->instantiate(module, sample_rate) != 0) return -1; @@ -649,7 +649,7 @@ int cras_dsp_pipeline_instantiate(struct pipeline *pipeline, int sample_rate) } pipeline->sample_rate = sample_rate; - FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) { + ARRAY_ELEMENT_FOREACH(&pipeline->instances, i, instance) { audio_port_array *audio_in = &instance->input_audio_ports; audio_port_array *audio_out = &instance->output_audio_ports; control_port_array *control_in = &instance->input_control_ports; @@ -661,7 +661,7 @@ int cras_dsp_pipeline_instantiate(struct pipeline *pipeline, int sample_rate) struct dsp_module *module = instance->module; /* connect audio ports */ - FOR_ARRAY_ELEMENT(audio_in, j, audio_port) { + ARRAY_ELEMENT_FOREACH(audio_in, j, audio_port) { float *buf = pipeline->buffers[audio_port->buf_index]; module->connect_port(module, audio_port->original_index, @@ -670,7 +670,7 @@ int cras_dsp_pipeline_instantiate(struct pipeline *pipeline, int sample_rate) audio_port->buf_index, instance->plugin->title, audio_port->original_index); } - FOR_ARRAY_ELEMENT(audio_out, j, audio_port) { + ARRAY_ELEMENT_FOREACH(audio_out, j, audio_port) { float *buf = pipeline->buffers[audio_port->buf_index]; module->connect_port(module, audio_port->original_index, @@ -681,7 +681,7 @@ int cras_dsp_pipeline_instantiate(struct pipeline *pipeline, int sample_rate) } /* connect control ports */ - FOR_ARRAY_ELEMENT(control_in, j, control_port) { + ARRAY_ELEMENT_FOREACH(control_in, j, control_port) { /* Note for input control ports which has a * peer, we use &control_port->peer->value, so * we can get the peer port's output value @@ -697,7 +697,7 @@ int cras_dsp_pipeline_instantiate(struct pipeline *pipeline, int sample_rate) control_port->value, instance->plugin->title, control_port->original_index); } - FOR_ARRAY_ELEMENT(control_out, j, control_port) { + ARRAY_ELEMENT_FOREACH(control_out, j, control_port) { module->connect_port(module, control_port->original_index, &control_port->value); @@ -717,7 +717,7 @@ void cras_dsp_pipeline_deinstantiate(struct pipeline *pipeline) int i; struct instance *instance; - FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) { + ARRAY_ELEMENT_FOREACH(&pipeline->instances, i, instance) { struct dsp_module *module = instance->module; if (instance->instantiated) { module->deinstantiate(module); @@ -759,7 +759,7 @@ static float *find_buffer(struct pipeline *pipeline, int i; struct audio_port *audio_port; - FOR_ARRAY_ELEMENT(audio_ports, i, audio_port) { + ARRAY_ELEMENT_FOREACH(audio_ports, i, audio_port) { if (audio_port->original_index == index) return pipeline->buffers[audio_port->buf_index]; } @@ -793,7 +793,7 @@ void cras_dsp_pipeline_run(struct pipeline *pipeline, int sample_count) int i; struct instance *instance; - FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) { + ARRAY_ELEMENT_FOREACH(&pipeline->instances, i, instance) { struct dsp_module *module = instance->module; module->run(module, sample_count); } @@ -882,7 +882,7 @@ void cras_dsp_pipeline_free(struct pipeline *pipeline) int i; struct instance *instance; - FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) { + ARRAY_ELEMENT_FOREACH(&pipeline->instances, i, instance) { struct dsp_module *module = instance->module; instance->plugin = NULL; ARRAY_FREE(&instance->input_audio_ports); @@ -920,7 +920,7 @@ static void dump_audio_ports(struct dumper *d, const char *name, return; dumpf(d, " %s (%d) =\n", name, n); - FOR_ARRAY_ELEMENT(audio_ports, i, audio_port) { + ARRAY_ELEMENT_FOREACH(audio_ports, i, audio_port) { dumpf(d, " %p, peer %p, orig=%d, buf=%d\n", audio_port, audio_port->peer, audio_port->original_index, audio_port->buf_index); @@ -938,7 +938,7 @@ static void dump_control_ports(struct dumper *d, const char *name, return; dumpf(d, " %s (%d) =\n", name, ARRAY_COUNT(control_ports)); - FOR_ARRAY_ELEMENT(control_ports, i, control_port) { + ARRAY_ELEMENT_FOREACH(control_ports, i, control_port) { dumpf(d, " %p, peer %p, orig=%d, value=%g\n", control_port, control_port->peer, control_port->original_index, control_port->value); @@ -973,7 +973,7 @@ void cras_dsp_pipeline_dump(struct dumper *d, struct pipeline *pipeline) / pipeline->total_samples * pipeline->sample_rate * 100); dumpf(d, " instances (%d):\n", ARRAY_COUNT(&pipeline->instances)); - FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) { + ARRAY_ELEMENT_FOREACH(&pipeline->instances, i, instance) { struct dsp_module *module = instance->module; dumpf(d, " [%d]%s mod=%p, total delay=%d\n", i, instance->plugin->title, module, diff --git a/cras/src/server/cras_expr.c b/cras/src/server/cras_expr.c index 5d8767fa..1a72c409 100644 --- a/cras/src/server/cras_expr.c +++ b/cras/src/server/cras_expr.c @@ -120,7 +120,7 @@ static struct cras_expr_value *find_value(struct cras_expr_env *env, int i; const char **key; - FOR_ARRAY_ELEMENT(&env->keys, i, key) { + ARRAY_ELEMENT_FOREACH(&env->keys, i, key) { if (strcmp(*key, name) == 0) return ARRAY_ELEMENT(&env->values, i); } @@ -178,7 +178,7 @@ static void function_and(cras_expr_value_array *operands, } /* if there is any #f, return it */ - FOR_ARRAY_ELEMENT(operands, i, value) { + ARRAY_ELEMENT_FOREACH(operands, i, value) { if (i == 0) continue; /* ignore "and" itself */ if (value->type == CRAS_EXPR_VALUE_TYPE_BOOLEAN && @@ -198,7 +198,7 @@ static void function_or(cras_expr_value_array *operands, int i; struct cras_expr_value *value; - FOR_ARRAY_ELEMENT(operands, i, value) { + ARRAY_ELEMENT_FOREACH(operands, i, value) { if (i == 0) continue; /* ignore "or" itself */ if (value->type != CRAS_EXPR_VALUE_TYPE_BOOLEAN || @@ -216,7 +216,7 @@ static char function_equal_real(cras_expr_value_array *operands) int i; struct cras_expr_value *value, *prev; - FOR_ARRAY_ELEMENT(operands, i, value) { + ARRAY_ELEMENT_FOREACH(operands, i, value) { if (i <= 1) continue; /* ignore equal? and first operand */ /* compare with the previous operand */ @@ -311,11 +311,11 @@ void cras_expr_env_free(struct cras_expr_env *env) const char **key; struct cras_expr_value *value; - FOR_ARRAY_ELEMENT(&env->keys, i, key) { + ARRAY_ELEMENT_FOREACH(&env->keys, i, key) { free((char *)*key); } - FOR_ARRAY_ELEMENT(&env->values, i, value) { + ARRAY_ELEMENT_FOREACH(&env->values, i, value) { cras_expr_value_free(value); } @@ -330,7 +330,7 @@ void cras_expr_env_dump(struct dumper *d, const struct cras_expr_env *env) struct cras_expr_value *value; dumpf(d, "--- environment ---\n"); - FOR_ARRAY_ELEMENT(&env->keys, i, key) { + ARRAY_ELEMENT_FOREACH(&env->keys, i, key) { dumpf(d, " key=%s,", *key); dumpf(d, " value="); value = ARRAY_ELEMENT(&env->values, i); @@ -527,7 +527,7 @@ static void dump_one_expression(struct dumper *d, break; case EXPR_TYPE_COMPOUND: dumpf(d, "%*scompound", indent, ""); - FOR_ARRAY_ELEMENT(&expr->u.children, i, sub) { + ARRAY_ELEMENT_FOREACH(&expr->u.children, i, sub) { dump_one_expression(d, *sub, indent + 2); } break; @@ -558,7 +558,7 @@ void cras_expr_expression_free(struct cras_expr_expression *expr) { int i; struct cras_expr_expression **psub; - FOR_ARRAY_ELEMENT(&expr->u.children, i, psub) { + ARRAY_ELEMENT_FOREACH(&expr->u.children, i, psub) { cras_expr_expression_free(*psub); } ARRAY_FREE(&expr->u.children); @@ -599,7 +599,7 @@ void cras_expr_expression_eval(struct cras_expr_expression *expr, cras_expr_value_array values = ARRAY_INIT; struct cras_expr_value *value; - FOR_ARRAY_ELEMENT(&expr->u.children, i, psub) { + ARRAY_ELEMENT_FOREACH(&expr->u.children, i, psub) { value = ARRAY_APPEND_ZERO(&values); cras_expr_expression_eval(*psub, env, value); } @@ -615,7 +615,7 @@ void cras_expr_expression_eval(struct cras_expr_expression *expr, syslog(LOG_ERR, "empty compound expression?"); } - FOR_ARRAY_ELEMENT(&values, i, value) { + ARRAY_ELEMENT_FOREACH(&values, i, value) { cras_expr_value_free(value); } diff --git a/cras/src/tests/.clang-format b/cras/src/tests/.clang-format index 3f19e616..a675ede3 100644 --- a/cras/src/tests/.clang-format +++ b/cras/src/tests/.clang-format @@ -1 +1,14 @@ BasedOnStyle: Chromium + +# Taken from: +# git grep -h '^#define [^[:space:]]*FOREACH[^[:space:]]*(' cras/ \ +# | sed "s,^#define \([^[:space:]]*FOREACH[^[:space:]]*\)(.*$, - '\1'," \ +# | sort | uniq + +ForEachMacros: + - 'ARRAY_ELEMENT_FOREACH' + - 'DL_FOREACH' + - 'DL_FOREACH_INTERNAL' + - 'LL_FOREACH' + - 'LL_FOREACH_SAFE' + diff --git a/cras/src/tests/array_unittest.cc b/cras/src/tests/array_unittest.cc index 00bdf065..175994ba 100644 --- a/cras/src/tests/array_unittest.cc +++ b/cras/src/tests/array_unittest.cc @@ -94,7 +94,7 @@ TEST(ArrayTest, ForLoop) { int expectedIndex = 0; double expectedValue = 0; - FOR_ARRAY_ELEMENT(&a, i, p) { + ARRAY_ELEMENT_FOREACH(&a, i, p) { EXPECT_EQ(expectedIndex, i); EXPECT_EQ(expectedValue, *p); expectedIndex++; |