Hello again,

On 09/10/2012 03:59 PM, Daniel Willmann wrote:
> On 09/10/2012 03:09 PM, Enlightenment SVN wrote:
>> Log:
>> eina/module: Rephrase warnings message on module init.
>>   
>>   Thsi will also fail if the symbol is there but the init function just fails
>>   to deliver EINA_TRUE. After to much digging and wondering why dlsymb and
>>   dlopen don't behave Daniel was able to point out to me that this warning 
>> also
>>   gets shown if init fails.
> 
> I found more. Wrote a patch and attached it. Then I had an idea and
> checked the documentation. From the documentation it sounds like
> providing an init function with EINA_MODULE_INIT() is optional. The
> current code (the check after dlsym()) seems to agree.
> 
> However, the WRN("") suggests that the code will and should fail if the
> module initialization symbol is not found.

after some discussion on IRC we agreed that the init function should be
mandatory. I don't see much use for a module without it and Cedric
assured me that all modules are using init function. Please see the
attached patch complete with news, changelog, authors and documentation.
Backported to 1.7 as well


Regards,
Daniel Willmann

From 5e2dfb3397e74a6f4c6d0e3b18378702be194b70 Mon Sep 17 00:00:00 2001
From: Daniel Willmann <[email protected]>
Date: Mon, 10 Sep 2012 15:25:19 +0100
Subject: [PATCH] eina_module: Fix eina_module_load() error handling

dlsym() will return NULL if EINA_MODULE_INIT() is not used inside the
module. We don't need to check both initcall and *initcall. Err out
correctly and clarify the log message.

Update the documentation to clarify the behaviour.

Signed-off-by: Daniel Willmann <[email protected]>
---
 branches/eina-1.7/AUTHORS                   |    1 +
 branches/eina-1.7/ChangeLog                 |    5 +++++
 branches/eina-1.7/NEWS                      |   12 ++++++++++++
 branches/eina-1.7/src/include/eina_module.h |   10 ++++++----
 branches/eina-1.7/src/lib/eina_module.c     |   13 +++++++++----
 trunk/eina/AUTHORS                          |    1 +
 trunk/eina/ChangeLog                        |    4 ++++
 trunk/eina/NEWS                             |    8 ++++++++
 trunk/eina/src/include/eina_module.h        |   10 ++++++----
 trunk/eina/src/lib/eina_module.c            |   14 ++++++++++----
 10 files changed, 62 insertions(+), 16 deletions(-)

diff --git a/branches/eina-1.7/AUTHORS b/branches/eina-1.7/AUTHORS
index ef0d3cc..5790825 100644
--- a/branches/eina-1.7/AUTHORS
+++ b/branches/eina-1.7/AUTHORS
@@ -25,3 +25,4 @@ Jonas M. Gastal <[email protected]>
 Raphael Kubo da Costa <[email protected]>
 J챕r척me Pinot <[email protected]>
 Mike Blumenkrantz <[email protected]>
+Daniel Willmann <[email protected]>
diff --git a/branches/eina-1.7/ChangeLog b/branches/eina-1.7/ChangeLog
index 39662ab..32f40ee 100644
--- a/branches/eina-1.7/ChangeLog
+++ b/branches/eina-1.7/ChangeLog
@@ -332,3 +332,8 @@
 2012-08-30  Carsten Haitzler (The Rasterman)
 
         1.7.0 release
+
+2012-09-10	Daniel Willmann
+
+        * Fix eina_module_load() error handling when EINA_MODULE_INIT() is not
+				used in the module
diff --git a/branches/eina-1.7/NEWS b/branches/eina-1.7/NEWS
index 2c364ce..baf453c 100644
--- a/branches/eina-1.7/NEWS
+++ b/branches/eina-1.7/NEWS
@@ -1,3 +1,15 @@
+Eina 1.7.1
+Changes since Eina 1.7.0:
+-------------------------
+
+Additions:
+
+Fixes:
+    * Fix eina_module_load() error handling when EINA_MODULE_INIT() is not used
+      in the module
+
+Removal:
+
 Eina 1.7.0
 
 Changes since Eina 1.2.0:
