[ekg2-commit] r3904 - in trunk: ekg plugins/logs: trunk/ekg/commands.c trunk/ekg/dynstuff.c trunk/ekg/dynstuff.h trunk/ekg/log.c trunk/ekg/msgqueue.c trunk/ekg/plugins.c trunk/ekg/stuff.c trunk/plugins/logs/main.c
SVN commit
svn w toxygen.net
Sob, 15 Mar 2008, 14:11:54 CET
Author: peres
Date: 2008-03-15 14:11:53 +0100 (Sat, 15 Mar 2008)
New Revision: 3904
Modified:
trunk/ekg/commands.c
trunk/ekg/dynstuff.c
trunk/ekg/dynstuff.h
trunk/ekg/log.c
trunk/ekg/msgqueue.c
trunk/ekg/plugins.c
trunk/ekg/stuff.c
trunk/plugins/logs/main.c
Log:
Revback lists3 stupidization.
Also return void* in LIST_REMOVE2 & LIST_UNLINK2.
Anyone using optimizations: please ignore strict aliasing warnings.
Modified: trunk/ekg/commands.c
===================================================================
--- trunk/ekg/commands.c 2008-03-15 08:48:11 UTC (rev 3903)
+++ trunk/ekg/commands.c 2008-03-15 13:11:53 UTC (rev 3904)
@@ -4021,7 +4021,7 @@
for (p = plugins; p;) {
plugin_t *next;
- next = (plugin_t *) LIST_UNLINK2(&plugins, p);
+ next = LIST_UNLINK2(&plugins, p);
plugin_register(p, -254);
p = next;
Modified: trunk/ekg/dynstuff.c
===================================================================
--- trunk/ekg/dynstuff.c 2008-03-15 08:48:11 UTC (rev 3903)
+++ trunk/ekg/dynstuff.c 2008-03-15 13:11:53 UTC (rev 3904)
@@ -131,6 +131,65 @@
return list_add_sorted(list, data, NULL);
}
+void *list_add_sorted3(list_t *list, list_t new, int (*comparision)(void *, void *))
+{
+ list_t tmp;
+
+ if (!list) {
+ errno = EFAULT;
+ return NULL;
+ }
+
+ new->next = NULL;
+ if (!(tmp = *list)) {
+ *list = new;
+ } else {
+ if (!comparision) {
+ while (tmp->next)
+ tmp = tmp->next;
+ tmp->next = new;
+ } else {
+ list_t prev = NULL;
+
+ while (comparision(new, tmp) > 0) {
+ prev = tmp;
+ tmp = tmp->next;
+ if (!tmp)
+ break;
+ }
+
+ if (!prev) {
+ new->next = *list;
+ *list = new;
+ } else {
+ prev->next = new;
+ new->next = tmp;
+ }
+ }
+ }
+
+ return new;
+}
+
+void *list_add_beginning3(list_t *list, list_t new)
+{
+ if (!list) {
+ errno = EFAULT;
+ return NULL;
+ }
+
+ new->next = *list;
+ *list = new;
+
+ return new;
+
+}
+
+void *list_add3(list_t *list, list_t new)
+{
+ return list_add_sorted3(list, new, NULL);
+}
+
/**
* list_remove_safe()
*
@@ -228,6 +287,60 @@
return 0;
}
+void *list_remove3(list_t *list, list_t elem, void (*func)(list_t data)) {
+ list_t tmp, last = NULL;
+ void *ret = NULL;
+
+ if (!list) {
+ errno = EFAULT;
+ return ret;
+ }
+
+ tmp = *list;
+ if (tmp && tmp == elem) {
+ *list = ret = tmp->next;
+ } else {
+ for (; tmp && tmp != elem; tmp = tmp->next)
+ last = tmp;
+ if (!tmp) {
+ errno = ENOENT;
+ return ret;
+ }
+ last->next = ret = tmp->next;
+ }
+
+ if (func)
+ func(tmp);
+ xfree(tmp);
+
+ return ret;
+}
+
+void *list_unlink3(list_t *list, list_t elem) {
+ list_t tmp, last = NULL;
+ void *ret = NULL;
+
+ if (!list) {
+ errno = EFAULT;
+ return ret;
+ }
+
+ tmp = *list;
+ if (tmp && tmp == elem) {
+ *list = ret = tmp->next;
+ } else {
+ for (; tmp && tmp != elem; tmp = tmp->next)
+ last = tmp;
+ if (!tmp) {
+ errno = ENOENT;
+ return ret;
+ }
+ last->next = ret = tmp->next;
+ }
+
+ return ret;
+}
+
/**
* list_remove()
*
@@ -272,6 +385,18 @@
return NULL;
}
+void *list_get_nth3(list_t list, int id) {
+ while (list) {
+ if ((--id) == 0)
+ return list;
+
+ list = list->next;
+ }
+
+ errno = ENOENT;
+ return NULL;
+}
+
void list_resort(list_t *list, int (*comparision)(void *, void *)) {
list_t tmplist = NULL;
list_t l = *list;
@@ -289,6 +414,21 @@
*list = tmplist;
}
+void list_resort3(list_t *list, int (*comparision)(void *, void *)) {
+ list_t tmplist = NULL;
+ list_t l = *list;
+
+ while (l) {
+ list_t cur = l;
+
+ l = l->next;
+
+ list_add_sorted3(&tmplist, cur, comparision);
+ }
+
+ *list = tmplist;
+}
+
/**
* list_count()
*
@@ -324,6 +464,23 @@
return 0;
}
+int list_destroy3(list_t list, void (*func)(void *)) {
+ list_t tmp;
+
+ while (list) {
+ if (func)
+ func(list);
+
+ tmp = list->next;
+
+ xfree(list);
+
+ list = tmp;
+ }
+
+ return 0;
+}
+
/**
* list_destroy()
*
@@ -348,177 +505,7 @@
return list_destroy2(list, free_data ? xfree : NULL);
}
-/** lists3 **/
-#define NEXT(a) *((void **) a) /* like l->next */
-#define FIRST(a) *((void **) a) /* like *l with list_t* */
-
-void *list_add_sorted3(void *list, void *new, int (*comparison)(void *, void *))
-{
- void *tmp;
-
- if (!list) {
- errno = EFAULT;
- return NULL;
- }
-
- NEXT(new) = NULL;
- if (!(tmp = FIRST(list))) {
- FIRST(list) = new;
- } else {
- if (!comparison) {
- while (NEXT(tmp))
- tmp = NEXT(tmp);
- NEXT(tmp) = new;
- } else {
- void *prev = NULL;
-
- while (comparison(new, tmp) > 0) {
- prev = tmp;
- tmp = NEXT(tmp);
- if (!tmp)
- break;
- }
-
- if (!prev) {
- NEXT(new) = FIRST(list);
- FIRST(list) = new;
- } else {
- NEXT(prev) = new;
- NEXT(new) = tmp;
- }
- }
- }
-
- return new;
-}
-
-void *list_add_beginning3(void *list, void *new)
-{
- if (!list) {
- errno = EFAULT;
- return NULL;
- }
-
- NEXT(new) = FIRST(list);
- FIRST(list) = new;
-
- return new;
-
-}
-
-void *list_add3(void *list, void *new)
-{
- return list_add_sorted3(list, new, NULL);
-}
-
-void *list_remove3(void *list, void *elem, void (*func)(list_t data)) {
- void *tmp, *last = NULL;
- void *ret = NULL;
-
- if (!list) {
- errno = EFAULT;
- return ret;
- }
-
- tmp = FIRST(list);
- if (tmp && tmp == elem) {
- FIRST(list) = ret = NEXT(tmp);
- } else {
- for (; tmp && tmp != elem; tmp = NEXT(tmp))
- last = tmp;
- if (!tmp) {
- errno = ENOENT;
- return ret;
- }
- NEXT(last) = ret = NEXT(tmp);
- }
-
- if (func)
- func(tmp);
- xfree(tmp);
-
- return ret;
-}
-
-void *list_unlink3(void *list, void *elem) {
- void *tmp, *last = NULL;
- void *ret = NULL;
-
- if (!list) {
- errno = EFAULT;
- return ret;
- }
-
- tmp = FIRST(list);
- if (tmp && tmp == elem) {
- FIRST(list) = ret = NEXT(tmp);
- } else {
- for (; tmp && tmp != elem; tmp = NEXT(tmp))
- last = tmp;
- if (!tmp) {
- errno = ENOENT;
- return ret;
- }
- NEXT(last) = ret = NEXT(tmp);
- }
-
- return ret;
-}
-
-int list_count3(void *first) {
- int count = 0;
-
- for (; first; first = NEXT(first))
- count++;
-
- return count;
-}
-
-void *list_get_nth3(void *first, int id) {
- while (first) {
- if ((--id) == 0)
- return first;
-
- first = NEXT(first);
- }
-
- errno = ENOENT;
- return NULL;
-}
-
-void list_resort3(void *list, int (*comparision)(void *, void *)) {
- void *tmplist = NULL;
- void *l = FIRST(list);
-
- while (l) {
- void *cur = l;
-
- l = NEXT(l);
-
- list_add_sorted3(&tmplist, cur, comparision);
- }
-
- FIRST(list) = tmplist;
-}
-
-int list_destroy3(void *first, void (*func)(void *)) {
- void *tmp;
-
- while (first) {
- if (func)
- func(first);
-
- tmp = NEXT(first);
-
- xfree(first);
-
- first = tmp;
- }
-
- return 0;
-}
-
/* list_t compatibility toolkit ( ; */
/* helper handler for using list_remove3() w/ list_t
Modified: trunk/ekg/dynstuff.h
===================================================================
--- trunk/ekg/dynstuff.h 2008-03-15 08:48:11 UTC (rev 3903)
+++ trunk/ekg/dynstuff.h 2008-03-15 13:11:53 UTC (rev 3904)
@@ -74,60 +74,50 @@
#ifndef EKG2_WIN32_NOFUNCTION
#define LIST_ADD_COMPARE(x, type) int x(const type data1, const type data2)
#define LIST_ADD_SORTED(list, data, comp) list_add_sorted(list, data, (void *) comp)
+#define LIST_ADD_SORTED2(list, data, comp) list_add_sorted3((list_t *) list, (list_t) data, (void *) comp)
+#define LIST_ADD_BEGINNING2(list, data) list_add_beginning3((list_t *) list, (list_t) data)
+#define LIST_ADD2(list, data) list_add3((list_t *) list, (list_t) data)
+#define LIST_COUNT2(list) list_count((list_t) list)
+#define LIST_GET_NTH2(list, id) list_get_nth3((list_t) list, id)
#define LIST_RESORT(list, comp) list_resort(list, (void *) comp)
+#define LIST_RESORT2(list, comp) list_resort3((list_t *) list, (void *) comp)
+
#define LIST_REMOVE(list, data, func) list_remove2(list, data, (void *) func)
+#define LIST_REMOVE2(list, elem, func) list_remove3((list_t *) list, (list_t) elem, (void *) func)
+#define LIST_UNLINK2(list, elem) list_unlink3((list_t *) list, (list_t) elem)
#define LIST_FREE_ITEM(x, type) void x(type data)
#define LIST_DESTROY(list, func) list_destroy2(list, (void *) func)
+#define LIST_DESTROY2(list, func) list_destroy3((list_t) list, (void *) func)
void *list_add(list_t *list, void *data);
void *list_add_beginning(list_t *list, void *data);
void *list_add_sorted(list_t *list, void *data, int (*comparision)(void *, void *));
+void *list_add3(list_t *list, list_t new);
+void *list_add_beginning3(list_t *list, list_t new);
+void *list_add_sorted3(list_t *list, list_t new, int (*comparision)(void *, void *));
+
+
int list_count(list_t list);
void *list_get_nth(list_t list, int id);
+void *list_get_nth3(list_t list, int id);
void list_resort(list_t *list, int (*comparision)(void *, void *));
+void list_resort3(list_t *list, int (*comparision)(void *, void *));
int list_remove(list_t *list, void *data, int free_data);
int list_remove2(list_t *list, void *data, void (*func)(void *));
+void *list_remove3(list_t *list, list_t elem, void (*func)(list_t));
+void *list_unlink3(list_t *list, list_t elem);
int list_destroy(list_t list, int free_data);
int list_destroy2(list_t list, void (*func)(void *));
+int list_destroy3(list_t list, void (*func)(void *));
void list_cleanup(list_t *list);
int list_remove_safe(list_t *list, void *data, int free_data);
-/** lists3 **/
-
-#define LIST_ADD_SORTED2(list, data, comp) list_add_sorted3(list, data, (void *) comp)
-#define LIST_ADD_BEGINNING2(list, data) list_add_beginning3(list, data)
-#define LIST_ADD2(list, data) list_add3(list, data)
-
-#define LIST_COUNT2(list) list_count3(list)
-#define LIST_GET_NTH2(first, id) list_get_nth3(first, id)
-#define LIST_RESORT2(list, comp) list_resort3(list, (void *) comp)
-
-#define LIST_REMOVE2(list, elem, func) list_remove3(list, elem, (void *) func)
-#define LIST_UNLINK2(list, elem) list_unlink3(list, elem)
-#define LIST_DESTROY2(first, func) list_destroy3(first, (void *) func)
-
-/* This is pretty fscked up, but some ppl like no-stupid-warnings more than readable types,
- * so here we use void* for almost everything; *list shall be pointer to pointer to var
- * pointing on first elem (like list_t*), *first only ptr to first element (like list_t). */
-
-void *list_add3(void *list, void *new);
-void *list_add_beginning3(void *list, void *new);
-void *list_add_sorted3(void *list, void *new, int (*comparison)(void *, void *));
-
-int list_count3(void *first);
-void *list_get_nth3(void *first, int id);
-void list_resort3(void *list, int (*comparison)(void *, void *));
-
-void *list_remove3(void *list, void *elem, void (*func)(list_t));
-void *list_unlink3(void *list, void *elem);
-int list_destroy3(void *first, void (*func)(void *));
-
LIST_FREE_ITEM(list_t_free_item, list_t);
list_t list_t_new(void *data);
#endif
Modified: trunk/ekg/log.c
===================================================================
--- trunk/ekg/log.c 2008-03-15 08:48:11 UTC (rev 3903)
+++ trunk/ekg/log.c 2008-03-15 13:11:53 UTC (rev 3904)
@@ -112,7 +112,7 @@
for (ll = lasts; ll; ) {
if (!xstrcasecmp(uid, ll->uid))
- ll = (struct last *) LIST_REMOVE2(&lasts, ll, list_last_free);
+ ll = LIST_REMOVE2(&lasts, ll, list_last_free);
else
ll = ll->next;
}
Modified: trunk/ekg/msgqueue.c
===================================================================
--- trunk/ekg/msgqueue.c 2008-03-15 08:48:11 UTC (rev 3903)
+++ trunk/ekg/msgqueue.c 2008-03-15 13:11:53 UTC (rev 3904)
@@ -92,7 +92,7 @@
for (m = msg_queue; m; ) {
if (!xstrcasecmp(m->rcpts, uid)) {
- m = (msg_queue_t *) LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
+ m = LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
res = 0;
} else
m = m->next;
@@ -120,7 +120,7 @@
for (m = msg_queue; m; ) {
if (!xstrcasecmp(m->seq, seq)) {
- m = (msg_queue_t *) LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
+ m = LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
res = 0;
} else
m = m->next;
@@ -171,7 +171,7 @@
continue;
/* wiadomość wysyłana z nieistniejącej już sesji? usuwamy. */
else if (!(s = session_find(m->session))) {
- next = (msg_queue_t *) LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
+ next = LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
continue;
}
@@ -186,7 +186,7 @@
}
command_exec_format(NULL, s, 1, cmd, m->rcpts, m->message);
- next = (msg_queue_t *) LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
+ next = LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
ret = 0;
}
Modified: trunk/ekg/plugins.c
===================================================================
--- trunk/ekg/plugins.c 2008-03-15 08:48:11 UTC (rev 3903)
+++ trunk/ekg/plugins.c 2008-03-15 13:11:53 UTC (rev 3904)
@@ -547,7 +547,7 @@
for (i = idles; i; ) {
if (i->plugin == p)
- i = (idle_t *) LIST_REMOVE2(&idles, i, NULL);
+ i = LIST_REMOVE2(&idles, i, NULL);
else
i = i->next;
}
Modified: trunk/ekg/stuff.c
===================================================================
--- trunk/ekg/stuff.c 2008-03-15 08:48:11 UTC (rev 3903)
+++ trunk/ekg/stuff.c 2008-03-15 13:11:53 UTC (rev 3904)
@@ -345,7 +345,7 @@
command_remove(NULL, a->name);
xfree(a->name);
list_destroy(a->commands, 1);
- if ((tmp = (alias_t *) LIST_REMOVE2(&aliases, a, NULL)))
+ if ((tmp = LIST_REMOVE2(&aliases, a, NULL)))
next = tmp;
removed = 1;
}
@@ -909,7 +909,7 @@
if (name)
printq("conferences_del", name);
tabnick_remove(c->name);
- if ((tmp = (struct conference *) LIST_REMOVE2(&conferences, c, conference_free_item)))
+ if ((tmp = LIST_REMOVE2(&conferences, c, conference_free_item)))
next = tmp;
removed = 1;
}
Modified: trunk/plugins/logs/main.c
===================================================================
--- trunk/plugins/logs/main.c 2008-03-15 08:48:11 UTC (rev 3903)
+++ trunk/plugins/logs/main.c 2008-03-15 13:11:53 UTC (rev 3904)
@@ -638,7 +638,7 @@
xfree(oldtarget);
oldtarget = b->target;
- b = (struct buffer *) LIST_REMOVE2(&(buffer_lograw.data), b, NULL);
+ b = LIST_REMOVE2(&(buffer_lograw.data), b, NULL);
if (!b) {
if (f) fclose(f);
Więcej informacji o liście dyskusyjnej ekg2-commit