From 45a791dfa194d2dc8db77e60fa9a6579ca28bf73 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 4 Sep 2012 22:20:25 +0000 Subject: [PATCH] eina: Fix EINA_INLIST_FOREACH_SAFE macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EINA_INLIST_FOREACH_SAFE is very broken and it only works by luck, depending on the __inlist field being the first one in the struct. Until now. This commit makes the following snippet to work: #include typedef struct _data { char *name; EINA_INLIST; } data; int main() { Eina_Inlist *inlist = NULL, *inlist_safe; data *reg, *d; reg = malloc(sizeof(data)); inlist = eina_inlist_append(inlist, EINA_INLIST_GET(reg)); EINA_INLIST_FOREACH_SAFE(inlist, inlist_safe, d) { printf("%p\n", d); inlist = eina_inlist_remove(inlist, EINA_INLIST_GET(d)); free(d); } return 0; } Patch-by: José Roberto de Souza SVN revision: 76150 --- legacy/eina/src/include/eina_inlist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/eina/src/include/eina_inlist.h b/legacy/eina/src/include/eina_inlist.h index e4de689176..c1c94df77f 100644 --- a/legacy/eina/src/include/eina_inlist.h +++ b/legacy/eina/src/include/eina_inlist.h @@ -803,7 +803,7 @@ EAPI Eina_Inlist *eina_inlist_sort(Eina_Inlist *head, Eina_Compare_Cb func); #define EINA_INLIST_FOREACH_SAFE(list, list2, l) \ for (l = (list ? _EINA_INLIST_CONTAINER(l, list) : NULL), list2 = l ? ((EINA_INLIST_GET(l) ? EINA_INLIST_GET(l)->next : NULL)) : NULL; \ l; \ - l = _EINA_INLIST_CONTAINER(l, list2), list2 = list2 ? list2->next : NULL) + l = list2 ? _EINA_INLIST_CONTAINER(l, list2) : NULL, list2 = list2 ? list2->next : NULL) /** * @def EINA_INLIST_REVERSE_FOREACH * @param list The list to be reversed.