diff --git a/branches/eina-1.7/src/include/eina_module.h b/branches/eina-1.7/src/include/eina_module.h
index 24a491d..d9e8264 100644
--- a/branches/eina-1.7/src/include/eina_module.h
+++ b/branches/eina-1.7/src/include/eina_module.h
@@ -48,11 +48,12 @@
  * dlclose(). This makes simple to have different users for the same
  * module.
  *
- * The loaded shared objects may have two visible functions that will
- * be called and might provide initialization and shutdown
+ * The loaded shared objects need to have two visible functions that will
+ * be called to provide initialization and shutdown
  * procedures. The symbols are @c __eina_module_init and
  * @c __eina_module_shutdown and will be defined by the macros
- * EINA_MODULE_INIT() and EINA_MODULE_SHUTDOWN().
+ * EINA_MODULE_INIT() and EINA_MODULE_SHUTDOWN(). If they are not defined
+ * eina_module_load() will fail.
  *
  * There are some helpers to automatically create modules based on
  * directory listing. See eina_module_arch_list_get(),
@@ -160,7 +161,8 @@ EAPI Eina_Bool
  * be loaded, the error #EINA_ERROR_WRONG_MODULE is set and
  * and #EINA_FALSE is returned. If it is a internal Eina module and the
  * module can not be initialized, the error #EINA_ERROR_MODULE_INIT_FAILED
- * is set and #EINA_FALSE is returned. If the module has already been loaded,
+ * is set and #EINA_FALSE is returned. This either means that no init function
+ * was found or that it failed. If the module has already been loaded,
  * it's reference counter is increased by one and #EINA_TRUE is returned.
  * If @p module is @c NULL, the function returns immediately #EINA_FALSE.
  *
diff --git a/branches/eina-1.7/src/lib/eina_module.c b/branches/eina-1.7/src/lib/eina_module.c
index 9e20fbd..42128b6 100644
--- a/branches/eina-1.7/src/lib/eina_module.c
+++ b/branches/eina-1.7/src/lib/eina_module.c
@@ -342,14 +342,19 @@ EAPI Eina_Bool eina_module_load(Eina_Module *m)
      }
 
    initcall = dlsym(dl_handle, EINA_MODULE_SYMBOL_INIT);
-   if ((!initcall) || (!(*initcall)))
-      goto ok;
+   if (!initcall)
+     {
+        WRN("could not find eina's entry symbol %s inside module %s",
+            EINA_MODULE_SYMBOL_INIT, m->file);
+        eina_error_set(EINA_ERROR_MODULE_INIT_FAILED);
+        dlclose(dl_handle);
+        return EINA_FALSE;
+     }
 
    if ((*initcall)() == EINA_TRUE)
       goto ok;
 
-   WRN("could not find eina's entry symbol %s inside module %s",
-       EINA_MODULE_SYMBOL_INIT, m->file);
+   WRN("Initialization of module %s failed", m->file);
    eina_error_set(EINA_ERROR_MODULE_INIT_FAILED);
    dlclose(dl_handle);
    return EINA_FALSE;
diff --git a/trunk/eina/AUTHORS b/trunk/eina/AUTHORS
index ef0d3cc..5790825 100644
--- a/trunk/eina/AUTHORS
+++ b/trunk/eina/AUTHORS
@@ -25,3 +25,4 @@ Jonas M. Gastal <[email protected]>
 Raphael Kubo da Costa <[email protected]>
 J챕r척me Pinot <[email protected]>
 Mike Blumenkrantz <[email protected]>
+Daniel Willmann <[email protected]>
diff --git a/trunk/eina/ChangeLog b/trunk/eina/ChangeLog
index 403c9d7..b93e7f1 100644
--- a/trunk/eina/ChangeLog
+++ b/trunk/eina/ChangeLog
@@ -341,3 +341,7 @@
 2012-09-11  Cedric Bail
 
 	* Speedup Eina Rbtree Iterator by recycling memory instead of massively calling malloc/free.
