From e3c05efe5e5085f3db14f1532a92de460b899ab5 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 16 Sep 2013 06:28:48 -0400 Subject: Remove static variables from functions in modules which causes them to be marked as gnu unique objects, which breaks dlclose()/dlopen() on g++ 4.5+ --- src/modulemanager.cpp | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'src/modulemanager.cpp') diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index a4df9004c..5b22e9419 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -22,7 +22,7 @@ #endif std::list ModuleManager::Modules; -std::map > ModuleManager::EventHandlers; +std::vector ModuleManager::EventHandlers[I_SIZE]; #ifdef _WIN32 void ModuleManager::CleanupRuntimeDirectory() @@ -112,19 +112,6 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out } #endif -std::vector &ModuleManager::GetEventHandlers(const Anope::string &name) -{ - std::map >::iterator it = EventHandlers.find(name); - if (it != EventHandlers.end()) - return it->second; - - std::vector &modules = EventHandlers[name]; - /* Populate initial vector */ - std::copy(Modules.begin(), Modules.end(), std::back_inserter(modules)); - - return modules; -} - /* This code was found online at http://www.linuxjournal.com/article/3687#comment-26593 * * This function will take a pointer from either dlsym or GetProcAddress and cast it in @@ -263,8 +250,8 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) Log(LOG_DEBUG) << "Module " << modname << " loaded."; /* Attach module to all events */ - for (std::map >::iterator it = EventHandlers.begin(); it != EventHandlers.end(); ++it) - it->second.push_back(m); + for (unsigned i = 0; i < I_SIZE; ++i) + EventHandlers[i].push_back(m); FOREACH_MOD(OnModuleLoad, (u, m)); @@ -365,9 +352,9 @@ ModuleReturn ModuleManager::DeleteModule(Module *m) void ModuleManager::DetachAll(Module *mod) { - for (std::map >::iterator it = EventHandlers.begin(); it != EventHandlers.end(); ++it) + for (unsigned i = 0; i < I_SIZE; ++i) { - std::vector &mods = it->second; + std::vector &mods = EventHandlers[i]; std::vector::iterator it2 = std::find(mods.begin(), mods.end(), mod); if (it2 != mods.end()) mods.erase(it2); @@ -376,13 +363,13 @@ void ModuleManager::DetachAll(Module *mod) bool ModuleManager::SetPriority(Module *mod, Priority s) { - for (std::map >::iterator it = EventHandlers.begin(); it != EventHandlers.end(); ++it) - SetPriority(mod, it->first, s); + for (unsigned i = 0; i < I_SIZE; ++i) + SetPriority(mod, static_cast(i), s); return true; } -bool ModuleManager::SetPriority(Module *mod, const Anope::string &i, Priority s, Module **modules, size_t sz) +bool ModuleManager::SetPriority(Module *mod, Implementation i, Priority s, Module **modules, size_t sz) { /** To change the priority of a module, we first find its position in the vector, * then we find the position of the other modules in the vector that this module -- cgit