diff --git a/legacy/eina/src/include/eina_inline_mempool.x b/legacy/eina/src/include/eina_inline_mempool.x index b13a39bb4d..c2eba8b384 100644 --- a/legacy/eina/src/include/eina_inline_mempool.x +++ b/legacy/eina/src/include/eina_inline_mempool.x @@ -23,6 +23,7 @@ typedef struct _Eina_Mempool_Backend Eina_Mempool_Backend; struct _Eina_Mempool_Backend { + const char *name; void *(*init)(const char *context, const char *options, va_list args); void (*free)(void *data, void *element); void *(*alloc)(void *data, unsigned int size); @@ -34,7 +35,6 @@ struct _Eina_Mempool_Backend struct _Eina_Mempool { - Eina_Module *module; Eina_Mempool_Backend backend; void *backend_data; }; @@ -57,4 +57,8 @@ eina_mempool_free(Eina_Mempool *mp, void *element) mp->backend.free(mp->backend_data, element); } +/* FIXME Do we actually need to export this functions?? */ +Eina_Bool eina_mempool_register(Eina_Mempool_Backend *be); +void eina_mempool_unregister(Eina_Mempool_Backend *be); + #endif diff --git a/legacy/eina/src/include/eina_mempool.h b/legacy/eina/src/include/eina_mempool.h index 801fbcbe99..505b4efe71 100644 --- a/legacy/eina/src/include/eina_mempool.h +++ b/legacy/eina/src/include/eina_mempool.h @@ -33,7 +33,6 @@ EAPI extern Eina_Error EINA_ERROR_NOT_MEMPOOL_MODULE; EAPI int eina_mempool_init(void); EAPI int eina_mempool_shutdown(void); -EAPI Eina_Module_Group * eina_mempool_module_group_get(void); EAPI Eina_Mempool * eina_mempool_new(const char *module, const char *context, const char *options, ...); EAPI void eina_mempool_delete(Eina_Mempool *mp); diff --git a/legacy/eina/src/include/eina_module.h b/legacy/eina/src/include/eina_module.h index 7a8e658770..e0184f7290 100644 --- a/legacy/eina/src/include/eina_module.h +++ b/legacy/eina/src/include/eina_module.h @@ -26,51 +26,30 @@ * @defgroup Module_Group Module * @{ */ + typedef struct _Eina_Module Eina_Module; -typedef struct _Eina_Module_Group Eina_Module_Group; -typedef struct _Eina_Module_Export Eina_Module_Export; typedef Eina_Bool (*Eina_Module_Cb)(Eina_Module *m, void *data); -struct _Eina_Module_Export -{ - const char *name; - const char *version; - const char *type; - const void *object; -}; +typedef Eina_Bool (*Eina_Module_Init)(void); +typedef void (*Eina_Module_Shutdown)(void); + +#define EINA_MODULE_INIT(f) Eina_Module_Init __eina_module_init = &f; +#define EINA_MODULE_SHUTDOWN(f) Eina_Module_Shutdown __eina_module_shutdown = &f; EAPI int eina_module_init(void); EAPI int eina_module_shutdown(void); -EAPI void eina_module_root_add(const char *root_path); - -EAPI Eina_Module_Group *eina_module_group_new(void); -EAPI void eina_module_group_delete(Eina_Module_Group *group); - -EAPI void eina_module_path_register(Eina_Module_Group *modules, const char *path, Eina_Bool recursive); -EAPI void eina_module_app_register(Eina_Module_Group *modules, const char *app, const char *types, const char *version); -EAPI void eina_module_register(Eina_Module_Group *modules, const Eina_Module_Export *static_module); - -EAPI Eina_List *eina_module_list_new(Eina_Module_Group *modules, Eina_Module_Cb cb, void *data); -EAPI void eina_module_list_delete(Eina_List *modules); - -EAPI Eina_Module *eina_module_new(Eina_Module_Group *modules, const char *name); -EAPI void eina_module_delete(Eina_Module *modules); +EAPI Eina_Module * eina_module_new(const char *file); +EAPI Eina_Bool eina_module_delete(Eina_Module *m); EAPI Eina_Bool eina_module_load(Eina_Module *module); -EAPI void eina_module_unload(Eina_Module *module); - -EAPI void eina_module_list_load(const Eina_List *list); -EAPI void eina_module_list_unload(const Eina_List *list); - -EAPI const char *eina_module_path_get(Eina_Module *module); +EAPI Eina_Bool eina_module_unload(Eina_Module *m); EAPI void *eina_module_symbol_get(Eina_Module *module, const char *symbol); +EAPI const char * eina_module_file_get(Eina_Module *m); -EAPI void *eina_module_export_object_get(Eina_Module *module); -EAPI const char *eina_module_export_type_get(Eina_Module *module); -EAPI const char *eina_module_export_version_get(Eina_Module *module); -EAPI const char *eina_module_export_name_get(Eina_Module *module); - -#define EINA_MODULE(Name, Type, Version, Object) EAPI Eina_Module_Export Eina_Export = { Name, Version, Type, Object }; +EAPI Eina_List * 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_unload(Eina_List *list); +EAPI void eina_module_list_delete(Eina_List *list); /** @} */ diff --git a/legacy/eina/src/lib/eina_mempool.c b/legacy/eina/src/lib/eina_mempool.c index c9f50bbe33..bf5e967636 100644 --- a/legacy/eina/src/lib/eina_mempool.c +++ b/legacy/eina/src/lib/eina_mempool.c @@ -23,48 +23,78 @@ #include #include "eina_mempool.h" -#include "eina_list.h" +#include "eina_hash.h" #include "eina_module.h" #include "eina_private.h" /*============================================================================* * Local * *============================================================================*/ - -static Eina_Module_Group *_group; +static Eina_Hash *_backends; +static Eina_List *_modules; static int _init_count = 0; static Eina_Mempool * -_new_from_buffer(const char *module, const char *context, const char *options, va_list args) +_new_from_buffer(const char *name, const char *context, const char *options, va_list args) { + Eina_Mempool_Backend *be; Eina_Mempool *mp; - Eina_Module *m; + Eina_Error err = EINA_ERROR_NOT_MEMPOOL_MODULE; eina_error_set(0); - m = eina_module_new(_group, module); - if (!m) return NULL; - if (eina_module_load(m) == EINA_FALSE) goto on_error; + be = eina_hash_find(_backends, name); + if (!be) + goto on_error; err = EINA_ERROR_OUT_OF_MEMORY; mp = malloc(sizeof(Eina_Mempool)); if (!mp) goto on_error; - mp->module = m; - mp->backend = *(Eina_Mempool_Backend *)eina_module_export_object_get(m); + + /* FIXME why backend is not a pointer? */ + mp->backend = *be; mp->backend_data = mp->backend.init(context, options, args); return mp; on_error: eina_error_set(err); - if (m) eina_module_delete(m); return NULL; } +/* Built-in backend's prototypes */ +#ifdef EINA_STATIC_BUILD_CHAINED_POOL +Eina_Bool chained_init(void); +void chained_shutdown(void); +#endif + +#ifdef EINA_STATIC_BUILD_PASS_THROUGH +Eina_Bool pass_through_init(void); +void pass_through_shutdown(void); +#endif + +#ifdef EINA_STATIC_BUILD_EMEMOA_UNKNOWN +Eina_Bool ememoa_unknown_init(void); +void ememoa_unknown_shutdown(void); +#endif + +#ifdef EINA_STATIC_BUILD_EMEMOA_FIXED +Eina_Bool ememoa_fixed_init(void); +void ememoa_fixed_shutdown(void); +#endif + /*============================================================================* * Global * *============================================================================*/ +Eina_Bool eina_mempool_register(Eina_Mempool_Backend *be) +{ + return eina_hash_add(_backends, be->name, be); +} +void eina_mempool_unregister(Eina_Mempool_Backend *be) +{ + eina_hash_del(_backends, be->name, be); +} /*============================================================================* * API * *============================================================================*/ @@ -79,16 +109,28 @@ eina_mempool_init(void) { if (!_init_count) { + eina_hash_init(); eina_module_init(); - _group = eina_module_group_new(); - if (!_group) return 0; - - eina_module_app_register(_group, "eina", "mp", NULL); - EINA_ERROR_NOT_MEMPOOL_MODULE = eina_error_msg_register("Not a memory pool module."); + _backends = eina_hash_string_superfast_new(); + /* dynamic backends */ + _modules = eina_module_list_get(PACKAGE_LIB_DIR "/eina/mp/", 0, NULL, NULL); + eina_module_list_load(_modules); + /* builtin backends */ +#ifdef EINA_STATIC_BUILD_CHAINED_POOL + chained_init(); +#endif +#ifdef EINA_STATIC_BUILD_PASS_THROUGH + pass_through_init(); +#endif +#ifdef EINA_STATIC_BUILD_EMEMOA_UNKNOWN + ememoa_unknown_init(); +#endif +#ifdef EINA_STATIC_BUILD_EMEMOA_FIXED + ememoa_fixed_init(); +#endif } - /* get all the modules */ return ++_init_count; } @@ -101,19 +143,27 @@ eina_mempool_shutdown(void) _init_count--; if (_init_count != 0) return _init_count; - /* remove the list of modules */ - eina_module_group_delete(_group); + /* builtin backends */ +#ifdef EINA_STATIC_BUILD_CHAINED_POOL + chained_shutdown(); +#endif +#ifdef EINA_STATIC_BUILD_PASS_THROUGH + pass_through_shutdown(); +#endif +#ifdef EINA_STATIC_BUILD_EMEMOA_UNKNOWN + ememoa_unknown_shutdown(); +#endif +#ifdef EINA_STATIC_BUILD_EMEMOA_FIXED + ememoa_fixed_shutdown(); +#endif + /* dynamic backends */ + eina_module_list_unload(_modules); eina_module_shutdown(); - + /* TODO delete the _modules list */ + eina_hash_shutdown(); return 0; } -EAPI Eina_Module_Group * -eina_mempool_module_group_get(void) -{ - return _group; -} - /** * */ @@ -140,7 +190,6 @@ EAPI void eina_mempool_delete(Eina_Mempool *mp) if (!mp) return ; mp->backend.shutdown(mp->backend_data); - eina_module_unload(mp->module); free(mp); } diff --git a/legacy/eina/src/lib/eina_module.c b/legacy/eina/src/lib/eina_module.c index 33da3ed042..9b60ee7b1c 100644 --- a/legacy/eina/src/lib/eina_module.c +++ b/legacy/eina/src/lib/eina_module.c @@ -44,853 +44,287 @@ #else # define MODULE_EXTENSION ".so" #endif /* ! _WIN32 */ -#define MODULE_SUBDIR "/modules/" -#define MODULE_BASE_EXTENTION "module" -typedef struct _Eina_Root_Directory Eina_Root_Directory; -typedef struct _Eina_Directory Eina_Directory; -typedef struct _Eina_Dir_List Eina_Dir_List; -typedef struct _Eina_Static Eina_Static; -typedef struct _Eina_App Eina_App; +#define EINA_MODULE_SYMBOL_INIT "__eina_module_init" +#define EINA_MODULE_SYMBOL_SHUTDOWN "__eina_module_shutdown" struct _Eina_Module { - EINA_INLIST; - - const char * path; - const char * name; - const Eina_App * app; - Eina_Module_Group * group; - - void * handle; - Eina_Module_Export * export; - - int references; - int load_references; - - Eina_Bool is_static_library; + EINA_INLIST; + char *file; + void *handle; + int ref; }; -struct _Eina_Directory +typedef struct _Dir_List_Get_Cb_Data { - EINA_INLIST; + Eina_Module_Cb cb; + void *data; + Eina_List *list; +} Dir_List_Get_Cb_Data; - const char * path; - const char * extention; - - Eina_App * app; -}; - -struct _Eina_App +typedef struct _Dir_List_Cb_Data { - const char * name; - const char * type; - const char * version; -}; + Eina_Module_Cb cb; + void *data; +} Dir_List_Cb_Data; -struct _Eina_Static +static Eina_Bool _dir_list_get_cb(Eina_Module *m, void *data) { - EINA_INLIST; - Eina_Module_Export static_desc; -}; + Dir_List_Get_Cb_Data *cb_data = data; + Eina_Bool ret = EINA_TRUE; -struct _Eina_Module_Group + if (cb_data->cb) + { + ret = cb_data->cb(m, cb_data->data); + } + if (ret) + { + cb_data->list = eina_list_append(cb_data->list, m); + } + return ret; +} + +static void _dir_list_cb(const char *name, const char *path, void *data) { - Eina_Inlist * lookup_directory; - Eina_Inlist * root_directory; - Eina_Inlist * recursive_directory; - Eina_Inlist * static_libraries; + Dir_List_Cb_Data *cb_data = data; + unsigned int length; - Eina_Inlist * loaded_module; -}; + length = strlen(name); + if (length < strlen(MODULE_EXTENSION) + 1) /* x.so */ + return; + if (!strcmp(name + length - strlen(MODULE_EXTENSION), + MODULE_EXTENSION)) + { + char file[PATH_MAX]; + Eina_Module *m; -struct _Eina_Root_Directory -{ - EINA_INLIST; - - const char * path; -}; - -struct _Eina_Dir_List -{ - Eina_Module_Group *modules; - Eina_Module *module; - Eina_List *list; - void *data; - - Eina_Module_Cb cb; -}; - -static Eina_Inlist * root_directory; -static char *self_name = NULL; + snprintf(file, PATH_MAX, "%s/%s", path, name); + m = eina_module_new(file); + if (!m) + return; + /* call the user provided cb on this module */ + cb_data->cb(m, cb_data->data); + } +} static int _eina_module_count = 0; - -static Eina_Module * -_eina_module_build(Eina_Module_Group *modules, Eina_App *app, - const char *path, int length_path, - const char *name) -{ - Eina_Module *module; - void *handle; - - handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); - if (!handle) return NULL; - - module = calloc(1, sizeof (Eina_Module) + length_path + strlen(name) + 1); - if (!module) return NULL; - - module->path = (char*)(module + 1); - module->name = module->path + length_path; - module->group = modules; - module->app = app; - module->handle = handle; - module->references = 1; - module->is_static_library = EINA_FALSE; - - memcpy((char*) module->path, path, length_path); - strcpy((char*) module->name, name); - - if (eina_module_load(module) == EINA_TRUE) - return module; - - free(module); - return NULL; -} - -static Eina_Module * -_eina_module_try(Eina_Module_Group *modules, - const char *path, int length_path, - const char *filename, int length_filename) -{ - Eina_Module *module; - - module = calloc(1, sizeof (Eina_Module) + length_path + length_filename + 2); - if (!module) return NULL; - - module->path = (char*)(module + 1); - module->name = NULL; - module->group = modules; - module->app = NULL; - module->references = 1; - module->is_static_library = EINA_FALSE; - - strcpy((char*) module->path, path); - strcat((char*) module->path, "/"); - strcat((char*) module->path, filename); - - module->handle = dlopen(module->path, RTLD_LAZY | RTLD_GLOBAL); - if (!module->handle) goto on_error; - - if (eina_module_load(module) == EINA_TRUE) - { - module->name = module->export->name; - return module; - } - - on_error: - free(module); - return NULL; -} - -static void -_eina_dir_module_cb(const char *name, const char *path, Eina_Dir_List *data) -{ - Eina_Module *module; - int length_name = strlen(name); - int length_path = strlen(path); - - if (strcmp(name + length_name - strlen(MODULE_EXTENSION), MODULE_EXTENSION)) - return ; - - module = _eina_module_try(data->modules, - path, length_path, - name, length_name); - if (!module) return ; - - if (data->cb) - { - if (data->cb(module, data->data) == EINA_TRUE) - { - data->modules->loaded_module = eina_inlist_prepend(data->modules->loaded_module, EINA_INLIST_GET(module)); - data->list = eina_list_append(data->list, module); - - return ; - } - } - else - { - if (strcmp(module->name, data->data) == 0) - { - /* FIXME: Compare version instead of taking the last one. */ - if (data->module) - { - eina_module_unload(module); - free(module); - } - - data->module = module; - return ; - } - } - - eina_module_unload(module); - free(module); -} - -/** - * @endcond - */ - -/*============================================================================* - * Global * - *============================================================================*/ - /*============================================================================* * API * *============================================================================*/ +/** + * To be documented + * FIXME: To be fixed + */ EAPI int eina_module_init(void) { - char *prefix; - char *path; + _eina_module_count++; - _eina_module_count++; + if (_eina_module_count != 1) + goto end_init; - if (_eina_module_count != 1) - goto end_init; - - /* Add some default path. */ - - /* 1. ~/lib/ */ - prefix = getenv("HOME"); - if (prefix) - { - #define SUBDIR_LIB "/lib" - - path = malloc(strlen(prefix) + strlen(SUBDIR_LIB) + 1); - if (path) - { - strcpy(path, prefix); - strcat(path, SUBDIR_LIB); - - eina_module_root_add(path); - - free(path); - } - } - - /* 2. $(EINA_MODULE_DIR)/ */ - prefix = getenv("EINA_MODULES_DIR"); - if (prefix) eina_module_root_add(prefix); - -#ifdef HAVE_DLADDR - { - Dl_info eina_dl; - /* 3. libeina.so/../ */ - if (dladdr(eina_module_init, &eina_dl)) - { - int length; - - self_name = strdup(eina_dl.dli_fname); - - prefix = strrchr(eina_dl.dli_fname, '/'); - - if (prefix) - { - length = strlen(prefix); - path = malloc(strlen(eina_dl.dli_fname) - length + 1); - if (path) - { - strncpy(path, eina_dl.dli_fname, strlen(eina_dl.dli_fname) - length); - path[strlen(eina_dl.dli_fname) - length] = 0; - - eina_module_root_add(path); - - free(path); - } - } - } - } -#else - self_name = malloc(strlen(PACKAGE_LIB_DIR) + strlen("/libeina") + strlen(MODULE_EXTENSION) + 1); - if (self_name) - { - strcpy(self_name, PACKAGE_LIB_DIR); - strcat(self_name, "/libeina"); - strcat(self_name, MODULE_EXTENSION); - } -#endif - - /* 4. PREFIX/ */ - prefix = PACKAGE_LIB_DIR; - if (prefix) eina_module_root_add(prefix); - - end_init: - return _eina_module_count; +end_init: + return _eina_module_count; } - +/** + * To be documented + * FIXME: To be fixed + */ EAPI int eina_module_shutdown(void) { - _eina_module_count--; + _eina_module_count--; + if (_eina_module_count != 0) + goto end_shutdown; + /* TODO should we store every module when "new" is called and + * delete the list of modules here + */ + + - if (_eina_module_count != 0) - goto end_shutdown; - - free(self_name); - self_name = NULL; - - while (root_directory) - { - Eina_Root_Directory *root; - - root = (Eina_Root_Directory*) root_directory; - - root_directory = eina_inlist_remove(root_directory, root_directory); - - free(root); - } - - end_shutdown: - return _eina_module_count; +end_shutdown: + return _eina_module_count; } - -EAPI void -eina_module_root_add(const char *root_path) +/** + * To be documented + * FIXME: To be fixed + */ +EAPI Eina_Bool eina_module_load(Eina_Module *m) { - Eina_Root_Directory *root; - unsigned int length; + void *dl_handle; + Eina_Module_Init *initcall; - if (!root_path) return ; + if (m->handle) goto loaded; - /* Lookup if the path is already registered. */ - EINA_INLIST_ITER_NEXT(root_directory, root) - if (!strcmp(root->path, root_path)) - return ; + dl_handle = dlopen(m->file, RTLD_NOW); + if (!dl_handle) return EINA_FALSE; - /* Add it. */ - length = strlen(root_path) + 1; - - root = calloc(1, sizeof (Eina_Root_Directory) + length); - if (!root) return ; - - root->path = (char*)(root + 1); - memcpy((char*) root->path, root_path, length); - - root_directory = eina_inlist_prepend(root_directory, EINA_INLIST_GET(root)); + initcall = dlsym(dl_handle, EINA_MODULE_SYMBOL_INIT); + if ((!initcall) || (!(*initcall))) + goto ok; + if ((*initcall)() == EINA_TRUE) + goto ok; + + dlclose(dl_handle); + return EINA_FALSE; +ok: + m->handle = dl_handle; +loaded: + m->ref++; + return EINA_TRUE; } - -EAPI Eina_Module_Group * -eina_module_group_new(void) +/** + * To be documented + * FIXME: To be fixed + */ +EAPI Eina_Bool eina_module_unload(Eina_Module *m) { - Eina_Module_Group *new; + Eina_Module_Shutdown *shut; + if (!m) return EINA_FALSE; - new = calloc(1, sizeof (Eina_Module_Group)); - - return new; + m->ref--; + if (!m->ref) + { + shut = dlsym(m->handle, EINA_MODULE_SYMBOL_SHUTDOWN); + if ((shut) && (*shut)) + (*shut)(); + dlclose(m->handle); + return EINA_TRUE; + } + return EINA_FALSE; } - -EAPI void -eina_module_group_delete(Eina_Module_Group *group) +/** + * To be documented + * FIXME: To be fixed + */ +EAPI Eina_Module * eina_module_new(const char *file) { - if (!group) return ; + Eina_Module *m; - while (group->lookup_directory) - { - Eina_Directory *dir = (Eina_Directory*) group->lookup_directory; + /* TODO check that the file exists */ - group->lookup_directory = eina_inlist_remove(group->lookup_directory, group->lookup_directory); - - free(dir); - } - - while (group->static_libraries) - { - Eina_Static *slib = (Eina_Static*) group->static_libraries; - - group->static_libraries = eina_inlist_remove(group->static_libraries, group->static_libraries); - - free(slib); - } - - while (group->loaded_module) - eina_module_delete((Eina_Module*) group->loaded_module); - - free(group); + m = malloc(sizeof(Eina_Module)); + /* TODO add the magic */ + m->file = strdup(file); + m->ref = 0; + m->handle = NULL; + + return m; } - -EAPI void -eina_module_path_register(Eina_Module_Group *modules, const char *path, Eina_Bool recursive) +/** + * To be documented + * FIXME: To be fixed + */ +EAPI Eina_Bool eina_module_delete(Eina_Module *m) { - Eina_Root_Directory *dir; - int length; + if (!m) return EINA_FALSE; - if (!modules || !path) return ; - - length = strlen(path) + 1; - - dir = calloc(1, sizeof (Eina_Root_Directory) + length); - if (!dir) return ; - - dir->path = (const char*) (dir + 1); - memcpy((char*) dir->path, path, length); - - if (recursive) - modules->recursive_directory = eina_inlist_prepend(modules->recursive_directory, EINA_INLIST_GET(dir)); - else - modules->root_directory = eina_inlist_prepend(modules->root_directory, EINA_INLIST_GET(dir)); + if (m->handle) + { + if (eina_module_unload(m) == EINA_FALSE) + return EINA_FALSE; + } + free(m->file); + free(m); + return EINA_TRUE; } - -EAPI void -eina_module_app_register(Eina_Module_Group *modules, const char *app, const char *type, const char *version) +/** + * To be documented + * FIXME: To be fixed + */ +EAPI void * eina_module_symbol_get(Eina_Module *m, const char *symbol) { - Eina_Directory *dir; - int app_length; - int type_length; - int version_length; - int subdir_length; - int extention_length; + if ((!m) || (!m->handle)) + return NULL; - if (!modules || !app) return ; - - app_length = strlen(app); - subdir_length = strlen(MODULE_SUBDIR); - extention_length = strlen(MODULE_ARCH) + strlen(MODULE_BASE_EXTENTION) + strlen(MODULE_EXTENSION) + 3; - - type_length = type ? strlen(type) + 1 : 0; - version_length = version ? strlen(version) + 1 : 0; - - dir = calloc(1, sizeof (Eina_Directory) - + app_length + subdir_length + type_length + 1 /* path length */ - + extention_length + version_length + 1 /* extention length */); - if (!dir) return ; - - /* Build app description. */ - dir->app = malloc(sizeof (Eina_App) + app_length + type_length + version_length + 1); - if (!dir->app) - { - free(dir); - return ; - } - dir->app->name = (char*) (dir->app + 1); - dir->app->type = dir->app->name + app_length + 1; - dir->app->version = dir->app->type + type_length; - memcpy((char*) dir->app->name, app, app_length + 1); - memcpy((char*) dir->app->type, type, type_length); - memcpy((char*) dir->app->version, version, version_length); - - /* Setup pointer. */ - dir->path = (const char*) (dir + 1); - dir->extention = dir->path + app_length + subdir_length + type_length + 1; - - /* Build path. "[app]/modules/{[type]/}" */ - strcpy((char*) dir->path, app); - strcat((char*) dir->path, MODULE_SUBDIR); - if (type) - { - strcat((char*) dir->path, type); - strcat((char*) dir->path, "/"); - } - - /* Build extention "/[MODULE_ARCH]/module{-[version]}.so" */ - strcpy((char*) dir->extention, "/"); - strcat((char*) dir->extention, MODULE_ARCH); - strcat((char*) dir->extention, "/"); - strcat((char*) dir->extention, MODULE_BASE_EXTENTION); - if (version) - { - strcat((char*) dir->extention, "-"); - strcat((char*) dir->extention, version); - } - strcat((char*) dir->extention, MODULE_EXTENSION); - - modules->lookup_directory = eina_inlist_prepend(modules->lookup_directory, EINA_INLIST_GET(dir)); + return dlsym(m->handle, symbol); } - -EAPI void -eina_module_register(Eina_Module_Group *modules, const Eina_Module_Export *static_module) +/** + * To be documented + * FIXME: To be fixed + */ +EAPI const char * eina_module_file_get(Eina_Module *m) { - Eina_Static *library; - - if (!modules || !static_module) return ; - - library = malloc(sizeof (Eina_Static)); - if (!library) return ; - - library->static_desc = *static_module; - - modules->static_libraries = eina_inlist_prepend(modules->static_libraries, EINA_INLIST_GET(library)); + if (!m) return NULL; + + return m->file; } -EAPI Eina_Module * -eina_module_new(Eina_Module_Group *modules, const char *name) +/** + * Gets a list of modules found on the directory path + * + * @param path The directory's path to search for modules + * @param recursive Iterate recursively on the path + * @param cb Callback function to call, if the return value of the callback is zero + * it won't be added to the list, if it is one, it will. + * @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) { - Eina_Root_Directory *root; - Eina_Directory *dir; - Eina_Module *module; - Eina_Static *slib; - Eina_Dir_List edl; - char path[PATH_MAX]; - int length; + Dir_List_Get_Cb_Data list_get_cb_data; + Dir_List_Cb_Data list_cb_data; + + if (!path) + return NULL; - if (!modules) return NULL; - - /* Lookup in loaded module. */ - EINA_INLIST_ITER_NEXT(modules->loaded_module, module) - if (!strcmp(module->name, name)) - { - module->references++; - - return module; - } - - /* Lookup in statically provided module. */ - EINA_INLIST_ITER_NEXT(modules->static_libraries, slib) - if (!strcmp(slib->static_desc.name, name)) - { - module = calloc(1, sizeof (Eina_Module)); - if (!module) return NULL; - - /* FIXME: Must retrieve the library path that provide slib->static_desc */ - module->path = self_name; - module->name = slib->static_desc.name; - module->export = &slib->static_desc; - module->group = modules; - module->references = 1; - module->is_static_library = EINA_TRUE; - - modules->loaded_module = eina_inlist_prepend(modules->loaded_module, EINA_INLIST_GET(module)); - - return module; - } - - /* Lookup for apps in each root_directory. */ - EINA_INLIST_ITER_NEXT(root_directory, root) - EINA_INLIST_ITER_NEXT(modules->lookup_directory, dir) - { - length = snprintf(path, PATH_MAX, "%s/%s/%s/%s", - root->path, dir->path, name, dir->extention) + 1; - if (length > PATH_MAX) return NULL; - - module = _eina_module_build(modules, dir->app, - path, length, - name); - if (!module) continue ; - - modules->loaded_module = eina_inlist_prepend(modules->loaded_module, EINA_INLIST_GET(module)); - return module; - } - - /* Lookup for apps with full path from root_dir. */ - EINA_INLIST_ITER_NEXT(modules->root_directory, root) - { - length = snprintf(path, PATH_MAX, "%s"MODULE_SUBDIR"%s/%s", - root->path, name, MODULE_BASE_EXTENTION""MODULE_EXTENSION) + 1; - if (length > PATH_MAX) return NULL; - - module = _eina_module_build(modules, NULL, - path, length, - name); - if (!module) continue ; - if (strcmp(module->export->name, name) != 0) - { - eina_module_unload(module); - free(module); - continue ; - } - - modules->loaded_module = eina_inlist_prepend(modules->loaded_module, EINA_INLIST_GET(module)); - return module; - } - - edl.list = NULL; - edl.modules = modules; - edl.module = NULL; - edl.data = (void*) name; - edl.cb = NULL; - - /* Lookup for library in a directory or recursively. */ - EINA_INLIST_ITER_NEXT(modules->recursive_directory, root) - eina_file_dir_list(root->path, EINA_TRUE, EINA_FILE_DIR_LIST_CB(_eina_dir_module_cb), &edl); - - return edl.module; + list_get_cb_data.list = NULL; + list_get_cb_data.cb = cb; + list_get_cb_data.data = data; + + list_cb_data.cb = &_dir_list_get_cb; + list_cb_data.data = &list_get_cb_data; + + eina_file_dir_list(path, recursive, &_dir_list_cb, &list_cb_data); + + return list_get_cb_data.list; } - -EAPI void -eina_module_delete(Eina_Module *module) +/** + * Load every module on the list of modules + * @param list The list of modules + */ +EAPI void eina_module_list_load(Eina_List *list) { - if (!module) return ; - - module->references--; - - if (module->references != 0) return ; - - module->group->loaded_module = eina_inlist_remove(module->group->loaded_module, EINA_INLIST_GET(module)); - - if (module->handle) dlclose(module->handle); - free(module); + Eina_List *l; + + for (l = list; l; l = eina_list_next(l)) + { + Eina_Module *m; + + m = eina_list_data(l); + eina_module_load(m); + } } - -EAPI Eina_List * -eina_module_list_new(Eina_Module_Group *modules, Eina_Module_Cb cb, void *data) +/** + * To be documented + * FIXME: To be fixed + */ +EAPI void eina_module_list_unload(Eina_List *list) { - Eina_List *list = NULL; - Eina_Root_Directory *root; - Eina_Directory *dir; - Eina_Module *module; - Eina_Static *slib; - struct dirent *rent; - DIR *look; - Eina_Dir_List edl; - char path[PATH_MAX]; - char filename[PATH_MAX]; - int path_length; - - /* Test against already loaded module. */ - EINA_INLIST_ITER_NEXT(modules->loaded_module, module) - if (cb(module, data) == EINA_TRUE) - { - module->references++; - - list = eina_list_append(list, module); - } - - /* Test against static module. */ - EINA_INLIST_ITER_NEXT(modules->static_libraries, slib) - { - module = calloc(1, sizeof (Eina_Module)); - if (!module) return NULL; - - module->path = self_name; - module->name = slib->static_desc.name; - module->export = &slib->static_desc; - module->group = modules; - module->references = 1; - module->is_static_library = EINA_TRUE; - - if (cb(module, data) == EINA_TRUE) - { - modules->loaded_module = eina_inlist_prepend(modules->loaded_module, EINA_INLIST_GET(module)); - list = eina_list_append(list, module); - } - else - free(module); - } - - /* Lookup for apps in each root_directory. */ - EINA_INLIST_ITER_NEXT(root_directory, root) - EINA_INLIST_ITER_NEXT(modules->lookup_directory, dir) - { - strcpy(path, root->path); - strcat(path, "/"); - strcat(path, dir->path); - - look = opendir(path); - if (!look) continue ; - - path_length = strlen(path); - - while ((rent = readdir(look))) - { - int length; - - length = snprintf(filename, PATH_MAX, "%s/%s/%s", - path, rent->d_name, dir->extention) + 1; - if (length > PATH_MAX) continue ; - - module = _eina_module_build(modules, dir->app, - filename, length, - rent->d_name); - if (!module) continue ; - - if (cb(module, data) == EINA_TRUE) - { - modules->loaded_module = eina_inlist_prepend(modules->loaded_module, EINA_INLIST_GET(module)); - list = eina_list_append(list, module); - } - else - { - eina_module_unload(module); - free(module); - } - } - - closedir(look); - } - - edl.list = list; - edl.modules = modules; - edl.data = data; - edl.cb = cb; - - /* Lookup for apps with full path from root_dir. */ - EINA_INLIST_ITER_NEXT(modules->root_directory, root) - eina_file_dir_list(root->path, EINA_FALSE, EINA_FILE_DIR_LIST_CB(_eina_dir_module_cb), &edl); - - /* Lookup for library in a directory or recursively. */ - EINA_INLIST_ITER_NEXT(modules->recursive_directory, root) - eina_file_dir_list(root->path, EINA_TRUE, EINA_FILE_DIR_LIST_CB(_eina_dir_module_cb), &edl); - - return edl.list; + Eina_List *l; + + for (l = list; l; l = eina_list_next(l)) + { + Eina_Module *m; + + m = eina_list_data(l); + eina_module_unload(m); + } } - -EAPI void -eina_module_list_delete(Eina_List *modules) +/** + * Helper function that iterates over the list of modules and calls + * eina_module_delete on each + * + */ +EAPI void eina_module_list_delete(Eina_List *list) { - Eina_Module *module; - - while (modules) - { - module = eina_list_data(modules); - eina_module_delete(module); - - modules = eina_list_remove_list(modules, modules); - } + Eina_List *l; + + for (l = list; l; l = eina_list_next(l)) + { + Eina_Module *m; + + m = eina_list_data(l); + eina_module_delete(m); + } } -EAPI Eina_Bool -eina_module_load(Eina_Module *module) -{ - if (!module) return EINA_FALSE; - - module->load_references++; - - if (module->load_references > 1) return EINA_TRUE; - - if (module->is_static_library == EINA_FALSE) - { - if (!module->handle) - module->handle = dlopen(module->path, RTLD_LAZY | RTLD_GLOBAL); - if (!module->handle) - return EINA_FALSE; - - module->export = dlsym(module->handle, "Eina_Export"); - } - - if (!module->export) goto on_error; - - if (!module->export->name) - goto on_error; - - if (module->app) - { - if (strcmp(module->app->name, module->export->name)) - goto on_error; - - if (module->app->type && module->export->type) - if (strcmp(module->app->type, module->export->type)) - goto on_error; - - if (module->export->version && module->app->version) - if (strcmp(module->app->version, module->export->version)) - goto on_error; - } - - return EINA_TRUE; - - on_error: - if (module->handle) - dlclose(module->handle); - module->handle = NULL; - - if (module->is_static_library == EINA_FALSE) - module->export = NULL; - - module->load_references--; - - return EINA_FALSE; -} - -EAPI void -eina_module_unload(Eina_Module *module) -{ - if (!module) return ; - - module->load_references--; - - if (module->load_references != 0) return ; - - if (module->handle) - dlclose(module->handle); - module->handle = NULL; - - if (module->is_static_library == EINA_FALSE) - module->export = NULL; -} - -EAPI void -eina_module_list_load(const Eina_List *list) -{ - while (list) - { - eina_module_load(eina_list_data(list)); - - list = eina_list_next(list); - } -} - -EAPI void -eina_module_list_unload(const Eina_List *list) -{ - while (list) - { - eina_module_unload(eina_list_data(list)); - - list = eina_list_next(list); - } -} - -EAPI const char * -eina_module_path_get(Eina_Module *module) -{ - if (!module) return NULL; - return module->path; -} - -EAPI void * -eina_module_symbol_get(Eina_Module *module, const char *symbol) -{ - if (!module) return NULL; - if (module->load_references <= 0) return NULL; - /* dlopen of NULL give a handler to the main program. */ - if (!module->handle) module->handle = dlopen(NULL, RTLD_LAZY | RTLD_NODELETE | RTLD_GLOBAL); - if (!module->handle) return NULL; - - return dlsym(module->handle, symbol); -} - -EAPI void * -eina_module_export_object_get(Eina_Module *module) -{ - if (!module) return NULL; - if (module->load_references <= 0) return NULL; - - return (void*) module->export->object; -} - -EAPI const char * -eina_module_export_type_get(Eina_Module *module) -{ - if (!module) return NULL; - if (module->load_references <= 0) return NULL; - - return module->export->type; -} - -EAPI const char * -eina_module_export_version_get(Eina_Module *module) -{ - if (!module) return NULL; - if (module->load_references <= 0) return NULL; - - return module->export->version; -} - -EAPI const char * -eina_module_export_name_get(Eina_Module *module) -{ - if (!module) return NULL; - if (module->load_references <= 0) return NULL; - - return module->export->name; -} diff --git a/legacy/eina/src/modules/mp/chained_pool/Makefile.am b/legacy/eina/src/modules/mp/chained_pool/Makefile.am index 0d5612cb92..978f5984bf 100644 --- a/legacy/eina/src/modules/mp/chained_pool/Makefile.am +++ b/legacy/eina/src/modules/mp/chained_pool/Makefile.am @@ -7,7 +7,7 @@ AM_CPPFLAGS = \ if !EINA_STATIC_BUILD_CHAINED_POOL -controllerdir = $(libdir)/eina/chained_pool/ +controllerdir = $(libdir)/eina/mp/ controller_LTLIBRARIES = eina_chained_mempool.la eina_chained_mempool_la_SOURCES = \ diff --git a/legacy/eina/src/modules/mp/chained_pool/eina_chained_mempool.c b/legacy/eina/src/modules/mp/chained_pool/eina_chained_mempool.c index 4e761c377a..d7eb69135d 100644 --- a/legacy/eina/src/modules/mp/chained_pool/eina_chained_mempool.c +++ b/legacy/eina/src/modules/mp/chained_pool/eina_chained_mempool.c @@ -205,9 +205,8 @@ eina_chained_mempool_shutdown(void *data) free(mp); } -#ifndef EINA_STATIC_BUILD_CHAINED_POOL - static Eina_Mempool_Backend mp_backend = { + .name ="chained_mempool", .init = &eina_chained_mempool_init, .shutdown = &eina_chained_mempool_shutdown, .realloc = &eina_chained_mempool_realloc, @@ -215,6 +214,19 @@ static Eina_Mempool_Backend mp_backend = { .free = &eina_chained_mempool_free }; -EINA_MODULE("chained_mempool", "mp", NULL, &mp_backend); +Eina_Bool chained_init(void) +{ + return eina_mempool_register(&mp_backend); +} + +void chained_shutdown(void) +{ + eina_mempool_unregister(&mp_backend); +} + +#ifndef EINA_STATIC_BUILD_CHAINED_POOL + +EINA_MODULE_INIT(chained_init); +EINA_MODULE_SHUTDOWN(chained_shutdown); #endif /* ! EINA_STATIC_BUILD_CHAINED_POOL */ diff --git a/legacy/eina/src/modules/mp/ememoa_fixed/Makefile.am b/legacy/eina/src/modules/mp/ememoa_fixed/Makefile.am index 41033db29f..649034b365 100644 --- a/legacy/eina/src/modules/mp/ememoa_fixed/Makefile.am +++ b/legacy/eina/src/modules/mp/ememoa_fixed/Makefile.am @@ -11,7 +11,7 @@ if EINA_ENABLE_EMEMOA if !EINA_STATIC_BUILD_EMEMOA_FIXED -controllerdir = $(libdir)/eina/chained_pool/ +controllerdir = $(libdir)/eina/mp/ controller_LTLIBRARIES = eina_ememoa_fixed.la eina_ememoa_fixed_la_SOURCES = \ diff --git a/legacy/eina/src/modules/mp/ememoa_fixed/eina_ememoa_fixed.c b/legacy/eina/src/modules/mp/ememoa_fixed/eina_ememoa_fixed.c index 77d2578e04..8b79a471b3 100644 --- a/legacy/eina/src/modules/mp/ememoa_fixed/eina_ememoa_fixed.c +++ b/legacy/eina/src/modules/mp/ememoa_fixed/eina_ememoa_fixed.c @@ -132,9 +132,8 @@ eina_ememoa_fixed_shutdown(void *data) free(efm); } -#ifndef EINA_STATIC_BUILD_EMEMOA_FIXED - static Eina_Mempool_Backend mp_backend = { + .name = "ememoa_fixed", .init = &eina_ememoa_fixed_init, .shutdown = &eina_ememoa_fixed_shutdown, .realloc = &eina_ememoa_fixed_realloc, @@ -144,6 +143,20 @@ static Eina_Mempool_Backend mp_backend = { .statistics = &eina_ememoa_fixed_statistics }; -EINA_MODULE("ememoa_fixed", "mp", NULL, &mp_backend); +Eina_Bool ememoa_fixed_init(void) +{ + return eina_mempool_register(&mp_backend); +} + +void ememoa_fixed_shutdown(void) +{ + eina_mempool_unregister(&mp_backend); +} + + +#ifndef EINA_STATIC_BUILD_EMEMOA_FIXED + +EINA_MODULE_INIT(ememoa_fixed_init); +EINA_MODULE_SHUTDOWN(ememoa_fixed_shutdown); #endif /* ! EINA_STATIC_BUILD_EMEMOA_FIXED */ diff --git a/legacy/eina/src/modules/mp/ememoa_unknown/Makefile.am b/legacy/eina/src/modules/mp/ememoa_unknown/Makefile.am index 5939b9bfe7..d20b7efd42 100644 --- a/legacy/eina/src/modules/mp/ememoa_unknown/Makefile.am +++ b/legacy/eina/src/modules/mp/ememoa_unknown/Makefile.am @@ -11,7 +11,7 @@ if EINA_ENABLE_EMEMOA if !EINA_STATIC_BUILD_EMEMOA_UNKNOWN -controllerdir = $(libdir)/eina/chained_pool/ +controllerdir = $(libdir)/eina/mp/ controller_LTLIBRARIES = eina_ememoa_unknown.la eina_ememoa_unknown_la_SOURCES = \ diff --git a/legacy/eina/src/modules/mp/ememoa_unknown/eina_ememoa_unknown.c b/legacy/eina/src/modules/mp/ememoa_unknown/eina_ememoa_unknown.c index 4d49db3154..77748466ad 100644 --- a/legacy/eina/src/modules/mp/ememoa_unknown/eina_ememoa_unknown.c +++ b/legacy/eina/src/modules/mp/ememoa_unknown/eina_ememoa_unknown.c @@ -138,9 +138,8 @@ eina_ememoa_unknown_size_shutdown(void *data) free(efm); } -#ifndef EINA_STATIC_BUILD_EMEMOA_UNKNOWN - static Eina_Mempool_Backend mp_backend = { + .name = "ememoa_unknown", .init = &eina_ememoa_unknown_size_init, .shutdown = &eina_ememoa_unknown_size_shutdown, .realloc = &eina_ememoa_unknown_size_realloc, @@ -150,6 +149,19 @@ static Eina_Mempool_Backend mp_backend = { .statistics = &eina_ememoa_unknown_size_statistics }; -EINA_MODULE("ememoa_unknown", "mp", NULL, &mp_backend); +Eina_Bool ememoa_unknown_init(void) +{ + return eina_mempool_register(&mp_backend); +} + +void ememoa_unknown_shutdown(void) +{ + eina_mempool_unregister(&mp_backend); +} + +#ifndef EINA_STATIC_BUILD_EMEMOA_UNKNOWN + +EINA_MODULE_INIT(ememoa_unknown_init); +EINA_MODULE_SHUTDOWN(ememoa_unknown_shutdown); #endif /* ! EINA_STATIC_BUILD_EMEMOA_UNKNOWN */ diff --git a/legacy/eina/src/modules/mp/pass_through/Makefile.am b/legacy/eina/src/modules/mp/pass_through/Makefile.am index 9314aa5ea3..79ec5e3a49 100644 --- a/legacy/eina/src/modules/mp/pass_through/Makefile.am +++ b/legacy/eina/src/modules/mp/pass_through/Makefile.am @@ -9,7 +9,7 @@ AM_CPPFLAGS = \ if !EINA_STATIC_BUILD_PASS_THROUGH -controllerdir = $(libdir)/eina/pass_through/ +controllerdir = $(libdir)/eina/mp/ controller_LTLIBRARIES = pass_through.la pass_through_la_SOURCES = \ diff --git a/legacy/eina/src/modules/mp/pass_through/pass_through.c b/legacy/eina/src/modules/mp/pass_through/pass_through.c index 914473610c..fe41a2b830 100644 --- a/legacy/eina/src/modules/mp/pass_through/pass_through.c +++ b/legacy/eina/src/modules/mp/pass_through/pass_through.c @@ -59,9 +59,9 @@ eina_pass_through_shutdown(__UNUSED__ void *data) { } -#ifndef EINA_STATIC_BUILD_PASS_THROUGH static Eina_Mempool_Backend mp_backend = { + .name = "pass_through", .init = &eina_pass_through_init, .shutdown = &eina_pass_through_shutdown, .realloc = &eina_pass_through_realloc, @@ -71,7 +71,20 @@ static Eina_Mempool_Backend mp_backend = { .statistics = NULL }; -EINA_MODULE("pass_through", "mp", NULL, &mp_backend); +Eina_Bool pass_through_init(void) +{ + return eina_mempool_register(&mp_backend); +} + +void pass_through_shutdown(void) +{ + eina_mempool_unregister(&mp_backend); +} + +#ifndef EINA_STATIC_BUILD_PASS_THROUGH + +EINA_MODULE_INIT(pass_through_init); +EINA_MODULE_SHUTDOWN(pass_through_shutdown); #endif /* ! EINA_STATIC_BUILD_PASS_THROUGH */ diff --git a/legacy/eina/src/tests/Makefile.am b/legacy/eina/src/tests/Makefile.am index b31c766ec8..8ac07448f1 100644 --- a/legacy/eina/src/tests/Makefile.am +++ b/legacy/eina/src/tests/Makefile.am @@ -65,6 +65,17 @@ eina_test_list.c eina_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libeina.la +module_dummydir = $(libdir)/eina/test +module_dummy_LTLIBRARIES = module_dummy.la + +module_dummy_la_SOURCES = \ +eina_test_module_dummy.c + +module_dummy_la_LIBADD = $(top_builddir)/src/lib/libeina.la @COVERAGE_LIBS@ +module_dummy_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version +module_dummy_la_LIBTOOLFLAGS = --tag=disable-static +module_dummy_la_DEPENDENCIES = $(top_builddir)/src/lib/libeina.la + endif if EINA_ENABLE_BENCH diff --git a/legacy/eina/src/tests/eina_suite.c b/legacy/eina/src/tests/eina_suite.c index 8ca16d590b..1b2020eb2b 100644 --- a/legacy/eina/src/tests/eina_suite.c +++ b/legacy/eina/src/tests/eina_suite.c @@ -69,10 +69,29 @@ eina_build_suite(void) return s; } +/* FIXME this is a copy from eina_test_mempool + * we should remove the duplication + */ +static Eina_List *_modules; +static void _mempool_init(void) +{ + eina_mempool_init(); + /* force modules to be loaded in case they are not installed */ + _modules = eina_module_list_get(PACKAGE_BUILD_DIR"/src/modules", 1, NULL, NULL); + eina_module_list_load(_modules); +} + +static void _mempool_shutdown(void) +{ + eina_module_list_delete(_modules); + /* TODO delete the list */ + eina_mempool_shutdown(); +} + int main(void) { - Eina_Module_Group *gp; + //Eina_Module_Group *gp; Suite *s; SRunner *sr; int failed_count; @@ -81,17 +100,13 @@ main(void) s = eina_build_suite(); sr = srunner_create(s); - eina_mempool_init(); - - eina_module_root_add(PACKAGE_BUILD_DIR"/src/tests"); - gp = eina_mempool_module_group_get(); - eina_module_path_register(gp, PACKAGE_BUILD_DIR"/src/modules", EINA_TRUE); + _mempool_init(); srunner_run_all(sr, CK_NORMAL); failed_count = srunner_ntests_failed(sr); srunner_free(sr); - eina_mempool_shutdown(); + _mempool_shutdown(); return (failed_count == 0) ? 0 : 255; } diff --git a/legacy/eina/src/tests/eina_test_mempool.c b/legacy/eina/src/tests/eina_test_mempool.c index 10a42f1d7f..27aa32153e 100644 --- a/legacy/eina/src/tests/eina_test_mempool.c +++ b/legacy/eina/src/tests/eina_test_mempool.c @@ -23,16 +23,33 @@ #include "eina_suite.h" #include "eina_mempool.h" +static Eina_List *_modules; + +static void _mempool_init(void) +{ + eina_mempool_init(); + /* force modules to be loaded in case they are not installed */ + _modules = eina_module_list_get(PACKAGE_BUILD_DIR"/src/modules", 1, NULL, NULL); + eina_module_list_load(_modules); +} + +static void _mempool_shutdown(void) +{ + eina_module_list_delete(_modules); + /* TODO delete the list */ + eina_mempool_shutdown(); +} + START_TEST(eina_mempool_init_shutdown) { Eina_Mempool *mp; - eina_mempool_init(); + _mempool_init(); mp = eina_mempool_new("test", "test", NULL); fail_if(mp != NULL); - eina_mempool_shutdown(); + _mempool_shutdown(); } END_TEST @@ -42,7 +59,7 @@ START_TEST(eina_mempool_chained_mempool) int *tbl[512]; int i; - eina_mempool_init(); + _mempool_init(); mp = eina_mempool_new("chained_mempool", "test", NULL, sizeof (int), 256); fail_if(!mp); @@ -64,7 +81,7 @@ START_TEST(eina_mempool_chained_mempool) eina_mempool_delete(mp); - eina_mempool_shutdown(); + _mempool_shutdown(); } END_TEST @@ -74,7 +91,7 @@ START_TEST(eina_mempool_pass_through) int *tbl[512]; int i; - eina_mempool_init(); + _mempool_init(); mp = eina_mempool_new("pass_through", "test", NULL, sizeof (int), 8, 0); fail_if(!mp); @@ -96,7 +113,7 @@ START_TEST(eina_mempool_pass_through) eina_mempool_delete(mp); - eina_mempool_shutdown(); + _mempool_shutdown(); } END_TEST @@ -107,7 +124,7 @@ START_TEST(eina_mempool_ememoa_fixed) int *tbl[512]; int i; - eina_mempool_init(); + _mempool_init(); mp = eina_mempool_new("ememoa_fixed", "test", NULL, sizeof (int), 8, 0); fail_if(!mp); @@ -132,7 +149,7 @@ START_TEST(eina_mempool_ememoa_fixed) eina_mempool_delete(mp); - eina_mempool_shutdown(); + _mempool_shutdown(); } END_TEST @@ -142,7 +159,7 @@ START_TEST(eina_mempool_ememoa_unknown) int *tbl[512]; int i; - eina_mempool_init(); + _mempool_init(); mp = eina_mempool_new("ememoa_unknown", "test", NULL, 0, 2, sizeof (int), 8, sizeof (int) * 2, 8); fail_if(!mp); @@ -168,7 +185,7 @@ START_TEST(eina_mempool_ememoa_unknown) eina_mempool_delete(mp); - eina_mempool_shutdown(); + _mempool_shutdown(); } END_TEST #endif diff --git a/legacy/eina/src/tests/eina_test_module.c b/legacy/eina/src/tests/eina_test_module.c index 24c769274d..ea979d3276 100644 --- a/legacy/eina/src/tests/eina_test_module.c +++ b/legacy/eina/src/tests/eina_test_module.c @@ -35,7 +35,6 @@ START_TEST(eina_module_init_shutdown) eina_module_shutdown(); eina_module_init(); eina_module_init(); - eina_module_root_add(PACKAGE_BUILD_DIR); eina_module_shutdown(); eina_module_shutdown(); eina_module_shutdown(); @@ -43,65 +42,36 @@ START_TEST(eina_module_init_shutdown) } END_TEST -static int i42 = 42; -static Eina_Module_Export static_test = { "simple", NULL, "test", &i42 }; -EAPI int stupid_test = 7; - -static Eina_Bool -_eina_module_test_cb(__UNUSED__ Eina_Module *m, __UNUSED__ void *data) +static Eina_Bool list_cb(Eina_Module *m, void *data) { + int *sym; + const char *file; + + /* the reference count */ + eina_module_load(m); + /* get */ + sym = eina_module_symbol_get(m, "dummy_symbol"); + fail_if(!sym); + fail_if(*sym != 0xbad); + file = eina_module_file_get(m); + fail_if(!file); + eina_module_unload(m); + return EINA_TRUE; } -START_TEST(eina_module_simple) + +START_TEST(eina_module_load_unload) { - Eina_Module_Group *gp; - Eina_Module *m; - Eina_List *list; - + Eina_List *_modules; + eina_module_init(); - - eina_module_root_add(PACKAGE_BUILD_DIR"/src/tests"); - - gp = eina_module_group_new(); - fail_if(!gp); - - eina_module_path_register(gp, PACKAGE_BUILD_DIR"/src/modules", EINA_TRUE); - eina_module_path_register(gp, PACKAGE_BUILD_DIR"/src/lib", EINA_FALSE); - eina_module_path_register(gp, PACKAGE_BUILD_DIR"/src/lib", EINA_FALSE); - - eina_module_app_register(gp, "eina", "test", NULL); - eina_module_app_register(gp, "eina", "bench", "1.0.0"); - - eina_module_register(gp, &static_test); - - m = eina_module_new(gp, "unknown"); - fail_if(m); - - m = eina_module_new(gp, "simple"); - fail_if(!m); - - fail_if(eina_module_load(m) != EINA_TRUE); - - fprintf(stderr, "path: %s\n", eina_module_path_get(m)); - fail_if(strcmp("test", eina_module_export_type_get(m))); - fail_if(eina_module_export_version_get(m) != NULL); - fail_if(strcmp("simple", eina_module_export_name_get(m))); - fail_if(eina_module_export_object_get(m) != &i42); - fail_if(eina_module_symbol_get(m, "eina_list_init") != &eina_list_init); - - eina_module_unload(m); - eina_module_delete(m); - - list = eina_module_list_new(gp, _eina_module_test_cb, NULL); - eina_module_list_load(list); - eina_module_list_unload(list); - eina_module_list_delete(list); - - m = eina_module_new(gp, "simple"); - - eina_module_group_delete(gp); - + _modules = eina_module_list_get(PACKAGE_BUILD_DIR"/src/tests/", 1, &list_cb, NULL); + fail_if(!_modules); + eina_module_list_load(_modules); + eina_module_list_unload(_modules); + eina_module_list_delete(_modules); + /* TODO delete the list */ eina_module_shutdown(); } END_TEST @@ -110,5 +80,5 @@ void eina_test_module(TCase *tc) { tcase_add_test(tc, eina_module_init_shutdown); - tcase_add_test(tc, eina_module_simple); + tcase_add_test(tc, eina_module_load_unload); } diff --git a/legacy/eina/src/tests/eina_test_module_dummy.c b/legacy/eina/src/tests/eina_test_module_dummy.c new file mode 100644 index 0000000000..9598858679 --- /dev/null +++ b/legacy/eina/src/tests/eina_test_module_dummy.c @@ -0,0 +1,17 @@ +#include "Eina.h" +#include + +Eina_Bool dummy_module_init(void) +{ + return EINA_TRUE; +} + +void dummy_module_shutdown(void) +{ + +} + +int dummy_symbol = 0xbad; + +EINA_MODULE_INIT(dummy_module_init); +EINA_MODULE_SHUTDOWN(dummy_module_shutdown);