+
+2012-09-11	Daniel Willmann
+        * Fix eina_module_load() error handling when EINA_MODULE_INIT() is not
+				used in the module
diff --git a/trunk/eina/NEWS b/trunk/eina/NEWS
index c6b08c9..7d1ab42 100644
--- a/trunk/eina/NEWS
+++ b/trunk/eina/NEWS
@@ -6,6 +6,14 @@ Changes since Eina 1.7.0:
 Improvements:
     * Speedup Eina Rbtree Iterator by recycling memory instead of massively calling malloc/free.
 
+Additions:
+
+Fixes:
+    * Fix eina_module_load() error handling when EINA_MODULE_INIT() is not used
+      in the module
+
+Removal:
+
 Eina 1.7.0
 
 Changes since Eina 1.2.0:
diff --git a/trunk/eina/src/include/eina_module.h b/trunk/eina/src/include/eina_module.h
index 24a491d..d9e8264 100644
--- a/trunk/eina/src/include/eina_module.h
+++ b/trunk/eina/src/include/eina_module.h
@@ -48,11 +48,12 @@
  * dlclose(). This makes simple to have different users for the same
  * module.
  *
- * The loaded shared objects may have two visible functions that will
- * be called and might provide initialization and shutdown
+ * The loaded shared objects need to have two visible functions that will
+ * be called to provide initialization and shutdown
  * procedures. The symbols are @c __eina_module_init and
  * @c __eina_module_shutdown and will be defined by the macros
- * EINA_MODULE_INIT() and EINA_MODULE_SHUTDOWN().
+ * EINA_MODULE_INIT() and EINA_MODULE_SHUTDOWN(). If they are not defined
+ * eina_module_load() will fail.
  *
  * There are some helpers to automatically create modules based on
  * directory listing. See eina_module_arch_list_get(),
@@ -160,7 +161,8 @@ EAPI Eina_Bool
  * be loaded, the error #EINA_ERROR_WRONG_MODULE is set and
  * and #EINA_FALSE is returned. If it is a internal Eina module and the
  * module can not be initialized, the error #EINA_ERROR_MODULE_INIT_FAILED
- * is set and #EINA_FALSE is returned. If the module has already been loaded,
+ * is set and #EINA_FALSE is returned. This either means that no init function
+ * was found or that it failed. If the module has already been loaded,
  * it's reference counter is increased by one and #EINA_TRUE is returned.
  * If @p module is @c NULL, the function returns immediately #EINA_FALSE.
  *
diff --git a/trunk/eina/src/lib/eina_module.c b/trunk/eina/src/lib/eina_module.c
index 736df0d..7b04964 100644
--- a/trunk/eina/src/lib/eina_module.c
+++ b/trunk/eina/src/lib/eina_module.c
@@ -342,14 +342,20 @@ EAPI Eina_Bool eina_module_load(Eina_Module *m)
      }
 
    initcall = dlsym(dl_handle, EINA_MODULE_SYMBOL_INIT);
-   if ((!initcall) || (!(*initcall)))
-      goto ok;
+   if (!initcall)
+     {
+        WRN("could not find eina's entry symbol %s inside module %s",
+            EINA_MODULE_SYMBOL_INIT, m->file);
+        eina_error_set(EINA_ERROR_MODULE_INIT_FAILED);
+        dlclose(dl_handle);
+        return EINA_FALSE;
+     }
 
    if ((*initcall)() == EINA_TRUE)
       goto ok;
 
-   WRN("could not find eina's entry symbol %s inside module %s, or the init function failed",
-       EINA_MODULE_SYMBOL_INIT, m->file);
+   WRN("Initialization of module %s failed",
+       m->file);
    eina_error_set(EINA_ERROR_MODULE_INIT_FAILED);
    dlclose(dl_handle);
    return EINA_FALSE;
-- 
1.7.9.5


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to