inspircd

A modular C++ IRC daemon (ircd). https://www.inspircd.org/
Log | Files | Refs | README

commit 8d87fa3837d26f11b1233badbe7ec540d38a686b
parent 1ad063eff9d62c3331da5b11326d80511f9d135b
Author: Peter Powell <petpow@saberuk.com>
Date:   Mon,  4 Feb 2019 23:37:54 +0000

DLLManager: add a function for retrieving a symbol.

Diffstat:
Minclude/dynamic.h | 6++++++
Msrc/dynamic.cpp | 36+++++++++++++++---------------------
2 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/include/dynamic.h b/include/dynamic.h @@ -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(); }; diff --git a/src/dynamic.cpp b/src/dynamic.cpp @@ -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()