* @{
*/
-/* TODO change the prototype to use an Eina_Inlist */
typedef struct _Eina_Inlist Eina_Inlist;
-
struct _Eina_Inlist
{
Eina_Inlist *next;
Eina_Inlist *last;
};
-EAPI void * eina_inlist_append(void *in_list, void *in_item);
-EAPI void * eina_inlist_prepend(void *in_list, void *in_item);
-EAPI void * eina_inlist_append_relative(void *in_list, void *in_item, void *in_relative);
-EAPI void * eina_inlist_prepend_relative(void *in_list, void *in_item, void *in_relative);
-EAPI void * eina_inlist_remove(void *in_list, void *in_item);
-EAPI void * eina_inlist_find(void *in_list, void *in_item);
+#define EINA_INLIST Eina_Inlist __in_list
+#define EINA_INLIST_GET(Inlist) &(Inlist->__in_list)
+
+EAPI Eina_Inlist * eina_inlist_append(Eina_Inlist *in_list, Eina_Inlist *in_item);
+EAPI Eina_Inlist * eina_inlist_prepend(Eina_Inlist *in_list, Eina_Inlist *in_item);
+EAPI Eina_Inlist * eina_inlist_append_relative(Eina_Inlist *in_list, Eina_Inlist *in_item, Eina_Inlist *in_relative);
+EAPI Eina_Inlist * eina_inlist_prepend_relative(Eina_Inlist *in_list, Eina_Inlist *in_item, Eina_Inlist *in_relative);
+EAPI Eina_Inlist * eina_inlist_remove(Eina_Inlist *in_list, Eina_Inlist *in_item);
+EAPI Eina_Inlist * eina_inlist_find(Eina_Inlist *in_list, Eina_Inlist *in_item);
-EAPI Eina_Iterator *eina_inlist_iterator_new(const void *in_list);
-EAPI Eina_Accessor *eina_inlist_accessor_new(const void *in_list);
+EAPI Eina_Iterator *eina_inlist_iterator_new(const Eina_Inlist *in_list);
+EAPI Eina_Accessor *eina_inlist_accessor_new(const Eina_Inlist *in_list);
-#define EINA_INLIST_ITER_NEXT(list, l) for (l = (void*)(Eina_Inlist *)list; l; l = (void*)((Eina_Inlist *)l)->next)
-#define EINA_INLIST_ITER_LAST(list, l) for (l = (void*)((Eina_Inlist *)list)->last; l; l = (void*)((Eina_Inlist *)l)->prev)
+#define EINA_INLIST_ITER_NEXT(list, l) for (l = (void*)list; l; l = (void*)(l->__in_list.next))
+#define EINA_INLIST_ITER_LAST(list, l) for (l = (void*)(list->last); l; l = (void*)(l->__in_list.prev))
/** @} */
typedef struct _Eina_Run Eina_Run;
struct _Eina_Run
{
- Eina_Inlist __list;
+ EINA_INLIST;
Eina_Benchmark_Specimens cb;
const char *name;
run->end = count_end;
run->step = count_step;
- bench->runs = eina_inlist_append(bench->runs, run);
+ bench->runs = eina_inlist_append(bench->runs, EINA_INLIST_GET(run));
}
EAPI Eina_Array *
struct _Eina_Counter
{
- Eina_Inlist __list;
+ EINA_INLIST;
Eina_Inlist *clocks;
const char *name;
struct _Eina_Clock
{
- Eina_Inlist __list;
+ EINA_INLIST;
Eina_Nano_Time start;
Eina_Nano_Time end;
return;
}
- counter->clocks = eina_inlist_prepend(counter->clocks, clk);
+ counter->clocks = eina_inlist_prepend(counter->clocks, EINA_INLIST_GET(clk));
clk->valid = EINA_FALSE;
clk->start = tp;
* To be documented
* FIXME: To be fixed
*/
-EAPI void * eina_inlist_append(void *in_list, void *in_item) {
- Eina_Inlist *l, *new_l;
- Eina_Inlist *list;
-
- list = in_list;
- new_l = in_item;
- new_l->next = NULL;
- if (!list) {
- new_l->prev = NULL;
- new_l->last = new_l;
- return new_l;
- }
- if (list->last)
- l = list->last;
- else
- for (l = list; (l) && (l->next); l = l->next)
- ;
- l->next = new_l;
- new_l->prev = l;
- list->last = new_l;
- return list;
+EAPI Eina_Inlist *
+eina_inlist_append(Eina_Inlist *list, Eina_Inlist *new_l)
+{
+ Eina_Inlist *l;
+
+ new_l->next = NULL;
+ if (!list) {
+ new_l->prev = NULL;
+ new_l->last = new_l;
+ return new_l;
+ }
+ if (list->last)
+ l = list->last;
+ else
+ for (l = list; (l) && (l->next); l = l->next)
+ ;
+ l->next = new_l;
+ new_l->prev = l;
+ list->last = new_l;
+ return list;
}
/**
* To be documented
* FIXME: To be fixed
*/
-EAPI void * eina_inlist_prepend(void *in_list, void *in_item) {
- Eina_Inlist *new_l;
- Eina_Inlist *list;
-
- list = in_list;
- new_l = in_item;
- new_l->prev = NULL;
- if (!list) {
- new_l->next = NULL;
- new_l->last = new_l;
- return new_l;
- }
- new_l->next = list;
- list->prev = new_l;
- new_l->last = list->last;
- list->last = NULL;
- return new_l;
+EAPI Eina_Inlist *
+eina_inlist_prepend(Eina_Inlist *list, Eina_Inlist *new_l)
+{
+ new_l->prev = NULL;
+ if (!list) {
+ new_l->next = NULL;
+ new_l->last = new_l;
+ return new_l;
+ }
+ new_l->next = list;
+ list->prev = new_l;
+ new_l->last = list->last;
+ list->last = NULL;
+ return new_l;
}
/**
* To be documented
* FIXME: To be fixed
*/
-EAPI void * eina_inlist_append_relative(void *in_list, void *in_item,
- void *in_relative) {
- Eina_Inlist *list, *relative, *new_l;
-
- list = in_list;
- new_l = in_item;
- relative = in_relative;
- if (relative) {
- if (relative->next) {
- new_l->next = relative->next;
- relative->next->prev = new_l;
- } else
- new_l->next = NULL;
- relative->next = new_l;
- new_l->prev = relative;
- if (!new_l->next)
- list->last = new_l;
- return list;
- }
- return eina_inlist_append(list, new_l);
+EAPI Eina_Inlist *
+eina_inlist_append_relative(Eina_Inlist *list,
+ Eina_Inlist *new_l,
+ Eina_Inlist *relative)
+{
+ if (relative) {
+ if (relative->next) {
+ new_l->next = relative->next;
+ relative->next->prev = new_l;
+ } else
+ new_l->next = NULL;
+ relative->next = new_l;
+ new_l->prev = relative;
+ if (!new_l->next)
+ list->last = new_l;
+ return list;
+ }
+ return eina_inlist_append(list, new_l);
}
/**
* To be documented
* FIXME: To be fixed
*/
-EAPI void * eina_inlist_prepend_relative(void *in_list, void *in_item,
- void *in_relative) {
- Eina_Inlist *list, *relative, *new_l;
-
- list = in_list;
- new_l = in_item;
- relative = in_relative;
- if (relative) {
- new_l->prev = relative->prev;
- new_l->next = relative;
- relative->prev = new_l;
- if (new_l->prev) {
- new_l->prev->next = new_l;
- /* new_l->next could not be NULL, as it was set to 'relative' */
- assert(new_l->next);
- return list;
- } else {
- /* new_l->next could not be NULL, as it was set to 'relative' */
- assert(new_l->next);
-
- new_l->last = list->last;
- list->last = NULL;
- return new_l;
- }
- }
- return eina_inlist_prepend(list, new_l);
+EAPI Eina_Inlist *
+eina_inlist_prepend_relative(Eina_Inlist *list,
+ Eina_Inlist *new_l,
+ Eina_Inlist *relative)
+{
+ if (relative) {
+ new_l->prev = relative->prev;
+ new_l->next = relative;
+ relative->prev = new_l;
+ if (new_l->prev) {
+ new_l->prev->next = new_l;
+ /* new_l->next could not be NULL, as it was set to 'relative' */
+ assert(new_l->next);
+ return list;
+ } else {
+ /* new_l->next could not be NULL, as it was set to 'relative' */
+ assert(new_l->next);
+
+ new_l->last = list->last;
+ list->last = NULL;
+ return new_l;
+ }
+ }
+ return eina_inlist_prepend(list, new_l);
}
/**
* To be documented
* FIXME: To be fixed
*/
-EAPI void * eina_inlist_remove(void *in_list, void *in_item) {
- Eina_Inlist *return_l;
- Eina_Inlist *list, *item;
-
- /* checkme */
- if (!in_list)
- return in_list;
-
- list = in_list;
- item = in_item;
- if (!item)
- return list;
- if (item->next)
- item->next->prev = item->prev;
- if (item->prev) {
- item->prev->next = item->next;
- return_l = list;
- } else {
- return_l = item->next;
- if (return_l)
- return_l->last = list->last;
- }
- if (item == list->last)
- list->last = item->prev;
- item->next = NULL;
- item->prev = NULL;
- return return_l;
+EAPI Eina_Inlist *
+eina_inlist_remove(Eina_Inlist *list, Eina_Inlist *item)
+{
+ Eina_Inlist *return_l;
+
+ /* checkme */
+ if (!list) return list;
+ if (!item) return list;
+
+ if (item->next)
+ item->next->prev = item->prev;
+
+ if (item->prev) {
+ item->prev->next = item->next;
+ return_l = list;
+ } else {
+ return_l = item->next;
+ if (return_l)
+ return_l->last = list->last;
+ }
+ if (item == list->last)
+ list->last = item->prev;
+ item->next = NULL;
+ item->prev = NULL;
+ return return_l;
}
/**
* To be documented
* FIXME: To be fixed
*/
-EAPI void * eina_inlist_find(void *in_list, void *in_item) {
- Eina_Inlist *l;
- Eina_Inlist *list, *item;
-
- list = in_list;
- item = in_item;
- for (l = list; l; l = l->next) {
- if (l == item)
- return item;
- }
- return NULL;
+EAPI Eina_Inlist *
+eina_inlist_find(Eina_Inlist *list, Eina_Inlist *item)
+{
+ Eina_Inlist *l;
+
+ for (l = list; l; l = l->next) {
+ if (l == item)
+ return item;
+ }
+ return NULL;
}
-EAPI Eina_Iterator *eina_inlist_iterator_new(const void *in_list) {
- Eina_Iterator_Inlist *it;
+EAPI Eina_Iterator *
+eina_inlist_iterator_new(const Eina_Inlist *list)
+{
+ Eina_Iterator_Inlist *it;
- if (!in_list) return NULL;
+ if (!list) return NULL;
- eina_error_set(0);
- it = calloc(1, sizeof (Eina_Iterator_Inlist));
- if (!it) {
- eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
- return NULL;
- }
+ eina_error_set(0);
+ it = calloc(1, sizeof (Eina_Iterator_Inlist));
+ if (!it) {
+ eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
+ return NULL;
+ }
- it->head = in_list;
- it->current = in_list;
+ it->head = list;
+ it->current = list;
- it->iterator.next = FUNC_ITERATOR_NEXT(eina_inlist_iterator_next);
- it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(eina_inlist_iterator_get_container);
- it->iterator.free = FUNC_ITERATOR_FREE(eina_inlist_iterator_free);
+ it->iterator.next = FUNC_ITERATOR_NEXT(eina_inlist_iterator_next);
+ it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(eina_inlist_iterator_get_container);
+ it->iterator.free = FUNC_ITERATOR_FREE(eina_inlist_iterator_free);
- return &it->iterator;
+ return &it->iterator;
}
-EAPI Eina_Accessor *eina_inlist_accessor_new(const void *in_list) {
- Eina_Accessor_Inlist *it;
+EAPI Eina_Accessor *
+eina_inlist_accessor_new(const Eina_Inlist *list)
+{
+ Eina_Accessor_Inlist *it;
- if (!in_list) return NULL;
+ if (!list) return NULL;
- eina_error_set(0);
- it = calloc(1, sizeof (Eina_Accessor_Inlist));
- if (!it) {
- eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
- return NULL;
- }
+ eina_error_set(0);
+ it = calloc(1, sizeof (Eina_Accessor_Inlist));
+ if (!it) {
+ eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
+ return NULL;
+ }
- it->head = in_list;
- it->current = in_list;
- it->index = 0;
+ it->head = list;
+ it->current = list;
+ it->index = 0;
- it->accessor.get_at = FUNC_ACCESSOR_GET_AT(eina_inlist_accessor_get_at);
- it->accessor.get_container = FUNC_ACCESSOR_GET_CONTAINER(eina_inlist_accessor_get_container);
- it->accessor.free = FUNC_ACCESSOR_FREE(eina_inlist_accessor_free);
+ it->accessor.get_at = FUNC_ACCESSOR_GET_AT(eina_inlist_accessor_get_at);
+ it->accessor.get_container = FUNC_ACCESSOR_GET_CONTAINER(eina_inlist_accessor_get_container);
+ it->accessor.free = FUNC_ACCESSOR_FREE(eina_inlist_accessor_free);
- return &it->accessor;
+ return &it->accessor;
}
struct _Eina_Module
{
- Eina_Inlist __list;
+ EINA_INLIST;
const char * path;
const char * name;
struct _Eina_Directory
{
- Eina_Inlist __list;
+ EINA_INLIST;
const char * path;
const char * extention;
struct _Eina_Static
{
- Eina_Inlist __list;
+ EINA_INLIST;
Eina_Module_Export static_desc;
};
struct _Eina_Root_Directory
{
- Eina_Inlist __list;
+ EINA_INLIST;
const char * path;
};
void *handle;
handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
- fprintf(stderr, "b [%s] %p\n", path, handle);
if (!handle) return NULL;
module = calloc(1, sizeof (Eina_Module) + length_path + strlen(name) + 1);
{
if (data->cb(module, data->data) == EINA_TRUE)
{
- data->modules->loaded_module = eina_inlist_prepend(data->modules->loaded_module, module);
+ data->modules->loaded_module = eina_inlist_prepend(data->modules->loaded_module, EINA_INLIST_GET(module));
data->list = eina_list_append(data->list, module);
return ;
root->path = (char*)(root + 1);
memcpy((char*) root->path, root_path, length);
- root_directory = eina_inlist_prepend(root_directory, root);
+ root_directory = eina_inlist_prepend(root_directory, EINA_INLIST_GET(root));
}
EAPI Eina_Module_Group *
memcpy((char*) dir->path, path, length);
if (recursive)
- modules->recursive_directory = eina_inlist_prepend(modules->recursive_directory, dir);
+ modules->recursive_directory = eina_inlist_prepend(modules->recursive_directory, EINA_INLIST_GET(dir));
else
- modules->root_directory = eina_inlist_prepend(modules->root_directory, dir);
+ modules->root_directory = eina_inlist_prepend(modules->root_directory, EINA_INLIST_GET(dir));
}
EAPI void
}
strcat((char*) dir->extention, MODULE_EXTENSION);
- modules->lookup_directory = eina_inlist_prepend(modules->lookup_directory, dir);
+ modules->lookup_directory = eina_inlist_prepend(modules->lookup_directory, EINA_INLIST_GET(dir));
}
EAPI void
library->static_desc = *static_module;
- modules->static_libraries = eina_inlist_prepend(modules->static_libraries, library);
+ modules->static_libraries = eina_inlist_prepend(modules->static_libraries, EINA_INLIST_GET(library));
}
EAPI Eina_Module *
module->references = 1;
module->is_static_library = EINA_TRUE;
- modules->loaded_module = eina_inlist_prepend(modules->loaded_module, module);
+ modules->loaded_module = eina_inlist_prepend(modules->loaded_module, EINA_INLIST_GET(module));
return module;
}
name);
if (!module) continue ;
- modules->loaded_module = eina_inlist_prepend(modules->loaded_module, module);
+ modules->loaded_module = eina_inlist_prepend(modules->loaded_module, EINA_INLIST_GET(module));
return module;
}
continue ;
}
- modules->loaded_module = eina_inlist_prepend(modules->loaded_module, module);
+ modules->loaded_module = eina_inlist_prepend(modules->loaded_module, EINA_INLIST_GET(module));
return module;
}
if (module->references != 0) return ;
- module->group->loaded_module = eina_inlist_remove(module->group->loaded_module, module);
+ module->group->loaded_module = eina_inlist_remove(module->group->loaded_module, EINA_INLIST_GET(module));
if (module->handle) dlclose(module->handle);
free(module);
if (cb(module, data) == EINA_TRUE)
{
- modules->loaded_module = eina_inlist_prepend(modules->loaded_module, module);
+ modules->loaded_module = eina_inlist_prepend(modules->loaded_module, EINA_INLIST_GET(module));
list = eina_list_append(list, module);
}
else
if (cb(module, data) == EINA_TRUE)
{
- modules->loaded_module = eina_inlist_prepend(modules->loaded_module, module);
+ modules->loaded_module = eina_inlist_prepend(modules->loaded_module, EINA_INLIST_GET(module));
list = eina_list_append(list, module);
}
else
#include "eina_inlist.h"
#include "eina_error.h"
#include "eina_module.h"
+#include "eina_mempool.h"
#include "eina_private.h"
typedef struct _Chained_Pool Chained_Pool;
struct _Chained_Pool
{
- Eina_Inlist _list_data;
+ EINA_INLIST;
void *base;
int usage;
};
{
Chained_Mempool *pool = data;
Chained_Pool *p = NULL;
- Eina_Inlist *item;
void *mem;
// look 4 pool from 2nd bucket on
- EINA_INLIST_ITER_NEXT(pool->first, item)
+ EINA_INLIST_ITER_NEXT(pool->first, p)
{
- p = (Chained_Pool*) item;
-
// base is not NULL - has a free slot
if (p->base)
{
- pool->first = eina_inlist_remove(pool->first, item);
+ pool->first = eina_inlist_remove(pool->first, EINA_INLIST_GET(p));
break;
}
}
{
p = _eina_chained_mp_pool_new(pool);
if (!p) return NULL;
- pool->first = eina_inlist_prepend(pool->first, p);
+ pool->first = eina_inlist_prepend(pool->first, EINA_INLIST_GET(p));
}
// this points to the next free block - so take it
mem = p->base;
// move to end - it just filled up
if (!p->base)
{
- pool->first = eina_inlist_remove(pool->first, p);
- pool->first = eina_inlist_append(pool->first, p);
+ pool->first = eina_inlist_remove(pool->first, EINA_INLIST_GET(p));
+ pool->first = eina_inlist_append(pool->first, EINA_INLIST_GET(p));
}
p->usage++;
pool->usage++;
{
Chained_Mempool *pool = data;
Chained_Pool *p;
- Eina_Inlist *item;
void *pmem;
int item_alloc, psize;
item_alloc = ((pool->item_size + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *);
psize = item_alloc * pool->pool_size;
// look 4 pool
- EINA_INLIST_ITER_NEXT(pool->first, item)
+ EINA_INLIST_ITER_NEXT(pool->first, p)
{
- p = (Chained_Pool*) item;
-
// pool mem base
pmem = (void *)(((unsigned char *)p) + sizeof(Chained_Pool));
// is it in pool mem?
p->base = ptr;
p->usage--;
pool->usage--;
- pool->first = eina_inlist_remove(pool->first, p);
+ pool->first = eina_inlist_remove(pool->first, EINA_INLIST_GET(p));
if (p->usage == 0)
// free bucket
_eina_chained_mp_pool_free(p);
else
// move to front
- pool->first = eina_inlist_prepend(pool->first, p);
+ pool->first = eina_inlist_prepend(pool->first, EINA_INLIST_GET(p));
break;
}
}
typedef struct _Eina_Test_Inlist Eina_Test_Inlist;
struct _Eina_Test_Inlist
{
- Eina_Inlist list;
+ EINA_INLIST;
int i;
};
START_TEST(eina_inlist_simple)
{
- Eina_Test_Inlist *lst = NULL;
+ Eina_Inlist *lst = NULL;
Eina_Test_Inlist *tmp;
Eina_Test_Inlist *prev;
int i = 0;
tmp = _eina_test_inlist_build(42);
- lst = eina_inlist_append(lst, tmp);
+ lst = eina_inlist_append(lst, EINA_INLIST_GET(tmp));
fail_if(!lst);
- lst = eina_inlist_remove(lst, tmp);
- lst = eina_inlist_prepend(lst, tmp);
+ lst = eina_inlist_remove(lst, EINA_INLIST_GET(tmp));
+ lst = eina_inlist_prepend(lst, EINA_INLIST_GET(tmp));
tmp = _eina_test_inlist_build(1664);
- lst = eina_inlist_append_relative(lst, tmp, lst);
+ lst = eina_inlist_append_relative(lst, EINA_INLIST_GET(tmp), lst);
fail_if(!lst);
- fail_if(lst->i != 42);
+ fail_if(((Eina_Test_Inlist*)lst)->i != 42);
prev = tmp;
tmp = _eina_test_inlist_build(3227);
- lst = eina_inlist_prepend_relative(lst, tmp, prev);
+ lst = eina_inlist_prepend_relative(lst, EINA_INLIST_GET(tmp), EINA_INLIST_GET(prev));
fail_if(!lst);
- fail_if(lst->i != 42);
+ fail_if(((Eina_Test_Inlist*)lst)->i != 42);
- lst = eina_inlist_remove(lst, tmp);
+ lst = eina_inlist_remove(lst, EINA_INLIST_GET(tmp));
- lst = eina_inlist_append_relative(lst, tmp, lst);
- lst = eina_inlist_remove(lst, tmp);
+ lst = eina_inlist_append_relative(lst, EINA_INLIST_GET(tmp), lst);
+ lst = eina_inlist_remove(lst, EINA_INLIST_GET(tmp));
- lst = eina_inlist_prepend_relative(lst, tmp, lst);
+ lst = eina_inlist_prepend_relative(lst, EINA_INLIST_GET(tmp), lst);
tmp = _eina_test_inlist_build(27);
- lst = eina_inlist_prepend_relative(lst, tmp, NULL);
+ lst = eina_inlist_prepend_relative(lst, EINA_INLIST_GET(tmp), NULL);
tmp = _eina_test_inlist_build(81);
- lst = eina_inlist_append_relative(lst, tmp, NULL);
+ lst = eina_inlist_append_relative(lst, EINA_INLIST_GET(tmp), NULL);
EINA_INLIST_ITER_NEXT(lst, tmp)
{
++i;
}
- eina_inlist_remove(NULL, tmp);
+ eina_inlist_remove(NULL, EINA_INLIST_GET(tmp));
lst = eina_inlist_remove(lst, NULL);
- tmp = eina_inlist_find(lst, prev);
- eina_inlist_remove(lst, tmp);
- tmp = eina_inlist_find(lst, tmp);
+ tmp = (Eina_Test_Inlist*) eina_inlist_find(lst, EINA_INLIST_GET(prev));
+ eina_inlist_remove(lst, EINA_INLIST_GET(tmp));
+ tmp = (Eina_Test_Inlist*) eina_inlist_find(lst, EINA_INLIST_GET(tmp));
fail_if(tmp != NULL);
while (lst)