Changed free_config

This commit is contained in:
Scott Anderson 2017-05-13 14:26:13 +12:00
parent 6b05f44339
commit 861e32a8ab
2 changed files with 19 additions and 64 deletions

View file

@ -37,10 +37,10 @@ typedef void (*freefn_t)(void *arg);
void list_free_with(list_t *list, freefn_t callback);
/*
* Frees a list, calling a function on each element after it's
* dereferenced before doing do.
* Frees a list, calling a function on each dereferenced element.
* For example, if you have a list of char * allocated with malloc,
* it would be safe to use free with this function.
* callback would receive a char * instead of a char **, meaning it's
* safe to use free as the callback.
* If list is null, no action is taken.
* list must be a list of pointers.
*/
@ -84,7 +84,7 @@ void list_swap(list_t *list, size_t i1, size_t i2);
void *list_get(list_t *list, size_t index);
/*
* Gets an element of a list and dereferences it.
* Gets an dereferenced element of a list.
* For example, if you have a list of char *, this function
* will return a char * instead of a char **, unlike list_get.
* index must be less than the length of the list.
@ -127,10 +127,9 @@ ssize_t list_lsearch(const list_t *list, int compare(const void *key, const void
void list_foreach(list_t *list, void callback(void *item));
/*
* Calls a function on every item in the list, after dereferencing
* the element.
* For example, if you have a list of char *, you will receive a char *
* in callback, instead of a char **, unlike list_foreach.
* Calls a function on every dereferenced item in the list.
* For example, if you have a list of char *, callback will
* receive a char * instead of a char **, unlike list_foreach.
* list must be a list of pointers.
*/
void list_foreachp(list_t *list, void callback(void *item));

View file

@ -214,63 +214,19 @@ void free_config(struct sway_config *config) {
if (!config) {
return;
}
size_t i;
for (i = 0; config->symbols && i < config->symbols->length; ++i) {
free_variable(list_getp(config->symbols, i));
}
list_free(config->symbols);
for (i = 0; config->modes && i < config->modes->length; ++i) {
free_mode(list_getp(config->modes, i));
}
list_free(config->modes);
for (i = 0; config->bars && i < config->bars->length; ++i) {
free_bar(list_getp(config->bars, i));
}
list_free(config->bars);
free_flat_list(config->cmd_queue);
for (i = 0; config->workspace_outputs && i < config->workspace_outputs->length; ++i) {
free_workspace_output(list_getp(config->workspace_outputs, i));
}
list_free(config->workspace_outputs);
for (i = 0; config->pid_workspaces && i < config->pid_workspaces->length; ++i) {
free_pid_workspace(list_getp(config->pid_workspaces, i));
}
list_free(config->pid_workspaces);
for (i = 0; config->criteria && i < config->criteria->length; ++i) {
free_criteria(list_getp(config->criteria, i));
}
list_free(config->criteria);
for (i = 0; config->no_focus && i < config->no_focus->length; ++i) {
free_criteria(list_getp(config->no_focus, i));
}
list_free(config->no_focus);
for (i = 0; config->input_configs && i < config->input_configs->length; ++i) {
free_input_config(list_getp(config->input_configs, i));
}
list_free(config->input_configs);
for (i = 0; config->output_configs && i < config->output_configs->length; ++i) {
free_output_config(list_getp(config->output_configs, i));
}
list_free(config->output_configs);
for (i = 0; config->command_policies && i < config->command_policies->length; ++i) {
free_command_policy(list_getp(config->command_policies, i));
}
list_free(config->command_policies);
for (i = 0; config->feature_policies && i < config->feature_policies->length; ++i) {
free_feature_policy(list_getp(config->feature_policies, i));
}
list_free(config->feature_policies);
list_free_withp(config->symbols, (freefn_t)free_variable);
list_free_withp(config->modes, (freefn_t)free_mode);
list_free_withp(config->bars, (freefn_t)free_bar);
list_free_withp(config->cmd_queue, free);
list_free_withp(config->workspace_outputs, (freefn_t)free_workspace_output);
list_free_withp(config->pid_workspaces, (freefn_t)free_pid_workspace);
list_free_withp(config->criteria, (freefn_t)free_criteria);
list_free_withp(config->no_focus, (freefn_t)free_criteria);
list_free_withp(config->input_configs, (freefn_t)free_input_config);
list_free_withp(config->output_configs, (freefn_t)free_output_config);
list_free_withp(config->command_policies, (freefn_t)free_command_policy);
list_free_withp(config->feature_policies, (freefn_t)free_feature_policy);
list_free(config->active_bar_modifiers);
free_flat_list(config->config_chain);