Add more error information during eina module load.

SVN revision: 36955
This commit is contained in:
Cedric BAIL 2008-10-22 08:56:19 +00:00
parent e4e3b0d5a2
commit 4bb02bdf37
2 changed files with 22 additions and 2 deletions

View File

@ -21,6 +21,7 @@
#include "eina_types.h" #include "eina_types.h"
#include "eina_array.h" #include "eina_array.h"
#include "eina_error.h"
/** /**
* @defgroup Module_Group Module * @defgroup Module_Group Module
@ -36,6 +37,9 @@ typedef void (*Eina_Module_Shutdown)(void);
#define EINA_MODULE_INIT(f) Eina_Module_Init __eina_module_init = &f; #define EINA_MODULE_INIT(f) Eina_Module_Init __eina_module_init = &f;
#define EINA_MODULE_SHUTDOWN(f) Eina_Module_Shutdown __eina_module_shutdown = &f; #define EINA_MODULE_SHUTDOWN(f) Eina_Module_Shutdown __eina_module_shutdown = &f;
extern EAPI Eina_Error EINA_ERROR_WRONG_MODULE;
extern EAPI Eina_Error EINA_ERROR_MODULE_INIT_FAILED;
EAPI int eina_module_init(void); EAPI int eina_module_init(void);
EAPI int eina_module_shutdown(void); EAPI int eina_module_shutdown(void);

View File

@ -26,6 +26,7 @@
#include <string.h> #include <string.h>
#include <dlfcn.h> #include <dlfcn.h>
#include "eina_error.h"
#include "eina_module.h" #include "eina_module.h"
#include "eina_file.h" #include "eina_file.h"
#include "eina_private.h" #include "eina_private.h"
@ -47,6 +48,9 @@
#define EINA_MODULE_SYMBOL_INIT "__eina_module_init" #define EINA_MODULE_SYMBOL_INIT "__eina_module_init"
#define EINA_MODULE_SYMBOL_SHUTDOWN "__eina_module_shutdown" #define EINA_MODULE_SYMBOL_SHUTDOWN "__eina_module_shutdown"
EAPI Eina_Error EINA_ERROR_WRONG_MODULE = 0;
EAPI Eina_Error EINA_ERROR_MODULE_INIT_FAILED = 0;
struct _Eina_Module struct _Eina_Module
{ {
char *file; char *file;
@ -121,6 +125,11 @@ eina_module_init(void)
if (_eina_module_count != 1) if (_eina_module_count != 1)
goto end_init; goto end_init;
eina_error_init();
EINA_ERROR_WRONG_MODULE = eina_error_msg_register("Wrong file format or no file module found");
EINA_ERROR_MODULE_INIT_FAILED = eina_error_msg_register("Module initialisation function failed");
end_init: end_init:
return _eina_module_count; return _eina_module_count;
} }
@ -134,11 +143,12 @@ eina_module_shutdown(void)
_eina_module_count--; _eina_module_count--;
if (_eina_module_count != 0) if (_eina_module_count != 0)
goto end_shutdown; goto end_shutdown;
eina_error_shutdown();
/* TODO should we store every module when "new" is called and /* TODO should we store every module when "new" is called and
* delete the list of modules here * delete the list of modules here
*/ */
end_shutdown: end_shutdown:
return _eina_module_count; return _eina_module_count;
@ -154,9 +164,13 @@ EAPI Eina_Bool eina_module_load(Eina_Module *m)
if (m->handle) goto loaded; if (m->handle) goto loaded;
eina_error_set(EINA_ERROR_WRONG_MODULE);
dl_handle = dlopen(m->file, RTLD_NOW); dl_handle = dlopen(m->file, RTLD_NOW);
if (!dl_handle) return EINA_FALSE; if (!dl_handle) return EINA_FALSE;
eina_error_set(EINA_ERROR_MODULE_INIT_FAILED);
initcall = dlsym(dl_handle, EINA_MODULE_SYMBOL_INIT); initcall = dlsym(dl_handle, EINA_MODULE_SYMBOL_INIT);
if ((!initcall) || (!(*initcall))) if ((!initcall) || (!(*initcall)))
goto ok; goto ok;
@ -169,6 +183,8 @@ ok:
m->handle = dl_handle; m->handle = dl_handle;
loaded: loaded:
m->ref++; m->ref++;
eina_error_set(0);
return EINA_TRUE; return EINA_TRUE;
} }
/** /**