Linux dynamic_link: add a better error report 90/14790/6
Clément DAVID [Wed, 2 Jul 2014 14:52:03 +0000 (16:52 +0200)]
Change-Id: Ife9a521a0039d361a97a56be052a774d7643a75d

scilab/modules/dynamic_link/includes/dynamiclibrary_others.h
scilab/modules/dynamic_link/includes/dynamiclibrary_windows.h
scilab/modules/dynamic_link/src/c/dynamiclibrary_others.c
scilab/modules/dynamic_link/src/c/dynamiclibrary_windows.c
scilab/modules/system_env/src/cpp/configvariable.cpp
scilab/modules/types/src/cpp/function.cpp

index 8a4759f..62f95d8 100644 (file)
@@ -40,7 +40,7 @@ BOOL FreeDynLibrary(DynLibHandle hInstance);
 * @param string that specifies the function
 * @return a pointer
 */
-DynLibFuncPtr GetDynLibFuncPtr(DynLibHandle hInstance, char *funcName);
+DynLibFuncPtr GetDynLibFuncPtr(DynLibHandle hInstance, const char *funcName);
 
 /**
 * return last dynamic linking error
index 3e704f3..ffa1b1f 100644 (file)
@@ -50,7 +50,7 @@ DYNAMIC_LINK_IMPEXP BOOL FreeDynLibrary(DynLibHandle hInstance);
 * @param string that specifies the function
 * @return
 */
-DYNAMIC_LINK_IMPEXP DynLibFuncPtr GetDynLibFuncPtr(DynLibHandle hInstance, char *funcName);
+DYNAMIC_LINK_IMPEXP DynLibFuncPtr GetDynLibFuncPtr(DynLibHandle hInstance, const char *funcName);
 
 /**
 * return last dynamic linking error
index a3126c9..6eecbf2 100644 (file)
@@ -47,7 +47,7 @@ BOOL FreeDynLibrary(DynLibHandle hInstance)
     return FALSE;
 }
 /*---------------------------------------------------------------------------*/
-DynLibFuncPtr GetDynLibFuncPtr(DynLibHandle hInstance, char *funcName)
+DynLibFuncPtr GetDynLibFuncPtr(DynLibHandle hInstance, const char *funcName)
 {
     if (hInstance)
     {
index 2152f22..529abac 100644 (file)
@@ -32,7 +32,7 @@ BOOL FreeDynLibrary(DynLibHandle hInstance)
     return (BOOL) FreeLibrary((HMODULE) hInstance);
 }
 /*---------------------------------------------------------------------------*/
-DynLibFuncPtr GetDynLibFuncPtr(DynLibHandle hInstance, char *funcName)
+DynLibFuncPtr GetDynLibFuncPtr(DynLibHandle hInstance, const char *funcName)
 {
     DynLibFuncPtr retFuncPtr = NULL ;
 
index 684a06b..dcc82d6 100644 (file)
@@ -779,7 +779,7 @@ DynLibHandle ConfigVariable::getDynModule(std::wstring _name)
         return it->second;
     }
 
-    return (DynLibHandle) - 1;
+    return 0;
 }
 
 int ConfigVariable::getDynModuleCount()
index 26f1684..e184af2 100644 (file)
@@ -428,17 +428,16 @@ Callable::ReturnValue DynamicFunction::Init()
     }
 
     DynLibHandle hLib = getDynModule(m_wstLibName.c_str());
-    if (hLib == (DynLibHandle) - 1)
+    if (hLib == 0)
     {
         char* pstLibName = wide_string_to_UTF8(m_wstLibName.c_str());
         hLib = LoadDynLibrary(pstLibName);
-        FREE(pstLibName);
 
-        if (hLib == (DynLibHandle) - 1)
+        if (hLib == 0)
         {
             //2nd chance for linux !
 #ifndef _MSC_VER
-            char* pstError = GetLastDynLibError();
+            char* pstError = strdup(GetLastDynLibError());
 
             /* Haven't been able to find the lib with dlopen...
             * This can happen for two reasons:
@@ -461,21 +460,28 @@ Callable::ReturnValue DynamicFunction::Init()
 
             FREE(pwstPathToLib);
 
-            if (hLib == (DynLibHandle) - 1)
+            if (hLib == 0)
             {
-                if (pstError != NULL)
-                {
-                    Scierror(999, _("A error has been detected while loading %s: %s\n"), pstLibName, pstError);
-                }
+                Scierror(999, _("A error has been detected while loading %s: %s\n"), pstLibName, pstError);
+                FREE(pstError);
+
+                pstError = GetLastDynLibError();
+                Scierror(999, _("A error has been detected while loading %s: %s\n"), pstPathToLib, pstError);
+
+                FREE(pstLibName);
+                FREE(pstPathToLib);
                 return Error;
             }
+            FREE(pstPathToLib);
 #else
             char* pstError = wide_string_to_UTF8(m_wstLibName.c_str());
             Scierror(999, _("Impossible to load %s library\n"), pstError);
             FREE(pstError);
+            FREE(pstLibName);
             return Error;
 #endif
         }
+        FREE(pstLibName);
         addDynModule(m_wstLibName.c_str(), hLib);
 
         //call init module function