forked from enlightenment/efl
Change module API to use Eina_Array as we want to use mempool and module for Eina_List.
Fix at the same time a closing bug in eina_module.c. SVN revision: 36312
This commit is contained in:
parent
fcfa65f9a9
commit
7c47066009
|
@ -20,7 +20,7 @@
|
||||||
#define EINA_MODULE_H_
|
#define EINA_MODULE_H_
|
||||||
|
|
||||||
#include "eina_types.h"
|
#include "eina_types.h"
|
||||||
#include "eina_list.h"
|
#include "eina_array.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup Module_Group Module
|
* @defgroup Module_Group Module
|
||||||
|
@ -46,10 +46,10 @@ EAPI Eina_Bool eina_module_unload(Eina_Module *m);
|
||||||
EAPI void *eina_module_symbol_get(Eina_Module *module, const char *symbol);
|
EAPI void *eina_module_symbol_get(Eina_Module *module, const char *symbol);
|
||||||
EAPI const char * eina_module_file_get(Eina_Module *m);
|
EAPI const char * eina_module_file_get(Eina_Module *m);
|
||||||
|
|
||||||
EAPI Eina_List * eina_module_list_get(const char *path, unsigned int recursive, Eina_Module_Cb cb, void *data);
|
EAPI Eina_Array * eina_module_list_get(const char *path, unsigned int recursive, Eina_Module_Cb cb, void *data);
|
||||||
EAPI void eina_module_list_load(Eina_List *list);
|
EAPI void eina_module_list_load(Eina_Array *list);
|
||||||
EAPI void eina_module_list_unload(Eina_List *list);
|
EAPI void eina_module_list_unload(Eina_Array *list);
|
||||||
EAPI void eina_module_list_delete(Eina_List *list);
|
EAPI void eina_module_list_delete(Eina_Array *list);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "eina_mempool.h"
|
#include "eina_mempool.h"
|
||||||
#include "eina_hash.h"
|
#include "eina_hash.h"
|
||||||
|
@ -31,7 +32,7 @@
|
||||||
* Local *
|
* Local *
|
||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
static Eina_Hash *_backends;
|
static Eina_Hash *_backends;
|
||||||
static Eina_List *_modules;
|
static Eina_Array *_modules;
|
||||||
static int _init_count = 0;
|
static int _init_count = 0;
|
||||||
|
|
||||||
static Eina_Mempool *
|
static Eina_Mempool *
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include "eina_module.h"
|
#include "eina_module.h"
|
||||||
#include "eina_file.h"
|
#include "eina_file.h"
|
||||||
#include "eina_private.h"
|
#include "eina_private.h"
|
||||||
#include "eina_inlist.h"
|
|
||||||
|
|
||||||
/*============================================================================*
|
/*============================================================================*
|
||||||
* Local *
|
* Local *
|
||||||
|
@ -50,7 +49,6 @@
|
||||||
|
|
||||||
struct _Eina_Module
|
struct _Eina_Module
|
||||||
{
|
{
|
||||||
EINA_INLIST;
|
|
||||||
char *file;
|
char *file;
|
||||||
void *handle;
|
void *handle;
|
||||||
int ref;
|
int ref;
|
||||||
|
@ -60,7 +58,7 @@ typedef struct _Dir_List_Get_Cb_Data
|
||||||
{
|
{
|
||||||
Eina_Module_Cb cb;
|
Eina_Module_Cb cb;
|
||||||
void *data;
|
void *data;
|
||||||
Eina_List *list;
|
Eina_Array *array;
|
||||||
} Dir_List_Get_Cb_Data;
|
} Dir_List_Get_Cb_Data;
|
||||||
|
|
||||||
typedef struct _Dir_List_Cb_Data
|
typedef struct _Dir_List_Cb_Data
|
||||||
|
@ -80,7 +78,7 @@ static Eina_Bool _dir_list_get_cb(Eina_Module *m, void *data)
|
||||||
}
|
}
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
cb_data->list = eina_list_append(cb_data->list, m);
|
eina_array_push(cb_data->array, m);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -164,7 +162,7 @@ EAPI Eina_Bool eina_module_load(Eina_Module *m)
|
||||||
goto ok;
|
goto ok;
|
||||||
if ((*initcall)() == EINA_TRUE)
|
if ((*initcall)() == EINA_TRUE)
|
||||||
goto ok;
|
goto ok;
|
||||||
|
|
||||||
dlclose(dl_handle);
|
dlclose(dl_handle);
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
ok:
|
ok:
|
||||||
|
@ -189,6 +187,7 @@ EAPI Eina_Bool eina_module_unload(Eina_Module *m)
|
||||||
if ((shut) && (*shut))
|
if ((shut) && (*shut))
|
||||||
(*shut)();
|
(*shut)();
|
||||||
dlclose(m->handle);
|
dlclose(m->handle);
|
||||||
|
m->handle = NULL;
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
|
@ -208,7 +207,7 @@ EAPI Eina_Module * eina_module_new(const char *file)
|
||||||
m->file = strdup(file);
|
m->file = strdup(file);
|
||||||
m->ref = 0;
|
m->ref = 0;
|
||||||
m->handle = NULL;
|
m->handle = NULL;
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -237,7 +236,7 @@ EAPI void * eina_module_symbol_get(Eina_Module *m, const char *symbol)
|
||||||
if ((!m) || (!m->handle))
|
if ((!m) || (!m->handle))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return dlsym(m->handle, symbol);
|
return dlsym(m->handle, symbol);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* To be documented
|
* To be documented
|
||||||
|
@ -246,7 +245,7 @@ EAPI void * eina_module_symbol_get(Eina_Module *m, const char *symbol)
|
||||||
EAPI const char * eina_module_file_get(Eina_Module *m)
|
EAPI const char * eina_module_file_get(Eina_Module *m)
|
||||||
{
|
{
|
||||||
if (!m) return NULL;
|
if (!m) return NULL;
|
||||||
|
|
||||||
return m->file;
|
return m->file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,72 +258,62 @@ EAPI const char * eina_module_file_get(Eina_Module *m)
|
||||||
* it won't be added to the list, if it is one, it will.
|
* it won't be added to the list, if it is one, it will.
|
||||||
* @param data Data passed to the callback function
|
* @param data Data passed to the callback function
|
||||||
*/
|
*/
|
||||||
EAPI Eina_List * eina_module_list_get(const char *path, unsigned int recursive, Eina_Module_Cb cb, void *data)
|
EAPI Eina_Array * eina_module_list_get(const char *path, unsigned int recursive, Eina_Module_Cb cb, void *data)
|
||||||
{
|
{
|
||||||
Dir_List_Get_Cb_Data list_get_cb_data;
|
Dir_List_Get_Cb_Data list_get_cb_data;
|
||||||
Dir_List_Cb_Data list_cb_data;
|
Dir_List_Cb_Data list_cb_data;
|
||||||
|
|
||||||
if (!path)
|
if (!path)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
list_get_cb_data.list = NULL;
|
list_get_cb_data.array = eina_array_new(4);
|
||||||
list_get_cb_data.cb = cb;
|
list_get_cb_data.cb = cb;
|
||||||
list_get_cb_data.data = data;
|
list_get_cb_data.data = data;
|
||||||
|
|
||||||
list_cb_data.cb = &_dir_list_get_cb;
|
list_cb_data.cb = &_dir_list_get_cb;
|
||||||
list_cb_data.data = &list_get_cb_data;
|
list_cb_data.data = &list_get_cb_data;
|
||||||
|
|
||||||
eina_file_dir_list(path, recursive, &_dir_list_cb, &list_cb_data);
|
eina_file_dir_list(path, recursive, &_dir_list_cb, &list_cb_data);
|
||||||
|
|
||||||
return list_get_cb_data.list;
|
return list_get_cb_data.array;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Load every module on the list of modules
|
* Load every module on the list of modules
|
||||||
* @param list The list of modules
|
* @param list The list of modules
|
||||||
*/
|
*/
|
||||||
EAPI void eina_module_list_load(Eina_List *list)
|
EAPI void eina_module_list_load(Eina_Array *array)
|
||||||
{
|
{
|
||||||
Eina_List *l;
|
Eina_Array_Iterator iterator;
|
||||||
|
Eina_Module *m;
|
||||||
for (l = list; l; l = eina_list_next(l))
|
unsigned int i;
|
||||||
{
|
|
||||||
Eina_Module *m;
|
EINA_ARRAY_ITER_NEXT(array, i, m, iterator)
|
||||||
|
|
||||||
m = eina_list_data_get(l);
|
|
||||||
eina_module_load(m);
|
eina_module_load(m);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* To be documented
|
* To be documented
|
||||||
* FIXME: To be fixed
|
* FIXME: To be fixed
|
||||||
*/
|
*/
|
||||||
EAPI void eina_module_list_unload(Eina_List *list)
|
EAPI void eina_module_list_unload(Eina_Array *array)
|
||||||
{
|
{
|
||||||
Eina_List *l;
|
Eina_Array_Iterator iterator;
|
||||||
|
Eina_Module *m;
|
||||||
for (l = list; l; l = eina_list_next(l))
|
unsigned int i;
|
||||||
{
|
|
||||||
Eina_Module *m;
|
EINA_ARRAY_ITER_NEXT(array, i, m, iterator)
|
||||||
|
|
||||||
m = eina_list_data_get(l);
|
|
||||||
eina_module_unload(m);
|
eina_module_unload(m);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Helper function that iterates over the list of modules and calls
|
* Helper function that iterates over the list of modules and calls
|
||||||
* eina_module_delete on each
|
* eina_module_delete on each
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
EAPI void eina_module_list_delete(Eina_List *list)
|
EAPI void eina_module_list_delete(Eina_Array *array)
|
||||||
{
|
{
|
||||||
Eina_List *l;
|
Eina_Array_Iterator iterator;
|
||||||
|
Eina_Module *m;
|
||||||
for (l = list; l; l = eina_list_next(l))
|
unsigned int i;
|
||||||
{
|
|
||||||
Eina_Module *m;
|
EINA_ARRAY_ITER_NEXT(array, i, m, iterator)
|
||||||
|
|
||||||
m = eina_list_data_get(l);
|
|
||||||
eina_module_delete(m);
|
eina_module_delete(m);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ static const Eina_Benchmark_Case etc[] = {
|
||||||
/* FIXME this is a copy from eina_test_mempool
|
/* FIXME this is a copy from eina_test_mempool
|
||||||
* we should remove the duplication
|
* we should remove the duplication
|
||||||
*/
|
*/
|
||||||
static Eina_List *_modules;
|
static Eina_Array *_modules;
|
||||||
static void _mempool_init(void)
|
static void _mempool_init(void)
|
||||||
{
|
{
|
||||||
eina_mempool_init();
|
eina_mempool_init();
|
||||||
|
|
|
@ -72,7 +72,7 @@ eina_build_suite(void)
|
||||||
/* FIXME this is a copy from eina_test_mempool
|
/* FIXME this is a copy from eina_test_mempool
|
||||||
* we should remove the duplication
|
* we should remove the duplication
|
||||||
*/
|
*/
|
||||||
static Eina_List *_modules;
|
static Eina_Array *_modules;
|
||||||
static void _mempool_init(void)
|
static void _mempool_init(void)
|
||||||
{
|
{
|
||||||
eina_mempool_init();
|
eina_mempool_init();
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/* EINA - EFL data type library
|
/* EINA - EFL data type library
|
||||||
* Copyright (C) 2008 Cedric Bail
|
* Copyright (C) 2008 Cedric Bail
|
||||||
*
|
*
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "eina_suite.h"
|
#include "eina_suite.h"
|
||||||
#include "eina_mempool.h"
|
#include "eina_mempool.h"
|
||||||
|
|
||||||
static Eina_List *_modules;
|
static Eina_Array *_modules;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_mempool_init(void)
|
_mempool_init(void)
|
||||||
|
|
|
@ -46,25 +46,25 @@ static Eina_Bool list_cb(Eina_Module *m, void *data)
|
||||||
{
|
{
|
||||||
int *sym;
|
int *sym;
|
||||||
const char *file;
|
const char *file;
|
||||||
|
|
||||||
/* the reference count */
|
/* the reference count */
|
||||||
eina_module_load(m);
|
eina_module_load(m);
|
||||||
/* get */
|
/* get */
|
||||||
sym = eina_module_symbol_get(m, "dummy_symbol");
|
sym = eina_module_symbol_get(m, "dummy_symbol");
|
||||||
fail_if(!sym);
|
fail_if(!sym);
|
||||||
fail_if(*sym != 0xbad);
|
fail_if(*sym != 0xbad);
|
||||||
file = eina_module_file_get(m);
|
file = eina_module_file_get(m);
|
||||||
fail_if(!file);
|
fail_if(!file);
|
||||||
eina_module_unload(m);
|
eina_module_unload(m);
|
||||||
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
START_TEST(eina_module_load_unload)
|
START_TEST(eina_module_load_unload)
|
||||||
{
|
{
|
||||||
Eina_List *_modules;
|
Eina_Array *_modules;
|
||||||
|
|
||||||
eina_module_init();
|
eina_module_init();
|
||||||
_modules = eina_module_list_get(PACKAGE_BUILD_DIR"/src/tests/", 1, &list_cb, NULL);
|
_modules = eina_module_list_get(PACKAGE_BUILD_DIR"/src/tests/", 1, &list_cb, NULL);
|
||||||
fail_if(!_modules);
|
fail_if(!_modules);
|
||||||
|
|
Loading…
Reference in New Issue