eina: Fix EINA_INLIST_FOREACH_SAFE macro
authorlucas <lucas>
Tue, 4 Sep 2012 22:20:25 +0000 (22:20 +0000)
committerlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 4 Sep 2012 22:20:25 +0000 (22:20 +0000)
commita95f377dd01937c06871c88df7039ff1ab776896
treeabb93d9568f2a4c18ab8f5b300c3f8192ed9e7ba
parent05b162dc248ffc539765e795935e03b749432564
eina: Fix EINA_INLIST_FOREACH_SAFE macro

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 <Eina.h>

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 <zehortigoza@profusion.mobi>
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@76150 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33
src/include/eina_inlist.h