Refactor workspaces to be stored in a TAILQ instead of an array

This fixes many problems we were having with a dynamically growing
array because of the realloc (pointers inside the area which was
allocated were no longer valid as soon as the realloc moved the
memory to another address).

Again, this is a rather big change, so expect problems and enable
core-dumps.
This commit is contained in:
Michael Stapelberg
2009-09-29 19:45:41 +02:00
parent 5a77081c55
commit 2b70e05ee9
15 changed files with 142 additions and 172 deletions

View File

@ -183,6 +183,7 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
while (!TAILQ_EMPTY(bindings)) {
bind = TAILQ_FIRST(bindings);
TAILQ_REMOVE(bindings, bind, bindings);
FREE(bind->translated_to);
FREE(bind->command);
FREE(bind);
}
@ -481,7 +482,7 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
LOG("setting name to \"%s\"\n", name);
if (*name != '\0')
workspace_set_name(&(workspaces[ws_num - 1]), name);
workspace_set_name(workspace_get(ws_num - 1), name);
free(ws_str);
continue;
}
@ -590,8 +591,8 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
REQUIRED_OPTION(font);
/* Set an empty name for every workspace which got no name */
for (int i = 0; i < num_workspaces; i++) {
Workspace *ws = &(workspaces[i]);
Workspace *ws;
TAILQ_FOREACH(ws, workspaces, workspaces) {
if (ws->name != NULL) {
/* If the font was not specified when the workspace name
* was loaded, we need to predict the text width now */
@ -601,7 +602,7 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
continue;
}
workspace_set_name(&(workspaces[i]), NULL);
workspace_set_name(ws, NULL);
}
return;