rendered paste bodyIndex: src/library.c
===================================================================
--- src/library.c (Revision 4454)
+++ src/library.c (Arbeitskopie)
@@ -79,25 +79,63 @@
else if (!prev && next)
d->libFunctions = next;
- // tell the plugins we removed a function
- CompLibraryFunction localFunc = *func;
- localFunc.function = NULL;
- updateLibraryFunction(d, &localFunc);
+ updateLibraryFunction(d, func);
}
+static void addLibraryFunctionToList(CompLibraryFunction *func, void *function)
+{
+ CompLibraryFunctionList *list = (CompLibraryFunctionList*) malloc(sizeof(CompLibraryFunctionList));
+ list->function = function;
+ list->prev = NULL;
+ list->next = NULL;
+
+ if (func->tail) {
+ func->tail->next = list;
+ list->prev = func->tail;
+ } else if (!func->current) {
+ func->head = list;
+ func->current = list;
+ }
+
+ func->tail = list;
+}
+
+static void removeLibraryFunctionFromList(CompLibraryFunction *func, CompLibraryFunctionList *list)
+{
+ CompLibraryFunctionList *prev = list->prev;
+ CompLibraryFunctionList *next = list->next;
+
+ if (prev) {
+ if (next)
+ prev->next = next;
+ else
+ prev->next = NULL;
+ }
+ if (next) {
+ if (prev)
+ next->prev = prev;
+ else
+ next->prev = NULL;
+ }
+
+ if (func->head == list)
+ func->head = next;
+ if (func->tail == list)
+ func->tail = prev;
+ if (!next && !prev)
+ func->current = NULL;
+
+ free(list);
+}
+
CompLibraryFunction *addLibraryFunction(CompDisplay *d, char *name, void *function)
{
- // we don't want to register two functions
- // with the same name yet
- if (getLibraryFunction(d, name))
- return NULL;
-
CompLibraryFunction *func = (CompLibraryFunction*) malloc(sizeof(CompLibraryFunction));
func->name = name;
- func->function = function;
insertLibraryFunction(d, func);
+ addLibraryFunctionToList(func, function);
return func;
}
@@ -109,6 +147,10 @@
if (!func)
return;
+ CompLibraryFunctionList *list;
+ for (list = func->head; list; list = list->next)
+ removeLibraryFunctionFromList(func, list);
+
unhookLibraryFunction(d, func);
free(func);
}