]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
DLLManager: add a function for retrieving a symbol.
authorPeter Powell <petpow@saberuk.com>
Mon, 4 Feb 2019 23:37:54 +0000 (23:37 +0000)
committerPeter Powell <petpow@saberuk.com>
Mon, 4 Feb 2019 23:37:54 +0000 (23:37 +0000)
include/dynamic.h
src/dynamic.cpp

index 905eb479e9ed02efe5eabb21f5458ea44b21d30d..c14452f8c1f42a7401ee48cace9e29695f69d476 100644 (file)
@@ -59,6 +59,12 @@ class CoreExport DLLManager : public classbase
         */
        Module* CallInit();
 
+       /** Retrieves the value of the specified symbol.
+        * @param name The name of the symbol to retrieve.
+        * @return Either the value of the specified symbol or or NULL if it does not exist.
+        */
+       void* GetSymbol(const char* name);
+
        /** Get detailed version information from the module file */
        std::string GetVersion();
 };
index 08564a0cd92dc1ef2bf17e89816e2dfc18c7f0f3..f2acdd51c6c11736ca62f42bf8bc53a85b4b64b6 100644 (file)
@@ -54,36 +54,30 @@ DLLManager::~DLLManager()
                dlclose(h);
 }
 
-union init_t {
-       void* vptr;
-       Module* (*fptr)();
-};
-
 Module* DLLManager::CallInit()
 {
-       if (!h)
-               return NULL;
-
-       init_t initfn;
-       initfn.vptr = dlsym(h, MODULE_INIT_STR);
-       if (!initfn.vptr)
+       union
        {
-               RetrieveLastError();
+               void* vptr;
+               Module* (*fptr)();
+       };
+
+       vptr = GetSymbol(MODULE_INIT_STR);
+       if (!vptr)
                return NULL;
-       }
 
-       return (*initfn.fptr)();
+       return (*fptr)();
 }
 
-std::string DLLManager::GetVersion()
+void* DLLManager::GetSymbol(const char* name)
 {
-       if (!h)
-               return "";
+       return h ? dlsym(h, name) : NULL;
+}
 
-       const char* srcver = (char*)dlsym(h, "inspircd_src_version");
-       if (srcver)
-               return srcver;
-       return "";
+std::string DLLManager::GetVersion()
+{
+       const char* srcver = static_cast<const char*>(GetSymbol("inspircd_src_version"));
+       return srcver ? srcver : "";
 }
 
 void DLLManager::RetrieveLastError()