From 25ce7de020d5c36fa46d87f0332c8be4bb97198d Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 11 Jun 2011 18:33:50 +0200 Subject: [PATCH] Only export a single function from modules This moves the version check into the function which loads the module info. That way, we just need a single dlsym() call per module and thus can't get any errors from the second dlsym() call. And IMHO this feels nicer anyway. ;-) Signed-off-by: Uli Schlachter --- Modules.cpp | 20 +++++--------------- Modules.h | 9 +++++---- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/Modules.cpp b/Modules.cpp index 13d255ed..ee045f88 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -1080,16 +1080,7 @@ ModHandle CModules::OpenModule(const CString& sModule, const CString& sModPath, return NULL; } - typedef double (*dFP)(); - dFP Version = (dFP) dlsym(p, "ZNCModVersion"); - - if (!Version) { - dlclose(p); - sRetMsg = "Could not find ZNCModVersion() in module [" + sModule + "]"; - return NULL; - } - - typedef void (*InfoFP)(CModInfo&); + typedef bool (*InfoFP)(double, CModInfo&); InfoFP ZNCModInfo = (InfoFP) dlsym(p, "ZNCModInfo"); if (!ZNCModInfo) { @@ -1098,13 +1089,12 @@ ModHandle CModules::OpenModule(const CString& sModule, const CString& sModPath, return NULL; } - if (CModule::GetCoreVersion() != Version()) { - bVersionMismatch = true; - sRetMsg = "Version mismatch, recompile this module."; - } else { - ZNCModInfo(Info); + if (ZNCModInfo(CModule::GetCoreVersion(), Info)) { sRetMsg = ""; bVersionMismatch = false; + } else { + bVersionMismatch = true; + sRetMsg = "Version mismatch, recompile this module."; } return p; diff --git a/Modules.h b/Modules.h index df6e6cd9..5c019d9a 100644 --- a/Modules.h +++ b/Modules.h @@ -55,14 +55,15 @@ template CGlobalModule* TModLoadGlobal(ModHandle p, #define MODCOMMONDEFS(CLASS, DESCRIPTION, GLOBAL, LOADER) \ extern "C" { \ - double ZNCModVersion(); \ - double ZNCModVersion() { return VERSION; } \ - void ZNCModInfo(CModInfo& Info); \ - void ZNCModInfo(CModInfo& Info) { \ + bool ZNCModInfo(double dCoreVersion, CModInfo& Info); \ + bool ZNCModInfo(double dCoreVersion, CModInfo& Info) { \ + if (dCoreVersion != VERSION) \ + return false; \ Info.SetDescription(DESCRIPTION); \ Info.SetGlobal(GLOBAL); \ LOADER; \ TModInfo(Info); \ + return true; \ } \ }